[Python] Why doesn't the Bluetooth module read the signal sent through the socket?

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I uploaded the code to the Arduino board so that when the message "1" is sent to the Bluetooth module, the motor turns on. I tested it using the Android apps "BT terminal" and "Arduino bluetooth control". I paired with the bluetooth module, typed "1" in the app, sent it, and it worked.

    However, when I send a signal through a socket using Python, the port monitor displays that the Bluetooth module has been connected, but no data has been transmitted.

    simplified code:

    from bluetooth import *
    target= "02:03:04:53:24:A1"
    sock= bluetooth.BluetoothSocket(Protocols.RFCOMM)
    sock.connect((target,1))
    sock.send(bytes(1))
    sock.close()


    #include <SoftwareSerial.h>
    SoftwareSerial bluetooth(10, 11);
    int M2= 4;

    void setup(){Serial.begin(9600);bluetooth.begin(9600);pinMode(M2,OUTPUT);}

    void loop() {
    If (bluetooth.available ()) {
    char data=bluetooth.read();
    Serial.println(data);
    if (data=='1') {
    digitalWrite(M2,HIGH);
    delay(1000);
    digitalWrite(M2,LOW);
    }}}


    I changed the library to a regular "socket", but nothing changed. I changed the code on the Arduino so that it expected "1" to be passed as bytes. But nothing changed.

    Continue reading...

Compartilhe esta Página