Thursday, August 7, 2014

Raspberry Pi Powered by the Sun!

In The Beginning…

Ever since the Raspberry Pi came out, I was entranced by the coolness factor of having a small pocket sized computer that cost just north of thirty bucks. Hats off to those devoted for making this project a reality and launching it to the world. The only problem for me at the time of Pi launch, was the fact that I lived in a Windows world, and to an extent, still am. I had no rad Linux skills. No formal or informal training. I got my hands on an installation disc of Mandrake way back in the day when I did call center tech support. The only way to get that geek cred in that place was to show you knew your stuff. I took that disc, spun it up in my 32x CD-ROM drive, wiped my Windows partition (you know, cause this open source stuff comes at a college student budget), and stepped through the install. After it was all said and done, Windows was back as soon as it had gone. FAIL. I had similar experiences with Red Hat and Ubuntu, but I did manage to get wireless working on the former, but it was too much of a pain to deal with when it was so easy to make it all work in Windows.

Flash forward to today. I’m still in my Windows world due to the place I work, but much more comfortable with Linux and even got my LPIC-1 certification. I’ve had my Raspberry Pi which was used to study for the aforementioned cert and has since been sitting in a lonely dark drawer next to a twice used wicked looking webcam I got from WGU. This dark and dreary future was not what I had envisioned for the poor Pi. There are so many cool projects out there and one that caught my eye was from a guy who had a web server running off a Raspberry Pi that was powered by the sun and 4AA rechargeable batteries. How cool does that sound?! I put this on my list of things I must do. After about a year or so I finally decided to shed some light on this project (did you see what did there?).

Let’s Get To Work

To kick this thing off, I went back to that old project page and got some information on power consumption of the Pi. Knowing I’m going to run this headless, that would save on the load drawing from the battery if I had attached some sort of touch screen. I tried to figure out the math behind how long it would run on a full charge before shutting down and going to bed which lead me to ask, what battery pack should I use? The original idea had AA batteries which fit the project scope, but I wandered over to my favorite maker’s page, adafruit.com. Searching the shop, I was happily greeted with my power answer and a plethora of parts and/or kits for everything Raspberry Pi. The parts I finally opted for are as follows:

·         Medium Solar Panel (6V, 2W) https://www.adafruit.com/products/200
·         USB / DC / Solar Lithium Ion/Polymer charger https://www.adafruit.com/products/390
·         Lithium Ion Battery Pack - 3.7V 4400mAh https://www.adafruit.com/products/354
·         Male DC Power adapter - 2.1mm plug to screw terminal block https://www.adafruit.com/products/369
·         PowerBoost 500 Basic - 5V USB Boost @ 500mA from 1.8V+ https://www.adafruit.com/products/1903
·         2 x JST 2-pin cable http://www.adafruit.com/products/261
·         Large Plastic Project Enclosure - Weatherproof with Clear Top http://www.adafruit.com/products/905
·         Waterproof Metal On/Off Switch with Red LED Ring http://www.adafruit.com/products/916

PowerBoost 500 Basic with USB
connector soldered on.
When the box showed up safe and sound, I was set. The USB Solar charger had to have the included capacitor soldered on to the PCB, the PowerBoost also needed the USB A jack to be soldered on. This was pretty easy and really one of my first soldering attempts at putting components onto a PCB (The only other things I’ve soldered were Deans connectors onto batteries).
USB/DC/Solar LiIon/LiPo charger
with capacitor soldered on.

Next, the battery had to have the JST cable soldered on. I left them long just in case I needed the extra length when fitting this all inside the enclosure. The last soldering to be done was to solder the two remaining JST cables together for the link between the charger and the PowerBoost. I did not show the soldering steps because if I can do it, you can too. Believe me. Finally the solar panel came with a plug that would not fit the USB charger. Easy fix was to nip the tip and add the 2.1mm plug.

That’s Great, But Does It Work?

Testing the PowerBoost 500 with the battery.
When a coding project gets near completion, I start looking at the components and wondering “how did I break this part?” The same holds true for this one. The PowerBoost and the charger, where I had to actually solder components to the PCB, were my biggest concern. Batteries I’ve done, but this seemed to be a more delicate operation. This is the point where I start testing the theoretically completed parts. So I plugged the battery into the PowerBoost and was delighted to see the green power LED light up. Does it power on the Pi? After plugging in the USB cable to both the PowerBoost and the Pi, the little pocket computer powered on. Success!

Ok, so that’s one part down. What about the solar panel and charger? Taking the solar panel, battery, and charger outside, I connected it all together. Again the LEDs that indicate charging came to life! Success x 2! It may seem pretty basic to a lot of you out there, but it’s small things like this that amaze me. Also, keep in mind I am the son of someone who has taken electrical engineering classes, yet still stuck his finger in a light socket to see if the power was still on.

Putting it all together with all components working should yield a working solar powered Raspberry Pi, right? I’m usually cynical when it comes to situations like these and usually expect the worst, so I won’t be disappointed when that outcomes happens. But today, things just clicked. Moments like this put a big smile on my face. The Cynicism Demon was slayed. Now to the next part of this project. Getting the Pi to run headless.

Prep the Pi

Since I used this Raspberry Pi to use as study for the LPIC-1 exam, a lot of the work was already done. But that was so long ago and it needed an update. More requirements popped up such as static IP address on the wlan0 interface and remote desktop. I also ran into the problem of having forgotten my user pi password since it was setup so long ago and so quickly neglected, thrown into a locked drawer, and forgotten about. But times change, things are brought out back into the light. Used for new purposes. First thing’s first, get wireless working.

For the wifi adapter, I had a very tiny Wi-Fi USB adapter from Edimax (EW-7811Un) being used in a security lab I setup earlier this year. When I got this adapter, I envisioned using it for the Pi, so the lab will suffer a little bit but these are so cheap on Amazon, I’ll be grabbing another soon. Setting up Wi-Fi was a little more difficult since I didn’t have a mouse to click on things (one USB for the Edimax and the other for a keyboard).

These are the steps I took to get Wi-Fi working on my network:
1)      Plug in the Edimax
2)      Power on the Raspberry Pi
3)      Ctrl+Esc and run wpa-gui.
4)      Tab through to the Manage Networks tab and fill in the blanks for SSID, Authentication, Encryption, and PSK.
5)      Tab to the Current Status tab and try to Connect. I had to reboot my Pi before it would connect to my access point.
6)      Upon connection, you’ll see the IP address populate on the Current Status tab.

Once I got connected to the access point and was able to successfully ping outside of the network it was time for updates. A quick apt-get command and everything was all set. So static IP shouldn’t be too hard, right? I spent about thirty minutes to an hour fighting with having the wlan0 interface retaining a static IP. Here are the steps I took to resolve this:

1)      Bring up LXTerminal
2)      Type: sudo nano /etc/network/interfaces
3)      Change the line “iface wlan0 inet dhcp” to read “iface wlan0 inet manual”
4)      Change the line “iface default inet dhcp” to read “iface default inet static”
5)      Add these lines after the above line: “address 192.168.xxx.xxx” “netmask 255.255.255.0” and “gateway 192.168.xxx.xxx” where xxx is your subnet and host octets.

I also checked wpa_supplicant.conf to make sure it all looked fine (and it did) by using the following command:

                Sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

This shows SSID, PSK, encryption type, etc. Basically everything you see in wpa_gui. I changed nothing in here. Now, the above solution is a little weird. Why not just set wlan0 to static? At first I did and got nowhere fast. The only thing I could ping was the loopback interface and my static IP address. Couldn’t ping the gateway IP although I did specify it. The above solution was the only thing I could come up with and make work after rebooting a few times to make sure it auto connects.
At this point, static IP and wireless are working. Just need to make remote desktop work. For this project, I do not need to access the Raspberry Pi desktop from outside of my network. For this feature you may press your luck with Google. Also, this is for connecting from a Windows based laptop to the Pi. I’m using xrdp for my remote desktop solution. I had already installed this feature when studying for the LPIC-1 exam, but here are the steps to install it:

1)      Bring up LXTerminal.
2)      Type: “sudo apt-get install xrdp”
3)      If it asks for your password, please feed the pi the password.
4)      This should begin installing your software for remote deskop, xrdp.
5)      Restart the Pi. This should get the Remote Desktop Protocol server running.
6)      You can verify this when the Pi boots up by finding the line: [OK] Starting Remote Desktop Protocol server : xrdp sesman. My Pi boots directly to the desktop so I have to be quick to find this line when it boots. If yours boots to command line, you’ll be able to easily find this line.

Great! RDP is up and running on the Raspberry Pi! Let’s jump back to the Windows world for a second.
1)      On the Windows laptop, bring up Remote Desktop Connection and enter in the static IP address we gave the Pi and hit Connect. You may get a security warning, hit OK since we know you got a nice safe Pi.
2)      You’ll be presented an XRDP login prompt showing Module, Username, and Password. Leave the module defaulted to sesman-Xvnc and type in your username and password (the default username is “pi” and the default password is “raspberry”).
3)      Click OK and peer through the Windows to the world of Pi.

Now, I had trouble on this part of the process because I didn’t remember the password I set for the user “pi” so long ago. There are a couple options to fix this:

1)      From an LXTerminal window, use the “sudo raspi-config” command to run the starting config and change the password that way.
2)      From an LXTerminal window, use the “sudo passwd” command.

I used option 1 which was quick and simple.

That’s about it for prepping the Pi. I haven’t really come up with what I want to do with the Pi. Should it be a web server, ftp server, etc.? or should it be used for a surveillance machine, like Ike created. Or should it be used for weather reports? Time will answer that question. But to finish out the build, we need to look at fitting all this stuff in a box.

What’s In the Box?!

So many drawn diagrams.
So much planning.
I’ve spent a few days looking at how to put all these parts in the box. I took measurements of the components with calipers. First observation was pretty obvious: All components including the Pi cannot remain on the same plane. That means shelves. The box has two M4 bosses that will work as a starting point for creating two shelves within the box. Bottom shelf will house the battery, charger, and PowerBoost. Top shelf will house the Pi. According to the tech specs on adafruit.com, this box has an internal height of 70mm. So there is the first constraint I had to deal with. How should I lay the planes in the box? I went with a 3.5”x6.5” plane for both top and bottom. These measurements gave me just enough room to fit the middle 90mm x 167mm space in the box. I drew out a few diagrams, namely, top down view of the inside of the box, a side view with components for vertical spacing, and one top down view of the shelves for placement of the components. Laying out the components was not too difficult when drawn out on paper (yeah, I guess I’m old school. No CAD here). Getting stand offs for this project proved a bit of a challenge. I had some of those jack screws you’d find on the back of a pc or laptop on either side of the video connection to support the video cable and some screws from the inside of a laptop. These screws seemed to fit but wouldn’t go all the way into the jack screw. I threw that idea away and found some nylon stand offs but would take about twenty days to get to my door step. In the end I used 2-56x3/4 nylon screws, #2 .032”thick washers, 2-56 nylon lock nuts and ¼” #4 nylon spacers to act as a makeshift standoff. Putting all these together, they fit well and snug on the small circuit boards.

Next order of business was obtaining the material for the shelves. I went to the local hardware store and got a sheet of Lexan cut to the above dimensions. Fit perfectly in the box. Next was to place the PowerBoost and the LiPo charger to know where to drill holes. All the places were marked on the Lexan and the drilling began. This was my first time drilling into polycarbonate. I read a lot on how to drill this stuff so it would not crack. Everyone agreed to clamp the Lexan to wood and drill with a drill press. I was not able to get my hands on a drill press, so I was careful to be as vertical as possible with my trusty drill. Lessons learned on the test pieces of Lexan showed that slow and steady wins the race here. On to the actual pieces. They turned out perfect. The circuit boards were screwed in place with the nylon screws, spacers, and nuts. As they say, measure twice, cut once. This was very true here. So the first shelf is done, on to the second shelf. Only three holes needed to be cut for this one: two for the bolts to hold up the shelf and one for the capacitor on the charger.
PowerBoost, Charger, and Battery
all layed out in the enclosure.
If that last hole was not made, the Pi would not be able to fit inside the box. Taking measurements of the capacitor, I marked the location where that hole would be drilled. However, something occurred to me. The capacitor is not perfectly vertical. So I made the hole, but used a dremel to widen the area where the Lexan and the capacitor kept touching. Easy fix, but that made the top shelf look a little janky. No one will see it since the piece will be covered anyway.

Another step that doesn’t really need to be documented but you’ll notice in the photos, I used a dremel to cut off the top of the bolts that are used for supporting the Lexan shelves. This was done so I could work with the shelves a little easier and just set them into the box instead of putting the shelves on the bolts and screwing everything into place. I’m going to cap them with locking nuts to prevent any sharp edges and make it look a little more finished.

Everything at this point was looking great, but another thing popped into my head. If I continue on with the plan I had in mind, I would have to take the box apart to turn off the Pi. I need a power switch I can easily have access to. Back to my layout drawing. I saw the space I needed for a switch. Again, Adafruit.com to the rescue. I ordered the on/off switch listed above in the parts list. This switch did not come pre-wired. This was a good thing for me. That means I get a bonus for learning how to wire up the switch. Again, I took measurements to get the vertical and horizontal placement correct on the side of the box. I required a 16mm hole drilled into the side of this box, but living in an imperial world, I wasn’t able to source a 16mm drill bit, so I went with a 5/8” bit and milled out the extra .1mm. No big deal, and the hole looked pretty clean.
Testing the external power button.
The LED makes it look good!
I quickly learned how to wire up the switch so the LED would turn on when the button is depressed and off when not switched on. Back when I was soldering all those wires together, I had enough length in the wires for the job. Question now is, can I still use the same wires or do I need to get a few more inches of wire. Lucky for me, there was just enough wire after cutting the cable apart from the original plan. I decided to wire up the cable between the charger and the PowerBoost instead of wiring up the battery directly. I went this route in case I have to change out my battery in the future, this could be done with little or no effort. The wiring for the switch goes as follows: positive wire from the charger goes to the Common terminal, then a small jumper wire goes from the Normally-Open terminal to the Positive terminal, then from the Positive terminal, to the PowerBoost, then the negative wire comes out of the PowerBoost to the Negative terminal on the switch, and then from the Negative terminal to the charger. This wiring scheme allows the LED to light up when the push button is in the on position and off while in the off position.

Quickly, I hooked up all the cables to the appropriate jacks, screwed the shelves in place, and used some double sided tape to keep the battery in place and also to keep the Pi case from being knocked around on the top shelf. Screwed the top cover in place and voila, a solar powered Raspberry Pi computer!

Praise the Sun!



At this point, I am feeling really good about this project. How amazing is it when you learn new skills and overcome challenges. I learned a lot in regards to planning for a project of this scale, making a soldering job look nice, how a switch is wired up, and more. I haven’t done any long term testing as to how long the Pi will run into the night when only running on battery. However, I find it amazing that this pocket computer can inspire so many people to come up with bright ideas and make them a tangible item. Some of the notable pages that helped me complete this project are as follows:

·         How to make a Raspberry Pi solar-powered FTP server
·         Adafruit.com
·         Ike the Network Guy
·         Raspberry Pi Forums

Final product. One solar powered Raspberry Pi!

Finally, for all you Sun Bro’s out there, Praise the Sun!


No comments:

Post a Comment