Go Down

Topic: Issue with read and writing serialy (python 3 with ubuntu) (Read 1 time) previous topic - next topic


Aug 27, 2014, 03:41 am Last Edit: Aug 27, 2014, 03:33 pm by 3_141592_Co Reason: 1
It would be amazing ig your could provide some sample code for the long and Int transfer. I am currently having some issues.
Here is some of my code if you wouldn't mind going through it. The issue I am getting is that it hangs at the first loop (seeing if the arduino is ready after it resets from opening a serial port) The arduino does reset but nothing on either side does anything after that. I know this because of a couple print statements (not connected to the serial besides the loop they are in) i didn't include never show up

Code: [Select]

class Target:
def run():
   (code not important (from openCV library)
   ser = serial.Serial("/dev/ttyACM0", 57600)
   connected = 0
   while connected == 0: //From consoul messages I am guessing this is where it is getting hung
       ser.write("3")               // I am little confused because the pySerial will only send strings but the arduino will not read strings?
       if ser.read() == 4:      //Might be the reason why the "connected" variable will never switch and end the loop
           connected = 1
   while connected == 1:
   (a lot of code related to openCV and not arduino serial)
   ser.write("1") # cheacking to see if the arduino is ready for now command
   read = ser.read()
   if read == 2:  #the value two is the arduino saying it is ready for a new command
       ser.write(str(center_point[1])) # Part of openCV code that needs to be sent to arduino
       time.sleep(.1) #giving arduino time to move value out of serial cache and into array(just thought of that now not really sure how to implement that into arduino code)

Code: [Select]

int readSerial = 0;

void setup() {
  pinMode(5, OUTPUT);
void loop() {
  readSerial = Serial.parseInt();
  if (readSerial == 3) {
    readSerial = Serial.parseInt();
    if (readSerial == 2) {
      readSerial = Serial.parseInt();



You did not post your Arduino code - just 2 copies of the Python code.

Look at this demo and this demo.

I'm not sure which problem you are trying to solve.

Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up