pyserial error with udoo neo

Discussion in 'UDOO NEO' started by Noel Georgi, Jan 13, 2016.

  1. Noel Georgi

    Noel Georgi New Member

    Joined:
    Jan 13, 2016
    Messages:
    12
    Likes Received:
    1
    i wrote a python script to read serial data:

    import serial
    ser=serial.Serial('/dev/ttyMCC',115200)
    while True:
    print ser.readline()

    but while running it produces these errors:

    Traceback (most recent call last):
    File "test.py", line 2, in <module>
    ser=serial.Serial('/dev/ttyMCC',115200)
    File "/usr/local/lib/python2.7/dist-packages/serial/serialutil.py", line 180, in __init__
    self.open()
    File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 311, in open
    self._update_dtr_state()
    File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 605, in _update_dtr_state
    fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_DTR_str)
    IOError: [Errno 22] Invalid argument

    there is no problem reading data from a usb to serial converter connected to the usb port......
    any help please
     
  2. sambrin

    sambrin New Member

    Joined:
    Jan 7, 2016
    Messages:
    7
    Likes Received:
    1
    Noel Georgi likes this.
  3. Noel Georgi

    Noel Georgi New Member

    Joined:
    Jan 13, 2016
    Messages:
    12
    Likes Received:
    1
    Thanks for the reply, the method followed is same but the udoo neo serial port is a virtual one, physical ports and usb serial ports works fine, maybe due to that a9 and m4 chips share the same port, more help appreciated!!!!
     
  4. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Where do you want to connect to with the python program? To the Arduino side? If so can you see data when you open the serial reader from Arduino IDE?
     
  5. Noel Georgi

    Noel Georgi New Member

    Joined:
    Jan 13, 2016
    Messages:
    12
    Likes Received:
    1
    this is the arduino code:

    void setup()
    {
    Serial.begin(115200);
    Serial0.begin(115200);
    }
    void loop()
    {
    Serial.write(Serial0.read());
    Serial0.write(Serial.read());
    }


    i am able to see the data received to the arduino by using:
    cat /dev/ttyMCC or cu -l /dev/ttyMCC -s 115200
    but cant connect to port /dev/ttyMCC via pyserial.....
    pyserial successfully connected to /dev/ttyUSB0 port of my us serial adapter connected to an arduino on breadboard
    I even tried linking /dev/ttyMCC to /dev/ttyS0 by
    sudo ln /dev/ttyMCC /dev/ttyS0
    and tried using /dev/ttyS0 in pyserial but failed with same error
     
  6. Pilif

    Pilif New Member

    Joined:
    Jan 11, 2016
    Messages:
    15
    Likes Received:
    2
    ca you set a timeout like serial.Serial('/dev/ttyMCC', 9600,timeout=.1) ? and then in code
    time.sleep(2) before you try to read for the first time? Here is the python code I used to test .. btw. for the Arduino side I used the example multiserial (from communication) and changed seria1 to serial0


    #! /usr/bin/env python

    import serial
    import time
    ports = [serial.Serial('/dev/ttyMCC', 9600,timeout=.1)]#,
    def gateway():

    for port in ports:
    # send synch/start command to all avr's
    port.write("PING")
    port.write("\r\n")
    print "aaaa"

    while 1:
    for port in ports:
    daten = port.readline()
    if(len(daten) > 0):
    print daten

    if __name__ == '__main__':

    #wait for avr to calm
    time.sleep(2) # this must be here

    #flush all garbage
    for port in ports:
    port.flushInput()
    port.flushOutput()

    gateway()
     
  7. Noel Georgi

    Noel Georgi New Member

    Joined:
    Jan 13, 2016
    Messages:
    12
    Likes Received:
    1
    Thanks for the code and help, but............
    Tried your code but still getting the same errors as below:

    Traceback (most recent call last):
    File "test.py", line 5, in <module>
    ports = [serial.Serial('/dev/ttyMCC', 9600,timeout=.1)]#,
    File "/usr/local/lib/python2.7/dist-packages/serial/serialutil.py", line 180, in __init__
    self.open()
    File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 311, in open
    self._update_dtr_state()
    File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 605, in _update_dtr_state
    fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_DTR_str)
    IOError: [Errno 22] Invalid argument


    where did you install pyserial from
    i did it using pip
    pip install pyserial
    i wonder whether its an issue with pyserial
     
  8. Pilif

    Pilif New Member

    Joined:
    Jan 11, 2016
    Messages:
    15
    Likes Received:
    2
    i think it was sudo apt-get install pyserial
    can you also change the arduino side with

    void setup() {
    // initialize both serial ports:
    Serial.begin(9600);
    Serial0.begin(9600);
    }

    void loop() {:
    if (Serial0.available()) {
    int inByte = Serial0.read();
    Serial.write(inByte);
    }

    // read from port 0, send to port 1:
    if (Serial.available()) {
    int inByte = Serial.read();
    Serial0.write(inByte);
    }
    }
    EDIT:
    btw. you can use minicom -D /dev/ttyMCC - b 9600 and then i think it was ctrl + A and'e' for Echo (to see what you tipe also) or just ctrl +A and then 'z' for options
     
    Noel Georgi likes this.
  9. Noel Georgi

    Noel Georgi New Member

    Joined:
    Jan 13, 2016
    Messages:
    12
    Likes Received:
    1
    Hi Pilif, thanks for your valuable information and fast reply, but I'm still getting the same errors when executing the python script, which version of udoobuntu are you using????

    FYI: i'm getting output in serial console and also minicom, the only problem is the python script
     
  10. Pilif

    Pilif New Member

    Joined:
    Jan 11, 2016
    Messages:
    15
    Likes Received:
    2
    the one before RC1 (but now I will have to use it since I messed my SD card :( )
    this is strange :(
     
  11. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Strange, I use the same code on RC1 to setup the connection and have no issues sending data viceversa:
    I do not use Serial0

    Python:
    arduino = serial.Serial('/dev/ttyMCC',115200,timeout=0)
    arduino.flushOutput()
    arduino.flushInput()
    serial_data = arduino.read()

    Arduino:
    Serial.begin(115200);
    delay(100);
    Serial.println("W"); //send commands to python
     
  12. Noel Georgi

    Noel Georgi New Member

    Joined:
    Jan 13, 2016
    Messages:
    12
    Likes Received:
    1
    I'm getting the same errors in python still, where did you install pyserial from?
     
    Last edited: Jan 14, 2016
  13. sambrin

    sambrin New Member

    Joined:
    Jan 7, 2016
    Messages:
    7
    Likes Received:
    1
    Its work for me. Im download and install pyserial-2.7 then use python 2 for programming.


    Sent from my iPhone using Tapatalk
     
  14. Noel Georgi

    Noel Georgi New Member

    Joined:
    Jan 13, 2016
    Messages:
    12
    Likes Received:
    1
    Issue resolved!!!!
    i had to remove pyserial installed using pio and installed python-serial and everything works like charm
    sudo pip uninstall pyserial
    sudo apt-get install python-serial


    Thanks everyone
     
    waltervl likes this.
  15. Melendez

    Melendez New Member

    Joined:
    Feb 10, 2016
    Messages:
    1
    Likes Received:
    1
    Thanks for your answers its works for me too.
     
    waltervl likes this.
  16. kpsbahn

    kpsbahn New Member

    Joined:
    Nov 24, 2015
    Messages:
    4
    Likes Received:
    2
    A big thanks from me to every one,
    After struggling with exactly the same problem for an entire day, I logged into the forum to post the problem.
    How lucky! Noel Georgi has already posted the same problem and got the solution also.
    The trick worked for me and ended my misery.
    Thanks once again, all of you.
     
    Noel Georgi likes this.
  17. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Last edited: Feb 12, 2016
  18. Noel Georgi

    Noel Georgi New Member

    Joined:
    Jan 13, 2016
    Messages:
    12
    Likes Received:
    1
    Happy to know that your issue is resolved!!! :)
     
  19. cyrilf

    cyrilf Active Member

    Joined:
    Feb 19, 2015
    Messages:
    168
    Likes Received:
    47
    Does anyone has the sources of this confidential python-serial library?
     
    Andrea Rovai likes this.
  20. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Do you mean the python-serial that you get from apt-get or the Udoo python serial? The first I don't know. The second is in UDOOboard github. Will add the link with an edit.
    Edit: https://github.com/UDOOboard/serial_libraries_examples
     

Share This Page