Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pi3 serial communication
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  RPi and smartphone Bluetooth communication GigiG 0 384 Mar-18-2025, 09:54 AM
Last Post: GigiG
  pyserial/serial "has no attribute 'Serial' " gowb0w 11 22,211 Sep-27-2024, 12:18 PM
Last Post: NigelHalse
  packet radio communication EmpireAndrew 1 2,870 Nov-01-2019, 06:35 PM
Last Post: micseydel
  WiFi communication Milad 2 3,132 Sep-07-2019, 11:53 AM
Last Post: ndc85430
  Serial communication with raspberry pi 3B and Xbee kj7 0 2,662 Mar-25-2019, 03:39 AM
Last Post: kj7
  Serial Communication Error AlphyOuseph 1 4,434 Feb-07-2019, 07:16 AM
Last Post: DeaD_EyE
  python-osc communication fauveboy 10 13,730 Jul-23-2018, 07:49 PM
Last Post: buran
  serial communication write(comand) and read(result) ricardons 1 3,835 Mar-01-2018, 04:26 PM
Last Post: mpd
  Serial communication with a board Bokka 2 6,177 Dec-07-2017, 07:34 AM
Last Post: Bokka
  Serial port communication FatimaSameer 1 3,836 Oct-03-2017, 09:47 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020