PI Hard with a Vengeance

A novice explores the Raspberry Pi.

Archive for the ‘Programming’ Category

Motion activated Screen Saver in Python on Raspberry Pi

leave a comment »

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

pir_test

Advertisements

Written by pihard

May 8, 2013 at 6:43 am

Installing the Gertboard Software & ATmega328P

leave a comment »

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 »

Written by pihard

May 6, 2013 at 5:14 am

Arduino Mega 2560 + Raspberry Pi experimental platform

leave a comment »

image

First experiment with a mobile platform using the Raspberry Pi and the Arduino mega 2560.  The kit comes from Sainsmart.com and is a very basic starter kit with the mega 2560, motor driver board and the sensor shield as well as most of the car parts themselves. I purchased them from Amazon.com for about $80 each.  Not bad when the Mega alone sells for $60+ bucks.
  We purchased 2 of them so my son and I can build them together. They have been very educational, but even more aggravating. The paperwork has to be searched out on the internet, and has been written by running another language through some translation software. Needless to say, the documents in English do not say what is intended and is very hard to decrypt. Same for the support site. The forums are updated, but it looks like the replies to customers are run through translation software. Plus user photos are missing from the forums.  The last avenue of support…. They say there is a support wiki, but when I try to log from multiple links, I get the dreaded ‘forbidden access’ error message.
  I am not alone here, everyone has problems with the wiring and getting help solving it… Almost nothing in Google searches as well. 4 paragraphs in the instructions does not help wire it… It really needs photos to show the connections the instructions can’t express.
  The vehicle is pretty straight forward and can be done from the instructions. I have worked in hobby electronics and know that I will figure it out soon, mostly because I own test equipment and know what to look for.  But for the average person entering into Arduino and robots? I would really research this kit first and understand what needs to be plugged into where,  before purchasing it. Their instructions are on the web (check amazon’s product description for the link.) be sure to read the ‘coding’ section, since that has the few paragraphs on the wiring.
  Overall, I am impressed with it and think it is well worth the money. Very configurable and can be expanded forever. If Sainsmart would develop their documents a little better, this could be the ideal entry level system at an incredible price! The way it is?…. I am going to learn more about computer hardware and electronics than I had planned too.
Stay tuned…. PI Hard!

Pi Hard With a Vengeance using WordPress for Android

Written by pihard

April 24, 2013 at 8:31 pm

%d bloggers like this: