Browser Controlled Roomba Robot With The Raspberry Pi Model 3 A+
Browser Controlled Roomba Robot With The Raspberry Pi Model 3 A+
Browser Controlled Roomba Robot With The Raspberry Pi Model 3 A+
by ianderson3
Overview
This Instructable will focus on how to give a dead Roomba a new brain (Raspberry Pi), eyes (Webcam), and a way
to control everything from a web browser.
There are a lot of Roomba hacks that allow control via the serial interface. I have not been fortunate enough to
come across a Roomba that has current firmware or working motherboard. Either the Roomba is too old or the
Roomba is dead. I found the Roomba I used for this project in a local thrift store bargain bin for $5. It still had a
decent battery, but a dead motherboard. (I also found the webcam at the same thrift store for around $5). All I'm
using from the original Roomba are the motors, chassis, and battery. You do not have to use a Roomba for this
project. You could use different motors, wheels, and chassis if you like. I just fancy turning a piece of junk into
something usable.
For this build I used the Raspberry Pi Model 3 A+ and a Riorand motor controller. I am using code from the Dexter
Industries Browser Controlled Robot that I modified. The Dexter Industries version sets up the Pi as a websocket
server that allows you to control their robot (brick pi platform) from a client html file running another computer.
I have changed the code use the GPIO pins and added a way for the Pi to shutdown when a button is clicked /
when the escape key is pressed in the browser. I also made some changes to the control web page to allow
viewing a motion stream through an iframe, while controlling the robot all within a single page. I set the Pi up with a
static IP to host the client file so I could connect using any computer or device on my network.
I am documenting the process here in the hope of showing how to create a simple, inexpensive base robot.
Parts Used
Browser Controlled Roomba Robot With the Raspberry Pi Model 3 A+: Page 1
Jumper Wires (Amazon Link) $7
I used Raspbian Stretch Lite. I didn't see a need for the desktop, but you may install the desktop version if you
prefer.
I am going to assume you already know how to install Raspbian. If you you need help, you can find the Raspberry
Pi Foundation's guide here.
Once you have Raspbian up and running, login and run the raspi-config program.
Select
2 Network Options
Select
N2 Wi-fi
Browser Controlled Roomba Robot With the Raspberry Pi Model 3 A+: Page 2
Setup SSH in raspi-config
Once I did the initial config, I used SSH to set everything up headless. (You could skip this if you use a monitor. It
was easier for me to make changes to the code without having to stop the robot and plug it into a monitor.)
Select
5 Interfacing Options
Select
P2 SSH
Select
Yes
<Finish>
pi@raspberrypi:~ $ ifconfig
You should receive an output similar to this. (Note the IP address; you may need it later. e.g.192.168.1.18)
Browser Controlled Roomba Robot With the Raspberry Pi Model 3 A+: Page 3
Setup a Static IP
To be able to consistently connect to your robot using the same address on your network, you will want to set up a
static IP.
I am using the address that was automatically assigned by DHCP when the Pi connected to my network. You can
change this to whatever you like as long as it matches up with your network and doesn't conflict with any other
assigned addresses.
Scroll down to #Example static IP configuration and change the following lines.
#interface eth0
#static ip_address=192.168.11.13
#static routers=192.168.11.1
#static domain_name_servers=192.168.11.1 8.8.8.8
Change to match your network and remove the # at the beginning of each line.
Example:
interface wlan0
static ip_address=192.168.1.18
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8
Connect from another computer using SSH. Windows users can use PuTTY or the Windows Subsystem for Linux
(Windows10).
[email protected]'s password:
Browser Controlled Roomba Robot With the Raspberry Pi Model 3 A+: Page 4
You should be now be at your Pi's command prompt.
pi@raspberrypi:~$
Motion is a program used in a lot of security camera / webcam projects. Motion has a lot of features. However, we
are setting it up to simply stream video from the webcam to port 8081.
Plug in your webcam and list connected usb devices (You may need to reboot after connecting).
pi@raspberrypi:~ $ lsusb
You should get an output similar to this. Note the Logitech C210.
If your camera doesn't show up, it might not be compatible or you may need to install additional drivers.
Install Motion
Update packages.
Browser Controlled Roomba Robot With the Raspberry Pi Model 3 A+: Page 5
pi@raspberrypi:~ $ sudo apt-get update
Install Motion.
daemon on
width 640
height 480
framerate 100
output_pictures off
ffmpeg_output_movies off
text_right
stream_port 8081
stream_quality 100
stream_localhost off
webcontrol_localhost off
Change to
start_motion_daemon=yes
Reboot
After the Pi has rebooted open the browser and verify that you have video streaming into the browser on port 8081
Example:
http://192.168.1.18:8081
Browser Controlled Roomba Robot With the Raspberry Pi Model 3 A+: Page 6
Troubleshooting the Motion Daemon
I ran into problems getting the motion daemon to start at boot while I was trying out different options in the
motion.conf file.
If you start motion before the motion daemon in Raspian Stretch, you will probably run into issues getting it to start
at boot later on. Running "sudo motion" without configuring the daemon to do it first creates the directory
/var/log/motion without granting write permission to the user.
Browser Controlled Roomba Robot With the Raspberry Pi Model 3 A+: Page 7
Step 3: Install Apache and Setup Web Control Page
Apache is the web server for the robot's control web page. We are going to replace the default Apache index.html
file with a file downloaded from github. You will also change a couple of lines of code to display the motion video
stream and assign where to send the commands to control the robot.
pi@raspberrypi:~ $ cd roombarobot
Replace the index.html file in the /var/www/html folder with the index.html file in the /home/pi/roombarobot
Change "YOURIPADDRESS" to the static IP address you setup in Step 1 and save the file.
Example:
On another computer, open up a browser and enter your Pi's IP address. You should see the control web page
with a box on the left, streaming video from your webcam, and the web control buttons on the right.
Browser Controlled Roomba Robot With the Raspberry Pi Model 3 A+: Page 8
Step 4: Setup and Test the Code
This code is written in python and requires the tornado library. The code uses the library to set up a server to listen
for commands from the control web page via websockets on port 9093.
Install pip
Once running, you should see "Ready" in the terminal. Open the control web page in a browser and click connect.
Then click any of the directional buttons on the page. You can also use the arrows keys on your keyboard as well.
Browser Controlled Roomba Robot With the Raspberry Pi Model 3 A+: Page 9
Ready
connection opened...
connection opened...
received: u
8
Running Forward
connection opened...
received: l
6
Turning Left
connection opened...
received: d
2
Running Reverse
connection opened...
received: r
4
Turning Right
Bugs
I have noticed a problem with the shutdown button on the control web page. Sometimes the shutdown button does
nothing when it is clicked or tapped. I have not been able to figure what is causing this, but there is a workaround.
If you are wanting to power off the robot and the shutdown button doesn't work, reload the page, click / tap the
connect button and then click / tap the shutdown button. It should power off.
Step 5: Assembly
As mentioned before, you do not have to use a Roomba for this project. Anything with two motors, two wheels and
a frame would work. I took the Roomba apart and removed everything except the wheel modules and the battery.
Wheel Modules
Browser Controlled Roomba Robot With the Raspberry Pi Model 3 A+: Page 10
The Roomba's wheels and motors are housed together in a removable module. Each module has a blue outer
housing containing the motor, gearbox, wheel, suspension spring, and interface board.
Interface Board
Each interface board has six wires running to it. There are two wires(Red[ + ], Black[ - ]) that rotate the motor, one
data wire for a hall effect sensor, one wire for the wheel drop switch, one 5V wire, and one GND wire to power the
sensor. You will have to take the module apart to access the interface board. I removed everything back to the
motor and soldered new [ + ] and [ - ] wires to the motor (see photos). It is up to you whether you want to preserve
the sensors or not.
Suspension Springs
Once you remove the vacuum portion, the Roomba's weight gets thrown off. If you do not remove the springs the
Roomba will sit at an angle. I originally removed these, but then added them back when I found it was struggling to
roll over carpet. Putting the spring back fixed the problem.
The motors are facing away from each other. That means that in order to drive the Roomba in a forward direction,
one motor will have to rotate forward while the other rotates backward. I did not think much about this until after I
wired everything up. I ended up just writing the code around how I initially wired the motors. This was a happy
accident because whenever the Raspberry Pi powers on/off, there is voltage output to the GPIO pins. The way I
have things wired up, the Roomba spins until the Raspberry Pi has booted up (about thirty seconds) and spins
when shutdown until the power is removed. If wired differently, it would would potentially roll forward / backward
which would be irritating. I plan to eventually fix this with a simple switch for the motor controller.
There isn't a lot that goes into putting everything together. I stripped the roomba down its chassis. With the cover
removed, you can easily clip off the existing plastic standoffs and drill holes to mount the electronics. There are
existing ports for running cables from the motors. If you are using the stock Roomba battery, there is already a
cutout for access to the battery terminals.
Browser Controlled Roomba Robot With the Raspberry Pi Model 3 A+: Page 11
Batteries
I used separate batteries for the Raspberry Pi and the motor controller. The Pi's battery is just a 5V battery pack
used to boost cellphones. For the motor controller I used the original Roomba battery that came with it. The battery
terminals are not labeled, so it is best to check the the voltage with a voltmeter before you you wire it up to the
motor controller. To attach the wires to the Roomba battery, I used four neodymium magnets (see photos). I
soldered two of the magnets to the wires and the other two I stuck to the battery terminals. Soldering
demagnetizes the magnets. However, the coating on the outside can still attach to the magnets on the terminals
and conduct electricity. This makes connecting and disconnecting the battery a piece of cake.
Testing
Once you have everything together, verify that you have everything wired up correctly, prop your robot up on
something (so it doesn't roll away), and power it on.
Go to the web control page and test it out. If everything is wired up correctly, the wheels should rotate in the
corresponding direction when the buttons are clicked / the arrow keys are pressed (don't forget to click connect).
2 1
1. wheel module
2. wheel module
Browser Controlled Roomba Robot With the Raspberry Pi Model 3 A+: Page 12
1
4 1
3
Browser Controlled Roomba Robot With the Raspberry Pi Model 3 A+: Page 13
Step 6: Starting the Python Code on Boot / Finishing Up
The last thing we need to do is tell Raspbian to start the python program on boot. To do this we are going to make
script and schedule it to run at reboot using crontab.
#!/bin/sh
#startrobot.sh
cd /
cd /home/pi/roombarobot
sudo python roombabot.py
cd /
pi@raspberrypi:~$ sh startrobot.sh
The roombabot.py program should now start when the Pi is rebooted or power cycled.
Finishing Up
At this point you should have a functional robot that you can control using the browser from any device on your
network. I have taken this a little further since the original build and setup a VPN to be able to access the robot
when I am away from home. I intend to make some additional changes in the future. I plan to make it autonomous
and possibly follow movement while still being able to take over the controls when I want.
Thanks!
Browser Controlled Roomba Robot With the Raspberry Pi Model 3 A+: Page 15