Some Background…
After I bought my Raspberry Pi I went through a little period of uncertainty that most other owners have, asking myself “how do I make this thing useful?” It didn’t take long before one of my colleagues created a GitHub repository for a little project that had been sitting around for a while – TeamFlash.
TeamFlash is a build light client app for TeamCity. It monitors the build server to find the status of the latest build and flashes a light in a different colour depending on that status. Having a little bit of electronics know-how, I wanted to see if I could make my Raspberry Pi into a standalone build light.
First up, I knew there had to be someone that’s interfaced with the GPIO ports. Within a few seconds of deciding to search I stumbled upon the RPi Low-level peripherals page. This has a sample of driving the GPIO using C# linking to the RaspberryPi.Net GitHub repository. It has one moving part – Mike McCauley’s BCM2835 library. Brilliant! Now to get it working…
Getting Started
The RapsberryPi.Net README has instructions on how to compile the BCM2835 library into a statically linked library named libbcm2835.so. To use GPIO from Mono I simply:
- Compiled the BCM2835 library
- Compiled the RaspberryPi.Net project
- Took the output of both and added them to my Dependencies folder
- Added RaspberryPi.Net.dll to my project as a reference
- Added libbcm2835.so to my project as a linked file and changed its build action to Copy if newer
Now I can write code like:
1
2
3
4
|
var led = new GPIOMem(GPIO.GPIOPins.GPIO01); led.Write( true ); Thread.Sleep(1000); led.Write( false ); |
Running TeamFlash on YOUR Pi
Here’s how you can get TeamFlash working on your Raspberry Pi.
Step 1 – Wiring it up
I’ve got some standard LEDs from an old Arduino kit, so I’ve hooked each of those in serial with a 330 Ohm resistor to ensure the forward current is within the correct range.
For more detail: A Raspberry Pi Build Light for TeamCity in Mono