Tuesday, May 20, 2014

Raspberry Pi Picture Frame Post 10 Remote and Video Demonstration

After doing some testing I was having problems with the remote working properly, and it still doesnt work quite as well as I want it to but that is what testing is for. Part of my problem was that my IOcheck.sh script had some errors in it. So I fixed those. Another issue I had was that my showweather.sh scripts were no executable. That was an easy fix, the code is below.
sudo chmod 775 /home/pi/drive/scripts/showweather.sh
sudo chmod 775 /home/pi/drive/scripts/showweather1.sh
Another item I did was each time a button is pressed I kill fbi first before trying to start the next one. {{sudo kill $(pgrep fbi)}} is the code to do that. That should go into IOcheck.sh. I also added a while loop to the if statements for each button so that it wont constantly try to reopen the fbi while you hold the button down. It wont check for input until you release the button now.The code is below.
while ["$( cat /sys/class/gpio/gpio17/value)" == '1' ]


Time for the first video of my picture frame working. Now as you can see in the video there are still some problems. Some of which I have no clue how to fix. First problem is the my photo slideshow takes a bit to start and I believe this is due to the size of the pictures. I am trying to resize the pictures down to 1280x1024 which is the resolution of my screen. I am currently using the pi to do the processing. Now we all know that the pi is not the most powerful device so depending on how many pictures you add it may take a while for this to process. If this works and helps I will add it to my morning sync. This way everyday new files will be downloaded, then resize, then the device will restart. The bigger problem than I have is the command line text you see flash on screen when switching between slideshow and weather.I have no clue how to fix this problem. I would bet there is a way but I do no know what it is so if you have any ideas leave a comment below.

I think I am going to change my weather button c to show the current weather for multiple locations instead of just one. Now it wont show a 5 day but the weather for towns where the whole family lives.

Wednesday, May 14, 2014

Raspberry Pi Picture Frame Post 9 Remote Setup

Remote Setup

Now I have already talked about setting the remote setup but we haven't gotten it completely setup. So we talked about how to get the pi to setup the individual pins as input or output. From my scripts folder the setup file is gpiosetup.sh. Currently I have 4 inputs and 1 output. I am probably going to add another input so that the pi can tell if the monitor is on or off. This way you can program the pi to turn the picture frame on every morning at 8 and off at 4 or whatever you like. While we can currently do that the pi doesn't know the state of the monitor so all we can tell it to do is toggle the display so if you use the remote to turn it off then at the scheduled time it would actually turn the monitor back on. Now my IOcheck.sh script is something that needs to be continually running. What I decided is but A will start the slideshow. Button B will show weather. Button C will show weather1 and button D will turn the display off/on. Basically we are constantly checking to see if a pin is high and if it is we run a script based on which button is pressed.

Now we need to run this script at startup as well. I am not sure why but Ted Hale doesnt put this in the same place as the slideshow start location. He puts at the end of /etc/rc.local. To edit that file we use {{sudo nano /etc/rc.local}} The line we want to add is {{/home/pi/drive/scripts/IOcheck.sh &}} and we want to add the before the exit 0 line. For those of you who are paying attention you may be wondering why do we have the & sign. What that sign does is tell the pi to run that script in the background. Otherwise we would never get anywhere because the pi would wait for that script to end and it never would.

Now at this point I believe that the picture frame is all ready to go. Testing is going to take a while which is always the fun part. Now I still have the frame to build but that can and will wait until I get some testing done. Some how my frame is going to have to let air flow because the screen generates a good bit of heat. I also want to make a good cheat cheat sheet of what does what and what goes where. Luckily most of that information is in these blog posts already. Just need to  bring them all into a simple file.

Tuesday, May 13, 2014

Raspberry Pi Picture Frame Post 8 Event Scheduler


Now for those of you who have been following along I have been doing some testing and found out that there is a slight problem with what I was doing. To make my life easier I have been keeping all of my scripts located in my google drive folder that syncs. This way I can edit them on my computer instead of having to do it via a command prompt. For the most part I still do edit them in the command prompt but it gives me options and I like options. It also means that for those of you who wants to replicate what I have done all of the files you download will always be up to date with what is on my device since I have just shared those folders with you. Now the flaw. Originally I created a user named slideshow which was the one who automatically logged on. Well do to the fact that my google drive sync folder is located in the pi user's folder the slideshow user needed special access which I do not know how to do. It keeps asking me for the su password or the password for slideshow which I did not have one setup for. So after not being able to figure out what the problem was I decided to change the auto login from user slideshow to user pi. I also had to add to the pi boot file the script to run the slideshow right away. {{sudo nano ~slidespihow/.bashrc}} add {{/home/pi/drive/scripts/slideshow.sh}} to the end of that file. Now when I reboot the slide show starts up right away.

Event Scheduler

Built into the pi os is an application called cron. this is an event scheduler. It is actually really easy to use. To open it the command is {{crontab -e}}. This will bring up a text file where you can create your tasks and when they will run. there are 6 parameters that we need to file in and they are {{m h  dom mon dow   command}}
  • m =what minute of the hour do you want
  • h = what hour of the day
  • dom = day of month
  • mon = month
  • dow = day of week
Somewhere along the line I read that fbi will fill the ram up or something along those lines and cause the pi to crash but it takes a rather long time to do that. Simplest solution to this problem is to restart the pi once a day. I also what grive to check for changes once a day so I made a script that will check google for changes, update what needs to be done and the reboot the picture frame so that the memory will clear and the new pictures will be displayed. That file is called grive.sh in my scripts folder. I randomly picked 1 am because this is going to be a present for my mom and rarely will she be up at that point so it will not bother anything. here is the line to make that happen {{0 1 * * * sh /home/pi/drive/scripts/grive.sh}} Now you may be wondering why *. Cron only runs the command if all of the place holders are true. so for my task it will run at minute 0 hour 1 of every day of every month of every day of the week. Now for my weather I am going to have that update every half hour. {{0,30 * * * * sh /home/pi/drive/scripts/weather.sh}} You see how I have 0,30. What that is going to do is at 0 minutes and 30 minutes of each hour of each day of each month of each day of the week run that command. you can do the same thing with each other holder. I also belive you can do ranges like 2-9, but don't quote me on that.

This project is really starting to come together now. Only a few things left to go.

Monday, May 12, 2014

Raspberry Pi Picture Frame Post 7 Slide Show and Weather Continued

Starting Slide Shows

It is time to start finishing up the different parts. Remember we are going to be using fbi to display the images. if you type in {{fbi}} into the terminal and hit enter it will show you all of the options for fbi. Now your preferences and mine are going to be different so I suggest that you read through what is available and choose the ones that you like. Before I get to my preferences if you are trying to start fbi from ssh you are going to have to include an extra setting so it know to use the monitor as the display instead of trying to show you them in the ssh window which just spits out an error. Now the code. I suggest you make an script for this line so if you want to change settings you can change the script instead of having to go modify boot files. If you download my files one of the files is to start the slideshow. {{fbi -noverbose -a  -u -t 10 /home/pi/drive/*.JPG}} Lets go through this piece by piece.
  • fbi = is the program we want to run
  • -noverbose = tells the program not to show the file names
  • -a = tells the program to auto zoom the pictures
  • -u = tells the program to pic random pictures
  • -t 10 = tell the program that we want 10 seconds on each picture
  • /home/pi/drive/*.JPG = /home/pi/drive/ is the directory that the pictures are in. *.JPG says we want all the pictures with .JPG file extension. Remember that linux is picky about capitalization so it will not show .jpg files. 
  • if you want to be able to start from ssh you must add -T 1
  • If you want to show multiple file types you should add this at the end of the above /home/pi/drive/*.XXX (xxx= what ever file format you want) make sure you give the directory location again.
  • You can also specify specific files if you prefer by replacing the * with the file name
Now you should be able to get a slide show started. I am not 100% sure if this is necessary but other people have included this on there guides so I will to. We need to make the script file executable. {{  sudo chmod 775 /home/pi/drive/scripts/slideshow.sh}} make sure you put file path correct. That is where mine is.

That last thing to do is have the slideshow start when we boot the device. To do that we edit the login script for the user, in my case slideshow. {{sudo nano ~slideshow/.bashrc}} You just need to add a line to the end of this file {{/home/pi/drive/scripts/slideshow.sh}}. So now every time you turn the pi on it will automatically start a slideshow using the pictures based on the information in the scripts. 

Weather Setup

 Most of the code for this section came from the kindle weather display. I had to make modifications because I wanted it to fill the screen instead of showing something designed for the kindle screen. 

Obviously the left picture is what other people have designed for the kindle and the right picture is what I changed it to so that it would use the monitor space a little better. Since I plan on having weather data for 2 different location based on what button you press I will be adding the location to this somewhere. Have not figured out exactly where yet, but that can wait until I get everything else working just how I like it. Now the process to get the weather is a multi step process. First we have the layout.

As I always suggest to people when they are doing design work for anything. Start with a piece of paper. It is much easier to sketch something out the try to throw things together on a computer. Now once you have the idea you have to get to work designing it on the computer. I did not start from scratch, but rather I took the file for the kindle weather display and modified to fit my needs. Now I am not an expert on any of what I am doing, I know just enough to be dangerous. When I redesigned the layout I got a little to ambitious. I suggest just modifing my file or the kindle one until you get it how you want.

Next we need to get the information. Again I took the kindle python script and added things until it got what I needed. This was one of the hardest parts of this whole project. I am not a programmer. I know the basics but this was one of my first real projects that used python. If I was asked to write the program from scratch I would be up a creek without a paddle and I probably wouldn't even have a canoe. After a lot of troubleshooting and research I was able to add the information that I wanted. Now whether you use my files or the files from the guy who orignally made the kindle picture from you are going to have to atleast edit the python file so that it has your correct location. there are 2 lines you need to modify. The first is the lat and lon in the 21 line of my file which is almost a direct copy of his. It is in decimal format so make sure you replace it with decimal format. You also need to find your local airport page. Go here, click on your state, then choose your closest airport. then look in the address bar. The webpage should be 4 letters.html. Change the last 4 letters of line 25 before the .xml to match the new ones.

The last step is to convert what the python script outputs and convert it to something that we can display. This is done using  rsvg that we installed in a previous post. {{rsvg file.svg file.png}} will convert a file with svg format to png. make sure that you include the directories if you are not in the correct folder. I have a script written that does this all for me automatically. Makes my life simpler. I like to run this ever 30 minutes or so and will get into that next time.

Left to do

  • Schedule events to happen and specific times
  • Program remote buttons to actually do what they are suppose to do
  • Add an input to monitor weather the monitor is on or off, will use the status led of the monitor as an output  
  • Make a cheat cheat for specific file locations
  • Build a nice frame
  • Gather pictures
  • Test
  • Give as present

Thursday, May 8, 2014

Raspberry Pi Picture Frame Post 6 Google Drive, Slide Show, Weather, IO

Step 5 Google Drive Continued

Well it took me a while but I did find a way to install grive and have it work. Thanks to Nathan HERE Below is the how to just commands no explanation why. Using a ssh program like putty will make your life much easier for this due to the steps after all the code runs. There are a few differences from his. First I added the wget to download the patch. Second I had to change the patch command because his downloadable files name changed at some point. At the end it will give you a website to go to to get authorization from google. Copy the website, go to it, accept the conditions (if you don't want grive to have access to your account then I suggest making another google account). Copy the access code to the terminal and hit enter. If everything goes according to plan, it will start synchronizing your google drive to the folder GoogleDrive (remember capitalization really matters in Linux) While you wait go get a coffee or bowl of ice cream or something, it may take a while. When it is all done it will say finished and you will have a command prompt again.

wget http://www.nburles.co.uk/sites/default/files/attachments/State.cc_.patch

sudo apt-get install git cmake build-essential libgcrypt11-dev libjson0-dev libcurl4-openssl-dev libexpat1-dev libboost-dev libboost-filesystem-dev libboost-program-options-dev libboost-test-dev binutils-dev libyajl-dev qt4-dev-tools patch

cd ~

git clone git://github.com/Grive/grive.git

patch ~/grive/libgrive/src/drive/State.cc -i ~/State.cc_.patch

cd grive

cmake .


mkdir ~/GoogleDrive

cp ~/grive/grive/grive ~/GoogleDrive

cd ~/GoogleDrive

./grive -a

Now that everything is copied you can type {{ls}} to see all of the files are copied. For my purposes if I am missing a picture or 2 its not the end of the world, if you are using this for a backup of files you may want to check to make sure everything copied. WARNING, you have to tell grive to check for files changes instead of it checking all by itself continuously. For a picture frame this isn't really an issue in my book. We will go over scheduling events later.

Step 6 Frame Buffer

Now I choose to use fbi, if I could find a command line based image viewer that had transitions I would but I havnt found that yet so I am sticking with fbi for now. The install for this is super simple
sudo apt-get update
sudo apt-get install fbi
Thats it. I wish grive could be installed that way.  Again the above and below comes from someone else work, I just brought it all together. His page can see his page HERE. Now he creates a folder to store his pictures in because he copies his pictures to the sd card directly instead of having it done automatically. Now he suggests creating a user that logs in when the device is powered and I see no reason not to so here is the code to do that. {{sudo adduser slideshow --ingroup video}}. This is going to ask you a bunch of questions. I hit enter 6 times then n then enter, then enter 5 more times, then y then enter. We now have a blank user created without a password named slideshow. Next we need to make that user log in at boot which is a little fun. First open inittab file by {{sudo nano /etc/inittab}}. Now we need to find a specific line {{1:2345:respawn:/sbin/getty --noclear 38400 tty1}}. When you find it put a {{#}} in front of it to comment it out. Add a blank line right after it and insert the following {{1:2345:respawn:/bin/login -f slideshow tty1 </dev/tty1 >/dev/tty1 2>&1}} Now exit with {{^x}} then y then enter. Now at boot the user slideshow will log in. If you did not want to create a new user you should be able to replace slideshow in the previous orange block with pi, now I am not sure if it will log in since pi has a password and slideshow does not.

So far we have gotten raspberry pi to boot, installed grieve and fbi. We can not get pictures off of google drive, and we can show them using fbi. Now its time to deal with the weather display.

Step 7 Weather display

The weather display was something that I added to what other people have already done. This was something that I thought would be a good idea, something that would take this project to the next level. My original plan was to use a web browser of some sort but I couldn't figure out how to get the web browser to load from the terminal so I changed tactics. I got the idea from the people who used an old kindle as a wall mounted weather display. What that group did was they used a webserver to download the information off the internet, and then convert it to an image than the kindle could the display. Well I thought, hey my picture frame is already setup to display images I just have to download the information. So I got the files I needed for the kindle project and made them fit my own needs. The first of which was adding information fields to the final output. See the kindle weather display only shows 4 days of weather total. Since I had a much bigger screen I figured I should show more information. I show 6 days of information, plus the day and current date.

There are 2 programs that we need for this to work. 1. is python which comes preinstalled. 2 is rsvg-convert. Now googling that may cause some problems trying to find the installer. that is because rsvg is part of librsvg2-bin so that is what we need to install{{sudo apt-get install librsvg2-bin}}. The reason we need this is because the python file creates a svg file and fbi will not display that. This outputs a png file which we can. Later I will come back to actually getting the weather information. You can download the weather files here.

Step 8 IO

Instead of adding buttons to the picture frame itself I decided it would be nice to have a wireless remote so that you could control the frame from your desk. Again there are multiple ways to access the gpio on the pi. I went with the way the guy did it from HERE. Same guide on how to setup fbi. Everytime the pi starts we are going to have to run a script to get the gpio setup correctly. I need 5 pins. 4 for input from the remote, and 1 output to turn the monitor on and off. Setup is easy enough, for each pin you need the following in a sh file. (you can download all of my required files here) Mine is called gpiosetup.sh. Every where there is an 18 make that what ever pin that you are currently using. I used 17,18,22,27 for inputs and 24 for an output. Now your probably curious why I choose those pins for those purposes. I choose those numbers so they would right by each other on the actual pin header. Here is a pin out I found on google.
# export GPIO pin 18 and set to input
echo "18" > /sys/class/gpio/export 
echo "in" > /sys/class/gpio/gpio18/direction
# export GPIO pin 18 and set to output
echo "18" > /sys/class/gpio/export 
echo "out" > /sys/class/gpio/gpio18/direction
No we need to create a script to check if any of the inputs are being activated.If you are downloading my scripts I called it IOcheck.sh. Since we want this to run continuosly we need to have a while loop. Button D on my remote is wired to gpio17. Since I had to do a voltage diver circuit to get safe voltages for pi I am not worried about setting up a pull up or down resistor in the earlier code. This also means I have a pull down physically installed. "$( cat /sys/class/gpio/gpio17/value)" gets the status of the button presses. I have found that I need to hold the button down for a little bit not just a quick press and release. In the if statement below I turn an output on for a half second, then off and wait a second. That output is wired to a transistor setup to act as a button that is connected to the monitor power button. This way I can physically turn the monitor on and off. Some people have chosen to just send a black screen or disable video output so the monitor goes to sleep but I would rather actually turn the monitor off. I may add in that if this button is help for an extended period of time it tells the pi to shut down, but I will save that for later. Copy everything between do and done below and paste it for each input you have.
while [ true ]
#Button D
if [ "$( cat /sys/class/gpio/gpio17/value)" == '1' ]
 sudo echo 1 > /sys/class/gpio/gpio23/value
 sleep .5
 sudo echo 0 > /sys/class/gpio/gpio23/value
 sleep 1


Wednesday, May 7, 2014

Raspberry Pi Picture Frame Post 5 Intial Setup, Wifi

Step 1 SD Card

Now that the hardware is ready it is time to remake the sd card so I don't have all the extra programs I installed last time while trying to get the system working. Now I am going to assume that you already have rasbian already installed, if you dont there are many different ways to install it onto an sd card but here is how I did it http://computers.tutsplus.com/articles/how-to-flash-an-sd-card-for-raspberry-pi--mac-53600

Step 2 Initial Setup

Once you put the SD card in the raspberry pi it will boot to a screen like below. First I suggest that you expand the filesystem to use the whole SD card. So just choose option 1.  If you mean to change the password you can use; option 2. For my picture frame I am using a command line based viewer so I am going to make it boot to the command line instead of a nice GUI environment.  Make sure you check your keyboard layout. It is under option 4 internationalion option. That's all that is needed for the initial setup. The default username is "pi" and the password is "raspberry"

 Step 3 Wifi

Since the whole point of this project is to have pictures updated without having to do anything to the frame wifi is a must. I happened to have a trendnet wifi adapter just lying around, if you are buying a new adapter the internet suggests that you get one of the ones that are known to work. I guess I got lucky that mine worked without much hassle. Getting the wireless to connect can be a pain and took me about an hour of changing this and that and rebooting alot. anything between {{}} double curly parentheses is what should be typed in. The first thin I did was to check to see that the raspberry pi saw the wifi adapter. To do that {{ifconfig}} will tell you all of your network interfaces. You should see 3 main groups. eth0, lo, and wlan0. If you do not see wlan0, your pi does not recognize your wifi card. Now if you google how to do this you will find a whole bunch of ways to do. Which is the best, I couldnt really tell you but this is what worked for me. Now that we know your card is being detected we need to look at the config file. to do that {{sudo nano /etc/network/interfaces}} for those of you who are new to linux the sudo command gives the current user administrator capabilites. nano on the other hand is a command line based text editor. Below is what your file should look like. I had to add a few things, you may not. (Edit 8/18/2014 Just looked up setup again because I am having network issues and there file was different so your setup may vary pending wireless card)
auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
once you have your file looking the same it is time to exit. at the bottom of the screen you can see an information area. it says {{^X}} is exit so hold control and hit x. Not at the bottom of the screen it is asking if you want to save the changes. Hit the {{y}} key for yes. Then it asks for a file name. Since we dont want to change it just hit Enter. Now you can see the command prompt back at the bottom of the screen again. we have one more file to modify and you should have wifi.

In the last file we modified we referenced /etc/wpa_supplicant/wpa_supplicant.conf so that is the file we are going to change. To do that type {{sudo nano /etc/wpa_supplicant/wpa_supplicant.conf}} When I came into this file it had only the top 2 lines, so I had to add the rest. For your ssid and psk make sure that you leave the quotes("). When I was googling around some did not have the quotes and some did. Also this is extremely important. Make sure you capitalization is correct. This includes your ssid. This is why it took me so long to get the wifi connected. the # is a note for people reading the file, you do not have to type those lines but it may come in useful down the line.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev 

# Protocol type can be: RSN (for WP2) and WPA (for WPA1) 

# Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or Enterprise)

 # Pairwise can be CCMP or TKIP (for WPA2 or WPA1)

#Authorization option should be OPEN for both WPA1/WPA2 (in less commonly used are SHARED and LEAP) 

Now to save we need to {{^x}} to exit, then y to save then enter to save as the same file name.  
Now all we have to do is reboot {{sudo reboot}}. Yes you have to use sudo to reboot. If you don't believe me go ahead and try it without it. If you typed everything correctly when it is rebooted you should now be connected to wifi. To test this log back on , the type {{ifconfig}} again to bring up or network interfaces. The line under wlan0 you should see inet addr:xxx.xxx.xxx.xxx .That is your ip address. If you don't you probably miss typed something along the line, just got back and check everything for errors, if you don't find any, Google is your friend. The post that I mostly followed to do this is at http://www.howtogeek.com/167425/how-to-setup-wi-fi-on-your-raspberry-pi-via-the-command-line/

Step 4 SSH

At this point you can now unplug the keyboard if you want and ssh into your project. To do that you need an ssh program. On my computer I use Putty and from my phone I use JuiceSSH. Any program with ssh capability will work though. For the settings for ssh you should use the ip address that we just saw (warning this can change since we have dhcp enabled. some routers will consistently give the same ip address to each device, some will change them. You should be able to log onto your router to find out the ip address if it has changed) the default port number of 22 is what we need and then you just need the username and password that you have been logging onto the pi with.Warning when using putty to place copied text into the terminal all you have to do is right click. control v doesn't do anything

Step 5 Google Drive

Now I highly suggest ussing ssh to send commands to the pi at this point. The reason being is you can copy and past things to the pi instead of having to hand type everything. Could we have done this when setting up the wifi, yes you could have but then you would have had to have it hardwired into the router which some of you may have done when installing raspbian. For those of you willing to spend $15 I would suggest insync. I have no relation to them  but what they have worked flawlessly for me when I was using it. You can try it for 15 days before you buy but it is definetly the easiest way I have found for sync google drive. Now I am in no rush to get this project done and didnt find out until today that insync was only a trial so I am back to trying to get grive to work. When I find a way that works I will be back.

Whats Left to do

Install fbi. This is really easy
Setup tasks in cron to keep everything up to date
Redo my weather information. Plan on having the 5 day weather for 2 locations
Setup IO pins
Sure I am missing something but that's it for now

Saturday, May 3, 2014

Raspberry Pi Picture Frame Post 4 Mounting Components

Well I finally got back to working on this project. It has been to long but thats what happens when you have so many projects going on. I finally got everything mounted to the back of the monitor and the wiring finished, I have not had time to completely check the wiring due to the fact that I changed what IO I used so my config files were not setup properly. The next step is to make a new sd card that only has the required software on it instead of the having all of the extra programs that I installed when I first tried to get this working. After I know the everything is working properly it will be time to make the frame and finish up the project. So close to being done but yet so much more to go. Below you can see the final wiring and placement for everything. I may end up having a flash drive for picture storage that way I can have more space than just the sd card, but currently I need that usb slot for a mouse and keyboard.

Friday, May 2, 2014

Quad Copter Revision 2 Post 3

Well After getting the helicopter built the project got turned over to student in my class. They were designing and building quad copters. The students designed one and the components for it we could not get because they were back order or we were unable to buy things from certain websites. So I gave them the task of shortening the wires, getting everything all hooked up and making it fly. After a while the students were finally ready to fly. When the first spun the props up the little tabs i had holding the arm in the open position were not big enough, so the students replaced them with longer screws. The next time we spun the props up the arms were not strong enough and the one motor just ripped itself completely off the arm. In the hope of saving weight I had the walls on the arm set pretty thin as well as did not have much of a fill. I now have a lot of redesigning to do to strengthen the arms up so I can get the helicopter to fly