The general idea is to hook up the Roomba via its serial port to a WiFi enabled Raspberry Pi2 B+. The Pi will process the data and give commands, if more juice is needed ill farm it out to a PC via WiFi, if more juice is needed I'll get a juicer!
Components
1×
Roomba 537 (from a bin)
1×
Raspberry Pi2 B+
1×
150M Miniature WiFi (802.11n) Module for Raspberry Pi
Bought from Core electronics
2×
2N7000 n-channel MOSFET
For logic level shifting
Once the the level shifter was functioning I then needed to connect the pi to the Roomba. To do this I used a 8-way male moulded din cable assembly which is much easier to find than the 7-way counterpart. This works because the 8th pin sits in the middle void created by the 7-way receptacle's locator (the rectangle in the middle of the connector in the image below) - that is it just chills in a void and does nothing.
With this cable I connected the Rx of the Roomba to the Tx of the Raspberry Pi (via the level shifter of course) and plugged it into the socket under the top cover of the Roomba - it is now ready for some serial commands.
As per the iRobot Roomba SCI spec to control the Roomba you need to first send a few commands with a 20 ms pause in between to put it in passive mode then safe mode then full mode which will allow unrestricted access. This is done by sending the opcodes 128, 130, 131 and 132.
To command the Roomba to drive it needs to be sent the opcode 137 (drive) and then 4 data bytes as per the following sequence ( a nice example is given in the SCI):
[137] [Velocity high byte] [Velocity low byte][Radius high byte] [Radius low byte]
My first command was forward 10mm/sec and 0 radius (value 32768) turn which doesn't quite work. The Roomba will move ok but will still run with a large radius - perhaps it is my hi/lo byte splitting function. But I am still calling that a victory cause it almost does what I want - just need a bit more work to suss out whats going wrong.
All the code for these commands and the basic framework I will be using is committed and pushed to my git repo.
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
)
whileTrue:
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!
The first step was to clean up this bad boi, order a power supply and figure out what was wrong with it. It seems that it may have been an issue with the dock which is as of yet not fixed because I have been lazy and plugged the charger directly into the Roomba.
After a long charge cycle the Roomba fired up and started vacuuming up all the dust in its new home. Looks like one persons trash is another's treasure!
The next step was to dig up my Raspberry Pi and see if it still worked. Damn it the memory card was corrupt, just needed to reformat it. I went with Rapsbian (because I am lazy) using the installer on the Pi website: https://downloads.raspberrypi.org/imager/
Once the image was installed on the pi I fired it up and it worked like a dream.
Next step get the WiFi working so I can remote into the Pi from any device on my network. The WiFi dongle that I chose claimed to be plug and play ready for the Pi, and it was. No messing about with drivers, win! With the WiFi working I enabled ssh using the official documentation: https://www.raspberrypi.org/documentation/remote-access/ssh/README.md. Now with this setup I can simply ssh into the pi using the command prompt i.e. ssh pi@(the ip address)
Once the ssh was setup I configured the Pi so that I could use windows Remote Desktop Connection to access the Pi's GUI. TO do this I followed the steps on: https://pimylifeup.com/raspberry-pi-remote-desktop/
Now the Pi is all setup the next step is to get the serial going!
this project is looking very great looking I am also working on the pretty similar type of website project you can see here https://bestgearly.com/best-juicer-under-100-200/