I’ve been looking for ways to control my Service droid robot, my Service droid robot has an ATmega2560 (with Arduino bootloader) and a Raspberry Pi. My goal is to control it over wifi. But I wanted to start with some more simpler things first. I’ve recently found some python code on letsmakerobots.com that lets me sent data over I2C from a Raspberry Pi to a micro controller.
Before getting this to work you need to configure I2C on the Raspberry Pi. Adafruit has written a nice guide how to do this. I also installed the python-SMBus package: sudo apt-get install python-smbus.
The Raspberry Pi’s gpio pins are 3.3V and my ATmega runs at 5V so I used a logic level converter to connect both. I connected my Bajduino Mega 3A board to the Raspberry Pi. My big Bajduino has an I2C logic level converter on board so I didn’t need to connect any extra electronics.
To test the Raspberry Pi I2C to Arduino connection I found some useful information on Oscar Liangs blog.
I then started modifying the code I found on letsmakerobots so the small webserver serves a webpage with 4 buttons. By pressing a button the python code will sent a command over I2C to the ATmega. By pressing the buttons I can control 4 leds connected to the ATmega. The webserver runs on port 888, I tried running it on the default webserver port 80 but couldn’t get it to work. I also have to run it as root, else I couldn’t access the I2C pins. This is a security issue, not something you want to try running on the internet.
You can download the python code here: webserver.txt (rename to .py)
Here is the Arduino sketch
I’m not sure if I will use this code to control my service droid robot. I’ve also been looking at using Apache with cgi to run python code. This is a bit harder to setup and write code for. So I’m still a long way of to control my robot over wifi with my Raspberry Pi 🙁
4 responses to “Controlling an Arduino through a Rapsberry Pi webserver”
Have you had any luck with this? Any git links?
I’m still scratching my head on how to control my robot through a nice web gui..
on my new raspberry pi 2 model b
i have been able to use berryboot and ubuntu with crome
and down load the ide for arduino
and program code pass from the pi 2 to my arduino uno
the new quad core cpu and gb of ram makes it happen
I am writing this to you on the pi two
so it is my new development environment
just a pi two and arduino uno and that is it in front of an hd tv
simply awe inspiring
a revolution is about to take place
where these two devices open the world of computing to many
I facing error with python code webserver