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.
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).
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
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.