Close

Are you serial?

A project log for Roomba 537 SLAM

I found a Roomba in an e-waste bin and decided to give it the gift of SLAM

podgePodge 05/02/2020 at 07:070 Comments

To get the Raspberry Pi and the Roomba talking by UART a little bit of prep work is needed.

The first thing is to set up the Pi so that it's serial pins can be used. I followed the guide here: https://www.electronicwings.com/raspberry-pi/raspberry-pi-uart-communication-using-python-and-c 

For a first check to see if the the Pi was transmitting I hooked up GPIO pin 14 (TX) to an oscilloscope, SSHed into my Pi and gave it a:

echo “SLAM” > /dev/ttyAMA0

The image below is what I was faced with... yuk! The signal should be going from 0V to 3.3V (or vice a versus) and be square not sludgy and triangularish. 


I poked around in the breadboard (which being honest is a bit of a rat's nest), I checked my connections and it all looked good. But wait, I have the Pi running off my laptop's USB port and the laptop isn't connected into the mains, could the laptop be throttling the power from the USB bus to my Pi? I plugged in the laptop to the mains and took another measurement and pow we are back in business! Look at those lovely (fuzzy) edges


OK, now I can transmit something reasonable I will need to sort out a level shifter so I don't damage my Raspberry Pi. Why? because the Roomba's serial outputs a 5V high and the Raspberry Pi does not have 5V tolerant GPIOs - see https://www.raspberrypi.org/documentation/usage/gpio/ and the table below taken from iRobot's Roomba Serial Command Interface (SCI) Specification. 

The first method that came to mind for doing this was to employ Philips trusty I2C bi-directional level shifter (but only configured for one way communications) which is described in their application note "AN97055Bi-directional level shifter for I²C-bus and other systems.". 

I hooked up the circuit and looped it back on itself so that I could check that the 3.3V -> 5V and the 5V -> 3.3V when transmitting. The circuit I used is in the picture below (note the symbol for the 2n7000 n-channel MOSFETs displayed here does not show the free-wheeling diode that is part or the real component).

With the test circuit hooked up and some probes in place, I sent another "SLAM". The three traces for the "SLAM" message at 19200 baud rate is shown below (the yellow and purple traces are the TX and RX with a slight offset since they are identical and hard to see otherwise). The other trace is the 5V high side, well its supposed to be the 5V high side, it looks like i'm only getting around 3.9V. Not sure why I am not getting the 5V, I will need to have a bit more of a think about my Rp values. The good thing is it probably doesn't matter because it is likely that the Roomba will still see the 3.9V as a high anyway - we shall see when I get my DIN cable.

For a final test today, I hooked up the Pi's TX and RX so it would send itself "SLAM!"  via the TX pin through the level shifter and then back to its RX pin. I then used the Python script below to output and receive the message.
 #!/usr/bin/env python   
import time
import serial

ser = serial.Serial(
    port='/dev/ttyAMA0',
    baudrate = 19200
)

while True:
     ser.write("SLAM".encode('utf-8'))
     received_data = ser.read()              #read serial port
     time.sleep(0.03)
     data_left = ser.inWaiting()            #check for remaining byte
     received_data += ser.read(data_left)
     print (received_data)   
     time.sleep(1)

 And look at that, the conversion works (at least for the Pi anyway)

Next stop will be hooking up to the Roomba when the DIN cable arrives - ill probably need to check my Rp values too!

Discussions