Reading values from RPLIDAR via UART

278 views
Skip to first unread message

Tomas Medina

unread,
Jul 6, 2018, 5:40:28 PM7/6/18
to BeagleBoard

I'm trying to read the values of an RPLIDAR (from RoboPeak) on the Beaglebone Black Wireless through UART1. Both GND pins are grounded and I'm connecting the pins labelled RX and TX to P9_24 and P9_26 on the Beaglebone, respectively. The V5.0, MOTOCTL, and VMOTO pins are all powered by P9_8. The following Python code is supposed to continuously read and display serial values.
import Adafruit_BBIO.UART as UART
import serial
import os

#Enabling the serial ports
os.system("config-pin P9_24 uart")
os.system("config-pin P9_26 uart")
UART.setup("UART1")

#Serial setup values
ser = serial.Serial()
ser.port = "/dev/ttyO1"
ser.baudrate = 115200
ser.close()

rx = ""

while True:
    ser.open()
    rx = ser.read()
    ser.close()
    print rx
 
However, when I run the program while the LIDAR is hooked up, nothing happens. How do I get the Beaglebone to read values from this LIDAR?

Dennis Lee Bieber

unread,
Jul 6, 2018, 10:48:28 PM7/6/18
to beagl...@googlegroups.com
On Fri, 6 Jul 2018 14:40:27 -0700 (PDT), Tomas Medina
<to...@evatech.net> declaimed the following:


>> #Serial setup values
>> ser = serial.Serial()
>> ser.port = "/dev/ttyO1"
>> ser.baudrate = 115200
>> ser.close()
>>
>> rx = ""
>>
>> while True:
>> ser.open()
>> rx = ser.read()
>> ser.close()
>> print rx
>>
>
>However, when I run the program while the LIDAR is hooked up, nothing
>happens. How do I get the Beaglebone to read values from this LIDAR?

Well... My initial thoughts would be: WHY the repetitive open/close of
the serial port???

Second... You should be able to specify port and rate when you create
the serial object (which will also open the port... You are invoking
.close() on a port that wasn't opened).

Third... .read() will wait forever if no bytes are sent by the device,
and will only read 1 byte at a time.

Something like this might reveal more information

ser = serial.Serial(port="...", baudrate=..., timeout=1)
while True:
rx = ser.read(1)
if not rx:
print "TIMEOUT - no data received"
else:
print rx, #, to keep output on one line


--
Wulfraed Dennis Lee Bieber AF6VN
wlf...@ix.netcom.com HTTP://wlfraed.home.netcom.com/

Tomas Medina

unread,
Jul 8, 2018, 11:19:06 PM7/8/18
to BeagleBoard
I close the serial port at the beginning of the program to make sure the port is clean before I start reading from it.

I tried specifying the port, baudrate, and set a time out at instantiation (ser = serial.Serial("/dev/ttyO1", 115200, timeout=1)) but the same thing happens. The only difference is that, because of the timeout, I get an empty line every second.

I mostly choose not to use timeouts in case the UART device takes a while to send something.

Dennis Lee Bieber

unread,
Jul 9, 2018, 9:28:25 AM7/9/18
to beagl...@googlegroups.com
On Sun, 8 Jul 2018 20:19:05 -0700 (PDT), Tomas Medina
<to...@evatech.net> declaimed the following:

>I close the serial port at the beginning of the program to make sure the
>port is clean before I start reading from it.

Closing the receiving end doesn't do anything for flushing data that
might be buffered on the sending side (and does even less if the receiving
end wasn't open to begin with). Granted, there is little use of
flow-control on these devices so the sending side probably doesn't even
pause before sending data.

>
>I tried specifying the port, baudrate, and set a time out at instantiation
>(ser = serial.Serial("/dev/ttyO1", 115200, timeout=1)) but the same thing
>happens. The only difference is that, because of the timeout, I get an
>empty line every second.
>

So probably not a problem on your code at least. That leaves either the
device is not sending data, or the wiring is not correct (have you tried
swapping Tx and Rx? In ancient practice, the meaning of those lines was
reversed between DCE ["modem"] and DTE ["terminal"], hence the need for
"null-modems" when connecting two DTE or two DCE devices).

On a 5V system, I'd probably try a low-current LED on the lines to
monitor, but 3.3V may be more difficult to avoid loading down the circuit.
Oscilloscope time -- make sure the device is sending data.

Brandon Sights

unread,
Jul 9, 2018, 10:25:54 AM7/9/18
to BeagleBoard
Did you try running as sudo/root?

Tomas Medina

unread,
Jul 9, 2018, 11:31:29 AM7/9/18
to BeagleBoard
Yes I am running the program as a root user
Reply all
Reply to author
Forward
0 new messages