Ask Hack Learn Share!
Let’s introduce the parts of our prototype.
Raspberry Pi (RPi) is a computer the size of a fist. We chose to install a Raspbian distro which is a debian distro tailored to fit into this small device.
Arduino is an open-source electronics platform that is incredibly powerful as an automats controller, with many sensors and periphrals available. In our prototype we wired it to a bread board with 2 leds, a red one on pin 2 and a green one on pin 3, and connected it to the Raspberry Pi over an USB cable.
Our Continuous Integration server of choice. Will be making API calls to the Sinatra web app running in the Raspberry Pi to report builds outcome.
Then it was just a matter of ssh-ing into the RPi and install things, the user is pi
and password raspberry
if I remember correctly. From now on, all bash commands are to be run in the bash of our debian in the RPi.
There exist many options to develop robots in a RPi, we chose Ruby as our language of choice, so install it with sudo apt-get install ruby
Download and install gort a Command Line Toolkit for robots.
If you want to follow along the easiest would be to clone the code of our prototype on github. So install git: sudo apt-get install git
. Clone the repo, cd into it, do gem install bundler
, and then run bundle install
.
Inspired by a BaRuCo talk we chose the artoo project to be able to develop the robots using Ruby. The artoo project is awesome, it even provides an API to communicate with the robots. Our sinatra server just talks to the robots over this API.
To communicate the RPi with the Arduino we chose artoo-arduino which contains the drivers and adaptors to talk to Arduino using the Firmata protocol from the RPi.
Now install the Arduino in the Raspberry Pi.
To communicate from the RPi to Arduino you need to get the address of the Arduino, so do:
Or using gort do
the ttyACMO part is the address of the Arduino.
Check the robot.rb file and change the values in line 5 for your Arduino’s address, and in line 8 and 9 for the correct led pins you choose to wire the breadboard.
We are ready to start it, now run
The first and second line connect the RPi and the Arduino over the Firmata protocol. The third one starts your sinatra server. To see the action as it goes do tail -F *.logs
if you like.
The CI needs to be configured to do a call to the Sinatra when a build succeeds and also when it fails. Basically this:
First get the ip of your RPi in your network, run ifconfig
.
Then configure the Jenkins by going to the Configure page of the project. Then at the bottom press the button Add post-build action and select Post build task. We detected the build outcome by finding the words FAILURE and SUCCESS in the build log and then do the corresponding call above.
Now is time to build your project and see lights go green and red!
You can see a demo in this video
or even the slides for the Xing meet robots presentation.
Credit is due to my team mates in building this prototype Ricard Sole and Krzysztof Heród for an Innovation Week at XING.