General ArduinoBluno

Bluno ble + python communication?

userHead spinal.cord 2024-07-23 05:39:07 5 Views0 Replies

If I use the example code for arduino…

 

[code]


void setup() {
 Serial.begin(115200);
 //initial the Serial
}

void loop()
{
 if(Serial.available()){
   Serial.write(Serial.read());
 }

}
[/code]

 

and the following Python code on PC

 

[code]

async def send_data(client, data):
   # Write data to the characteristic in chunks
   for i in range(0, len(data), MAX_DATA_SIZE):
       chunk = data[i:i + MAX_DATA_SIZE]  # Get the chunk of data
       encoded_chunk = chunk.encode('utf-8')  # Encode the chunk as bytes
       await client.write_gatt_char(SERIAL_PORT_UUID, encoded_chunk)
       print(f"Sent data chunk: {chunk}")
[/code]

 

I can send text to the bluno and print it out on the serial monitor.

But how do I do it the other way around? I want to send data from the bluno TO the python code on the PC.

 

Thanks.