Hi,
I try to use pybluez to read data from Arduino/bluetooth to Python on Win10. I have now working code for reading via USB and it works well. But I have no idea how to do it with BT. Now I can connect BT device and read some data but not exactly what I need.
OLD working code for serial:
Is there any way how to proceed?
Thanks!
EDIT:
Main question is: Is possible send array of 30000 floats from Teensy/Arduino to Python via bluetooth in very short time? And how to receive it in Python?
I try to use pybluez to read data from Arduino/bluetooth to Python on Win10. I have now working code for reading via USB and it works well. But I have no idea how to do it with BT. Now I can connect BT device and read some data but not exactly what I need.
OLD working code for serial:
import serial
import struct
SAMPLES= 30000
v_data = []
s = struct.Struct('<' + str(SAMPLES) + 'f')
ser = serial.Serial(port=serio, baudrate=2000000)
ser.reset_input_buffer()
ser.write("r".encode())
serial_data = ser.read(SAMPLES*4)
unpacked_data = s.unpack(serial_data)
v_data[0:SAMPLES] = unpacked_data[0:SAMPLES]NOW I try this:import bluetooth
import serial
import struct
v_data = []
ser = ""
s = struct.Struct('<' + str(10) + 'f')
SAMPLES = 30000
bd_addr = "FC:A8:9A:00:22:33" #itade address
port = 1
sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sock.connect((bd_addr, port))
print('Connected')
#sock.settimeout(1.0)
sock.send("r")
print('Sent data')
while True:
v_data = sock.recv(100)
if len(v_data) == 0: break
print("received [%s]" % v_data)
print(v_data)I have this code in Teensy4.0:#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // RX, TX
char inChar;
void setup()
{
Serial.begin(38400);
Serial.println("I am ready to send some stuff!");
mySerial.begin(38400);
}
void loop() // run over and over
{
if (Serial.available() > 0) {
inChar = Serial.read();
for(int i=0; i<100; i++) {
byte *b = (byte *)&i;
mySerial.write(b[0]);
mySerial.write(b[1]);
mySerial.write(b[2]);
mySerial.write(b[3]);
}
}
}But data seems like nonsense and it is very slow. With Serial I can read 30k values in 0.2s. Is there any way how to proceed?
Thanks!
EDIT:
Main question is: Is possible send array of 30000 floats from Teensy/Arduino to Python via bluetooth in very short time? And how to receive it in Python?
