Serial Receiving from Arduino to Raspberry Pi with PySerial stops after a while

后端 未结 5 828
小蘑菇
小蘑菇 2021-01-04 19:09

I\'m working on a project in which I have to receive some 25 character data at a time in order to process it in Raspberry Pi. Here is the example code that generates some da

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-04 19:43

    During your loop function in your Arduino code you never end an newline char \n, this is only a problem with ser.readline() because it reads until a \n character.

    During your setup function you correctly send a \n character which could explain the intial value being sent, but not the data.

    perhaps modifying your Arduino code like this:

    void loop(){
        for(i=0;i<25;i++){
            for(a=0;a

    And your python code like so...

    ser = None
    try:
        ser = serial.Serial('/dev/AMA0',9600,timeout=3)
        ser.open()
    
        while True:
            try:
                serial_data = ser.readline()
                print serial_data
            except:
                pass
    except:
        pass    
    finally:
        if ser:
            ser.close()
    

提交回复
热议问题