eizfrim
Posts: 3
Joined: Wed Nov 09, 2016 5:53 pm

Problem using UART over GPIO on RPi 2

Wed Nov 09, 2016 5:54 pm

I'm trying to use a Lidar with my raspberry pi 2 running Raspbian. The way I'm trying this is via UART, it can be done with a usb cable but since the sensor will be spinning around, it has a slipdisk to which I've soldered the serial connections (5V, GND, TX and RX). I've already made sure to go to raspi-config and disable the serial console, when I connect the sensor to the pi and run

Code: Select all

ls /dev/tty*
no new devices appear, when I disconnect the sensor and run it again, nothing goes away, so it doesn't recognize it from the beginning.

The sensor is an SF30 Lidar, which despite running on 5V, the serial interface is 3.3V, which I know is what the RPi uses, I have also checked the connections to make sure the sensor's RX goes to the Pi's TX and the sensor's TX goes to the Pi's RX. I've also tried powering the sensor with an external power supply (and making sure to connect it's ground with the Pi's) to no avail, is there something I'm missing?

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Problem using UART over GPIO on RPi 2

Wed Nov 09, 2016 7:11 pm

All the Pi's GPIO are 3V3. Connecting them to 5V may damage them.

As long as you have recent software the UART will be called /dev/serial0 which is a link (synonym) to /dev/ttyAMA0.

Physically the UART is connected to pins 8 (TXD) and 10 (RXD).

You also need to connect the grounds of the Pi and your serial device.

eizfrim
Posts: 3
Joined: Wed Nov 09, 2016 5:53 pm

Re: Problem using UART over GPIO on RPi 2

Thu Nov 10, 2016 3:32 am

joan wrote:All the Pi's GPIO are 3V3. Connecting them to 5V may damage them.

As long as you have recent software the UART will be called /dev/serial0 which is a link (synonym) to /dev/ttyAMA0.

Physically the UART is connected to pins 8 (TXD) and 10 (RXD).

You also need to connect the grounds of the Pi and your serial device.
I actually mentioned the sensor's serial interface being 3.3V and making sure the grounds were connected.
I fixed the issue by modifying the last line in /boot/config.txt from uart_enable=0 to uart_enable=1.

I can now get data however it looks like I'm having a configuration problem, I'm supposed to receive a byte ranging from 0-255 but all I get are random weird characters or blank spaces, I've checked the baud rates, sto bits, parity, etc but still am receiving weird inputs.

User avatar
karrika
Posts: 1125
Joined: Mon Oct 19, 2015 6:21 am
Location: Finland

Re: Problem using UART over GPIO on RPi 2

Thu Nov 10, 2016 6:37 am

This sounds as a very hi-tech project. I assume that it uses some insanely high baudrate for creating the image. Have you set the init_uart_clock variable in /boot/config.txt correctly? For non-standard baudrates I set it 64 times higher than the desired baud rate.

You could also have a look if the signal is inverted. The piscope by joan could be helpful.

eizfrim
Posts: 3
Joined: Wed Nov 09, 2016 5:53 pm

Re: Problem using UART over GPIO on RPi 2

Thu Nov 10, 2016 6:03 pm

karrika wrote:This sounds as a very hi-tech project. I assume that it uses some insanely high baudrate for creating the image. Have you set the init_uart_clock variable in /boot/config.txt correctly? For non-standard baudrates I set it 64 times higher than the desired baud rate.

You could also have a look if the signal is inverted. The piscope by joan could be helpful.

I actually managed to fix the problem, the sensor sends the serial data encoded as ASCII characters, which is why I was seeing data but as weird, random characters, all I had to do was use the ord(data) function in Python to convert it to the decimal numbers I was expecting.

The uart clock variable sounds like it might help me with the project, I'll look into it, thanks.

Return to “Troubleshooting”