Python Forum

Full Version: pi3 serial communication
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I have this two pieces of codes, It is used to communicate between pi 3 and Arduno via HC-0% bluetooth. It was work about a year ago but now I try to use it it stop workin and I can't figure why,
on the python side:
#! /usr/local/bin/python3
 
import serial
from time import sleep
# for Linux
#bt_ser = serial.Serial("/dev/rfcomm0", baudrate=38400)
# for Mac
bt_ser = serial.Serial("/dev/tty.HC_05_1-DevB", baudrate=38400) #/dev/tty.HC_05_1-DevB
bt_ser.write(str.encode('1'))
duino_data=bt_ser.readline()
print (duino_data)

on the arduino sketch
#include <SoftwareSerial.h>
 
SoftwareSerial mySerial(10, 11); // RX, TX (on Arduino)



void setup()
{
  // Open serial communications and wait for port to open:
  mySerial.begin(38400);
  pinMode(13, OUTPUT);
}
 
void loop() // run over and over
{
  if (mySerial.available()) {
    //if(mySerial.read()==1) {
      mySerial.println("Hello from Duino");
      digitalWrite(13, HIGH); // turn on
      //digitalWrite(13, HIGH); // turn on
      
    //}
    digitalWrite(13, HIGH); // turn on
  }
    
    delay(1000);
}
Here when I run the python code, it does turn on the LED on the Arduino, which means the data was sent out, but what did I send out? a string '1'? And it never get the "Hello from Duino" string back from Arduino. What is wrong with my code? Thanks