Python Forum
Serial loopback with Arduino doesn't work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Serial loopback with Arduino doesn't work
#1
Hi,
I'm trying to establish a serial communication with my Arduino Uno using pyserial. To test it, I programmed a simple loop back example, where the data I send with my python program over USB is send back unchanged. However, I get weird results. I already checked that the data the Arduino receives is OK (it is). When I just send data from the Arduino to the Computer (e.g. Serial.print('a')) the data is received correctly by my python program. I already tried to use ArduinoData.read(1) instead of ArduinoData.readline() in python and Serial.print(), Serial.println() and Serial.write() in Arduino. I get similar results each time.

I already looked in several forums and the pyserial documentation but couldn't find anything that helps.

I hope someone here can help me. Thanks!

Here is my python code:
import serial

delay = 0

ArduinoData = serial.Serial('COM8', 9600)
print("port is open!")


while(delay<1000):
    delay+=1
    ArduinoData.write(b'a')
    
        
data = ArduinoData.readline()
#data1 = ArduinoData.read(1)

print(data)
#print(data1)

ArduinoData.close()
Arduino Code:
byte data;

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

void loop() {
  //wait for data
  
  while(!Serial.available());
  data = Serial.read();
  
  Serial.println(data);
  delay(500);
  
}
console output:
Output:
=== RESTART: C:\Users\thoma\Documents\studium\learn python\mySerial\test1.py === port is open! b'133\r\n' >>> === RESTART: C:\Users\thoma\Documents\studium\learn python\mySerial\test1.py === port is open! b'133\r\n' >>> === RESTART: C:\Users\thoma\Documents\studium\learn python\mySerial\test1.py === port is open! b'88\r\n' >>> === RESTART: C:\Users\thoma\Documents\studium\learn python\mySerial\test1.py === port is open! b'133\r\n' >>> === RESTART: C:\Users\thoma\Documents\studium\learn python\mySerial\test1.py === port is open! b'133\r\n' >>> === RESTART: C:\Users\thoma\Documents\studium\learn python\mySerial\test1.py === port is open! b'133\r\n' >>> === RESTART: C:\Users\thoma\Documents\studium\learn python\mySerial\test1.py === port is open! b'97\r\n' >>> === RESTART: C:\Users\thoma\Documents\studium\learn python\mySerial\test1.py === port is open! b'97\r\n' >>> === RESTART: C:\Users\thoma\Documents\studium\learn python\mySerial\test1.py === port is open! b'133\r\n' >>> === RESTART: C:\Users\thoma\Documents\studium\learn python\mySerial\test1.py === port is open! b'88\r\n'
Reply


Messages In This Thread
Serial loopback with Arduino doesn't work - by ThomasS - Sep-18-2020, 06:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PIP doesn't work YKR 1 845 Mar-28-2025, 02:10 PM
Last Post: snippsat
  I'm trying to install python 3.11.11 on windows 10 - it doesn't work Petonique 2 2,686 Feb-04-2025, 05:42 PM
Last Post: snippsat
  sending strings to arduino over serial/accessing DLLs HeWhoHas 0 918 Nov-09-2024, 06:01 PM
Last Post: HeWhoHas
  pyserial/serial "has no attribute 'Serial' " gowb0w 11 24,615 Sep-27-2024, 12:18 PM
Last Post: NigelHalse
  Extending list doesn't work as expected mmhmjanssen 2 1,598 May-09-2024, 05:39 PM
Last Post: Pedroski55
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 2,116 Jun-24-2023, 02:14 PM
Last Post: deanhystad
Star Pyserial not reading serial.readline fast enough while using AccelStepper on Arduino MartyTinker 4 9,211 Mar-13-2023, 04:02 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 3,855 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  color code doesn't work harryvl 1 1,972 Dec-29-2022, 08:59 PM
Last Post: deanhystad
  client.get_all_tickers() Doesn't work gerald 2 2,826 Jun-16-2022, 07:59 AM
Last Post: gerald

Forum Jump:

User Panel Messages

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