Problem Serial ttyUSB0 code


5 posts
by sarandaegus » Sat Dec 17, 2016 4:05 pm
Hi, this is my first post in this comunity, so sorry if the post dont belong here.

ok.i am working in the comunication with raspberry pi with RPLIDAR sensor, The RPLIDAR is a sensor scanner 2D, this send points in the plane.i have tried with this code in python:

https://github.com/jmccormack200/RPLidar/blob/master/LidarPrint.py

but it doesnt work, i understand thar i have to change the last code line, because i am working in Debian Software (Linux) and the COM port dont exist, the usb port of the sensor is "/dev/ttyUSB0"

Code: Select all
if __name__ == "__main__":
    #COM4 was used on my computer, this will change based on
    #your setup and whether you're on Windows/Mac/Linux
    #port = '/dev/ttyUSB0'
    #port = 20
    port = "/dev/ttyUSB0"
    ser = serial.Serial(port, 115200, timeout = 5)
    ser.setDTR(False)
    print ser.name

    #Create a Lidar instance, this will immidiately start printing.
    #To edit where the data is sent, edit the GetPoints Method
    lidar = Lidar(ser)


when i run this, appears this:

Code: Select all
/dev/ttyUSB0
Connecting
...


the right response when the code is running is this:

Code: Select all
./dev/ttyUSB0
Connecting
...
(146, 131)
(147, 132)
(148, 133)
(150, 134)
(151, 135)
(154, 135)
(156, 137)
(158, 139)
(161, 140)
(164, 141)
(166, 142)


but dont work this, so what is the problem?

In this other forum, they work with this code and it does work.

https://github.com/ev3dev/ev3dev/issues/491

I have to work with the sample code of RPLIDAR and this work in raspberry, so maybe the problem isn't the usb port conection.

Code: Select all
pi@raspberrypi:~ $ lsusb
Bus 001 Device 005: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
Bus 001 Device 004: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub



Thank you and sorry for my english.

Sergio
Posts: 3
Joined: Sat Dec 17, 2016 2:03 pm
by scruss » Sun Dec 18, 2016 4:15 am
Is your pi user a member of the dialout group? You need that for serial access. Do this, then log out and back in again:
Code: Select all
    sudo usermod -a -G dialout pi
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
User avatar
Posts: 1186
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
by sarandaegus » Sun Dec 18, 2016 10:19 am
Hi Mr.scruss right now i am trying with this code:

Code: Select all
pi@raspberrypi:~ $ sudo usermod -a -G dialout pi
pi@raspberrypi:~ $


Not seen nothing .. is it ok? Then i tried to run my code and the same problem appears. What is wrong? :S
Also tried in root mode, but is same, too i tried change ('/dev/ttyUSB0') for ("/dev/ttyUSB0") in my code but the problem persists.

Any other suggestions?

Thank you for you response.

Sergio
Posts: 3
Joined: Sat Dec 17, 2016 2:03 pm
by sarandaegus » Sun Dec 18, 2016 10:31 am
Ah .. I forgot to tell you that after entering the code, I rebooted raspberry

Code: Select all
pi@raspberrypi:~ $ sudo usermod -a -G dialout pi
pi@raspberrypi:~ $ sudo reboot
Posts: 3
Joined: Sat Dec 17, 2016 2:03 pm
by scruss » Mon Jun 19, 2017 2:55 pm
Is your serial port really /dev/ttyUSB0? The output from dmesg will tell you what the device name is.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
User avatar
Posts: 1186
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON