Build Monitor on Raspberry Pi
I'm starting a small but slightly ambitious project, around integrating several bits of technology that I've never had fully working together so in the spirit of divide-and-conquer here's a quick snippet to create a build monitor on a raspberry pi using some python code, the GPIO library and some basic electronics.
Electronics
You will need a couple of electronics bits and bobs for this project:
- Raspberry Pi (running Raspbian or similar)
- Breadboard
- Red LED
- 330 Ohm Resistor
- Jumper Wires
Wiring
The Raspberry Pi has specific pins on the connector set aside for power, ground and GPIO. Refer to the GPIO documentation to work out which pins you want to pick for power and IO (and change the code below if you decide to pick different output pins). The IO pins are subtly different on each version of the PI so if you aren't sure which Pi you have you can find the right version here.
Code
# Circuit Diagram
# Pin7 (GPIIO4)
# --¬
# |
# |
# _
# \ / Red Led
# ---
# |
# -
# | | 300 Ohm
# | | Resistor
# -
# |
# --
# Pin 9 (GND)
from gpiozero import LED
import time
red_led = LED(17)
blink_time = 0.5
while True:
red_led.on()
time.sleep(blink_time)
red_led.off()
time.sleep(blink_time)
Running the code, you should see the LED blinking on and off.
Build Monitor
Now a build monitor is supposed to keep an eye on a build process and report on good builds by showing a green light and failed builds by showing a red light.
We can add a second coloured LED to the circuit and attach it to a different output pin on the pi. So a good build (controlled by a variable for now) will show one LED and a bad build will turn that off and turn on the other LED.
from gpiozero import LED
import time
red_led = LED(17)
green_led = LED(18)
blink_time = 0.5
build_good = True
while True:
unused_led = red_led if build_good else green_led
status_led = green_led if build_good else red_led
unused_led.off()
status_led.on()
time.sleep(blink_time)
status_led.off()
time.sleep(blink_time)