Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Pyserial not working
I'm new to Python and Pyserial.

I have this project that I'm working on where I need to have an Arduino communicate to my Python code through Pyserial.

Here is my Pyserial code.

import serial
import time
import sys

ser = serial.Serial('/dev/cu.usbserial-A505BRMT', 9600)  # open serial port
while True:
    print('write:',str.encode('90')) #print the sent value through the serial to check
    ser.write(str.encode('90'))#send the following value

    print('read:', the same value back from the arduino

Here is my Arduino code.
char data; //Holds incoming character

void setup()
Serial.begin(9600);   //Serial Port at 9600 baud

void loop() {
  if (Serial.available() > 0)   //Print only when data is received
    data =;   //Read byte of data
    Serial.print(data);   //Print byte of data
Basically I'm sending a number (90) to the Arduino to read it in the serial monitor and then send it back to the Python code to read it again.
print('read:', This line doesn't seem to work no matter the value I use

Anyone has an idea to fix it?
Shouldn't it be non-zero value in it's the size (in bytes) to read

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  install Pyserial neeheng 2 144 Jul-11-2019, 03:05 PM
Last Post: neeheng
  Dialup Modem using pyserial - Need it to show response from the other end. Rython 1 301 Jun-20-2019, 10:09 PM
Last Post: roy
  Problem to sent message with pyserial and ser.write DJ_Depannage 18 672 Apr-15-2019, 08:45 PM
Last Post: DJ_Depannage
  pyserial-master installed bbut not recognized elwolv1 0 269 Jan-04-2019, 08:37 PM
Last Post: elwolv1
  Trouble with Pyserial and Arduino LiTing 3 808 Oct-07-2018, 11:00 AM
Last Post: Larz60+
  pyserial char by char io fcagney 4 1,007 May-15-2018, 10:45 PM
Last Post: DeaD_EyE
  Unable to read csv file inside full code snippet, at the same time its working seprat sreeraj 2 804 Jan-28-2018, 07:25 PM
Last Post: sreeraj
  Cannot attach to com port with Pyserial sabdulqadir 0 2,017 Nov-15-2017, 12:47 AM
Last Post: sabdulqadir
  Failed attempt to install pyserial skeeve 4 2,488 Nov-07-2017, 05:08 PM
Last Post: snippsat
  PySerial Question PythonMan 2 1,061 Oct-30-2017, 11:53 PM
Last Post: PythonMan

Forum Jump:

Users browsing this thread: 1 Guest(s)