Archive for May 2013
Our main blog is now hosted at Pihard.blogspot.com Read the rest of this entry »
The past few weeks while installing my Raspberry Pi and Gertboard, configuring and testing other people’s software…I have been sitting on an idea for my first project. On one of my run’s to Radio Shack, I found a Parallax Passive Infrared (PIR) Sensor for only $5. Unknown if it would even work with my system (voltage and sensor type), I picked it up with this single idea in mind.
The idea was to have the PIR sensor detect me as I come into the room and turn off the Raspberry Pi’s Energy Saving Screen Blanking. Well I dived right in and taught myself enough Python to get the sensor up and working (yes, the Parallax Rev. B PIR Sensor will work at 3.3v. (or 5 off the board as well)). I even managed to get the HDMI to engage and Disengage the power saving Screen Blanking. But it is a hardware issue that requires the screen to be redrawn to put the desktop back on the monitor. Something that most people think isn’t possible right now on the RPi (I have a few ideas on that though…). But even if I did get it working through TVService calls, it would not be feasible for the average user to try it out because it would have to be configured to each and every HDMI’s individual settings.
Well, my solution for now, is to run the xscreensaver service and let the PIR handle shutting down the screen-saver when I approach the computer. Not exactly what I was looking for, but still a fun and useful first project. I am going to share it with anyone who would like to try it. Shouldn’t need a Gertboard. It only needs one GPIO pin for the PIR’s signal line. I chose 25, but it can be any unused gpio io pin. Then a 3v3 or 5v pin for the PIR “+” lead, and a ground for the PIR’s “-”
lead. Real simple, that’s the hardware except for the placement of the sensor, but that will be a personal choice for each person. Last thing about this hardware, the Parallax PIR sensor has a high and low setting. This is to adjust the range to between 15 to 30 feet. The sensor is ideal for the PI/Gertboard since it can run on 3-6 volts. It runs great on 3.3v.Now onto the code. Written in python. My first attempt after just learning about it a couple weeks ago. So please be kind in your critiques. It should run on everyone’s Raspbian system the way it is. One thing that will be required to run it “as is” is the xscreensaver configured and running on your X desktop. If you haven’t installed it yet, you can get it with the simple shell command:
sudo apt-get install xscreensaver
(or use the synaptic or aptitude package installers…). After configured and tested. Then all you need to do is run code from a terminal using the command:
sudo python pir_test.py
It will give you a notice that you have 30 seconds to leave the PIR sensor area and then your screen will turn on your selected screen-saver. Walk into the area and as soon as the PIR sensor detects you, the program deactivates your screensaver, resets the gpio port and exits back to your desktop. Sweet, simple and all done in a few lines of code.
I really urge you to enter the code by hand and try to understand what each line is doing. The downloaded Python Code is FILLED with comments. My comments aren’t at all necessary. They are just to help you understand what is going on in the code. It is also not the only way to do the exact same thing. I have found a couple different ways to do each thing in the code, This is just the way I put it together. It is usable as it is, but not practical if you have to activate it every time you leave your computer. It would take a few more line to make it check to see if anyone is at the computer and have it activate if no one is around for 10 minutes. Not too hard to get it running when you desktop starts and have it loop so it runs continuously and resets itself when turning off the screen saver. These are a few of the next steps I am going to take with it. I would love to see others take this tutorial and make something useful out of it. If you do, please let me know!
Here’s The Code: pir_test.py
First I would like to mention a site for anyone new to linux. http://cli.learncodethehardway.org/book/
I consider myself a newbie although I ran a multi-line Dial-up BBS (1200Bps!) on DOS back in the late 80’s early 90’s and used a linux shell account to import Internet e-mail and Usenet newsgroups for my users. Now that I am starting with the Pi, I have to learn the basics all over again. Anyhow this site is a really quick read, just over an hour and I think I am up to speed with the basic shell commands again. Someone with no experience with CLI might take a bit longer, but it is a free site and very informative. I Absolutely recommend it to the beginner. (I am now using the sister site for Python learnpythonthehardway.org/book/..looks like it will take a bit longer to complete, but just as “easy going”!)
Now for what I have been doing the past few days with the Raspberry Pi. I have fully installed the Gertboard and all of the related software. It has taken a lot of research and hunting since the software and details of the complete setup are in several different sites. I read and did ALL of the sample projects in the user manual. (Python Samples, not the “C”. I also got both the RPi.GPIO and the WiringPi for Python versions working so I could try all the examples!)
Not knowing Unix very well, was quite a learning experience. The hardest part was actually getting the ATmega up and running properly with the Arduino IDE. Not at all like installing an arduino ATMega (USB) or Read the rest of this entry »
Just received my new Raspberry Pi and the Gertboard! So here’s a picture of the new case with both installed. Works way better than I could ever imagine!
One thing that makes me nervous is working on the RPI and Arduino with all the circuits exposed. Well I had some acrylic plastic sitting around for the past few year and I had a spare 30 minutes this afternoon, so I cranked out a protyping platform/protective case. The boards will mount inside so they are secure. All 4 sides are open so I can run wires in and out with no problems. On the very top I think I am going to mount the solderless breadboard. The top cover comes off by removing the 4 top nuts. Maybe make it even easier by using wing-nuts or even barrel-nuts if I can find them. The whole thing measures 8×9 inches and the opening is a generous 2″ inches. Enough room for the raspberry pi, an Arduino mega 2560 and a relay board or motor controller.. Can even stack my pi face or Gert board. If there is any interest, I took a lot of photos and could make an instructable with all the details. Really easy and a quick afternoon project that looks great. So if you would like to learn more, leave me a comment and let me know! Pi Hard With a Vengeance using WordPress for Android