16-LED Stripboard Top Schematics, Soldering, and Testing
I had decided to design the top board of the enclosure with several LEDs, 3 LEDs on both side, and a Raspberry fruit (6 red LED) and 2 leaves (4 green LED) in the middle. Before getting started, I did some experiment on a breadboard, and quickly discovered that 5V LEDs can’t simply be put in series (2 LEDs require 10V, 6 LEDs 30V and so on), so I had to connect them in parallel with a resistor for each. My initial plan was actually to use 11 LEDs in series just for the Raspberry, which I scaled down to 6 LEDS in parallel due to lack of space.
Since the LED are 5V, and Raspberry Pi GPIO output 3.3V, you need a transistor to handle voltage difference. The transistor base resistor is to limit the GPIO current (33k Ohm resistors worked for me), and I selected the LED resistors based on breadboard trial and error. 220 Ohm seemed good for red and yellow LEDs, as well as small green LED, but I had to with 75 Ohm resistors for the green LEDs, as they were just too dim with 220 Ohm resistor.
I bought my components from dx.com and ebay:
- 50x 2N2222 NPN Transistors – $1.13
- 5x Perfboards – $6.60
- 100x 5V LEDs (Green/Red/Yellow) – $4.60
- 2500x resistors with different resistances – $17.60 (I think I may now have enough resistors for the rest of my life…)
- 40x 30cm breadboard wires – $4.90
I decided to only show the LED on the top of the board, and solder all other components on the other side. You just need plier to cut the components wire leads as close as possible from the stripboard surface.
I started soldering the 5V line, and you can see I struggled a bit at that stage to connect the soldering pad. Finally, I found out I had to remove the soldering iron quickly, as soon as the solder was melt on 2 adjacent pads, and the rest of the board looks a little better.
Before testing it, you’d better check, and even double check, the connections with a multimeter, or you may damage your Raspberry Pi if something goes wrong. I connected 5V and GND to the 26-pin header of the Raspberry Pi, as well as the 3.3V pin to test the 9 inputs (and 16 LEDs). Once I confirmed everything worked, I used a glue gun to add isolation between parts that present a risk a short-circuit.
Relay Stripboard Side Schematics, Soldering, and Testing
I adapter the schematics above from susa.net, as I did not need the extra D1 diode as it is already part of the relay board. Instead of BC337 transistor, I used 2N2222 with a 33 kOhm transistor base resistor. I also threw caution out of the window, as I connected 220V load, but more on that later.
I used 7 stand offs to fasten the relay board to my perfboard, adding some screw isolation caps, as the 3 stand-offs screw at the top were too long. The 3 pins on the left of the picture below are + (Connected to 5V), – (Connected to Ground), and S (connected to GPIO 25 on RPi). On the right you are three pins of the load with COMMON in the middle, NC (Normal Close contact) and NO (Normal Open contact) on the sides. If you want your device to be ON by default, connect NC and COMMON, otherwise NO and COMMON.
As with the LED board, I checked the connection with a multimeter first, and then with a breadboard. Since using 220V with a breadboard would be suicidal, I decided to use a 5V LED for testing instead, using the connection diagram from openhomeautomation.net.
Software – Linux, Controlling LEDs with GPIO and the Relay with a Web page.
There are already many instructions available to control Raspberry Pi’s GPIO, setup a web server, etc… But I added a little challenge to my setup by using a 256MB SD card. That means Raspbian cannot be installed, you have to cross-compile your program, as there’s not enough space to install the GCC toolchain, and you can’t use web servers like Apache2 or nginx either. That may look like self-inflicted unnecessary pain, but it’s a nice training exercise, as it’s much closer to what engineers actually use to develop networked embedded devices.
Since I can’t use Raspbian, I’ve decided to use a minimal image built with Yocto instead. I’ve already written the instructions to use Yocto for Raspberry Pi previously, but I won’t use the exact Yocto image I generated in that post, as I’ll have to enable more options in busybox.
We can’t build anything directly on the Raspberry Pi, so we need to find a cross-toolchain. The good news is that Yocto already made one for us (and itself) which you can find in ./poky/build/tmp/sysroots/x86_64-linux/usr/bin/armv6-vfp-poky-linux-gnueabi/ directory.
Let’s add it to our path:
I’ll use bcm2835 library to control the GPIOs, so let’s download, build, and install it to ~/edev/rpi/gpio directory:
cd ~/edev/rpi mkdir gpio cd gpio wgettar xzvf bcm2835-1.26. cd bcm2835-1.26/ ./configure --target=arm-poky-linux-gnueabi- --host=arm-poky-linux-gnueabi --prefix=/home/jaufranc/edev/rpi/gpio make make install
I’ve written two simple C programs:
- gpio_out.c – Use to set a GPIO pin high or low. Usage: ./gpio_out [pin] [value]. I’ll use it to control the relay.