Google+ Followers

Sunday, 5 January 2014

Cacheberry pi in detail.

Do you ever wonder if you combine your hobbies? I did till a few months ago i saw a project on twitter, when i asked about it i was pointed to jclements github page https://github.com/jclement/Cacheberry-Pi and there i started to build my own.

 But it wasnt so simple, I was having problems with the LCD and further delving with twitter and google I found a cacher and electronic enthusiast called Steve who had forked the project and is still currently tidying it up on his github page https://github.com/Aurock 

 So next was to create a new image, with the files and after realising that the I2C LCD can use slightly different pins I realised i had to just change the LCDconf file, but luckily Aurock had done this after speaking to him about this project (as well as update some coding). 

 So to build this cacheberry pi I needed the following:
 Raspberry pi model b 512mb but im sure a 256mb model will work.
 I2C 2x16 LCD display
 LED Resistor for LED
 ublox gps module (or you can use the more expensive adafruit one) 
 a car cigarette lighter plug with wires which i attached to a 12v to 5v 3w usb device which then has a mini usb lead to power the pi.
  optional is a 2x13 gpio ribbon connecter. 

 software:
 Python 2.7 GPsd - Available through APT 
  PySpatialite - Available through APT 
 LCDProc - Available through APT (required custom display driver)
 RPi.GPIO AutoFS - Available through APT 

 commands: 
 $ sudo apt-get update 
 $ sudo apt-get upgrade 
 $ sudo apt-get install autofs lcdproc python-pyspatialite sqlite3 gpsd vim-nox gpsd-clients screen python-dev i2c-tools python-smbus git 

 The RPi.GPIO library needs to be installed separately since it's not in APT. 
$ cd /usr/src $ sudo wget http://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.4.1a.tar.gz#md5=9acdb66290350aaa74b99de859ded153 
$ sudo tar -xvf RPi.GPIO-0.4.1a.tar.gz $ cd RPi.GPIO-0.4.1a/ 
$ sudo python setup.py 
install The lcdproc python library:
 $ cd /usr/src 
$ sudo wget http://pypi.python.org/packages/source/l/lcdproc/lcdproc-0.03.tar.gz#md5=177328fd30c973151b5e75f9c1b992c7 
$ sudo tar -xzf lcdproc-0.03.tar.gz 
$ cd lcdproc-0.03/ 
$ sudo python setup.py install 

 Download CacheberryPi Software Clone the CacheberryPi repository to your "pi" user's home folder.
 $ cd ~
 $ git clone https://github.com/jclement/Cacheberry-Pi.git or Aurocks updated version: 
$ git clone https://github.com/Aurock/Cacheberry-Pi.git 

 Configuration 

 Install the ifup script so we can see network configuration on the LCD.

 $ cd ~/Cacheberry-Pi/util
 $ sudo cp ifup-lcdproc /etc/network/if-up.d 
 $ sudo chmod 755 /etc/network/if-up.d/-lcdproc 
 Install lcdproc configuration files and LCD driver. 
  $ cd ~/Cacheberry-Pi/misc 
 $ sudo cp LCDd.conf /etc
 $ sudo cp hd44780-i2c/hd44780.so /usr/lib/lcdproc/
 Setup udev to make GPS devices world write/readable: 
$ cd ~/Cacheberry-Pi/misc 
$ sudo cp 70-persistent-net.rules /etc/udev/rules.d/ 
 Edit 2 files to enable i2c: In /etc/modprobe.d/raspi-blacklist.conf Add a # before the line "blacklist i2c-bcm2708". 
Add the following 2 lines in /etc/modules i2c-dev i2c-bcm2708 
 Edit /etc/rc.local to start CacheberryPi on startup.
 Add the following before "exit 0" nohup /home/pi/Cacheberry-Pi/start & Configure autofs for update functionality.
 $ cd ~/Cacheberry-Pi/misc $ cp auto.removable /etc 
$ cp auto.master /etc Edit /etc/hosts and /etc/hostname and replace "raspberrypi" with "cacheberrypi". 

 The GPS module I used connects directly to the GPIO pins on the Raspberry Pi and communicates via serial. In /etc/inittab scroll to the end of the document, where you should add a # sign before this line:
 T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100 
 Next, edit /boot/cmdline.txt - This file is just one long line of text. 
 Find and remove the following:
 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 
 GPSD must also be reconfigured for the serial port instead of the USB. 
To do this, run:
 sudo dpkg-reconfigure gpsd 
 This will start up a configuration screen where you need to configure the gpsd. Set gpsd to run automatically at startup, then accept the default settings on all the following screens until prompted for the port that the gps unit is connected to. Enter /dev/ttyAMA0 in the port field. 

 The settings within the cacheberrypi folder include timezone, imperial and metric which are easy to set and bingo the software side is set up. If the lcd display isnt showing anything then try this version of the files:
 https://github.com/Aurock/Cacheberry-Pi/tree/AltHardware/misc/hd44780-i2c 
Put LCDd.conf in /etc and the hd44780.so in /usr/lib/lcdproc 

 Next up was to join all the gizmos together, i decided to use a 2x13 connector ribbon so wires couldnt accidently fall off connecting i2c vcc to pin2 (5v) sda pin3 and scl pin 5. 

 Next was the led i soldered a resistor to the leg and then connected positive to pin 22 (gpio25) and the negative to ground pin 6. The gps was connected (as it works on 3v) positve to pin 1 (3.3v), ground to pin 6, tx to pin 10 (marked rx) you dont need to transmit to gps as we only need info from the gps thus gps tx to raspberry recieve.
once soldered I covered the soldered wires with electrical tape to ensure no shorting out.
Next up I made a case, found a small box just big enough for the pi and the innards, go cut a small hole for screen to go through, small hole for power cable, cut out the usb bit so you can update it with a usb stick and placed the gps unit on the roof before taping it together in place with gaffa tape a: to make it stronger and b: to hold everything in place. I then made a small hole for the led to pop through and ended with this.
Next was to fire up the pi and attach the usb stick so the caches canload onto it.
Then i decided after a few crashed sd cards to add a reset button that you press and hold in before you turn it off, this could be done via P6 on the pi board and soldering on a two button lead, using this has so far only led to one crash, but thats like nothing compared to before this add on.
This i then taped to the very top so easily accessable if needed, if i was to do this again i would put the button on the side screwed in. There is also a small hole in the top to let heat escape and with the slightly bigger slit on the right for the usb it should help air circulate and stop the pi from heating up, althrough raspberry pi have said there should be no problem with over heating as it can work fine up to 80c.

Now already to go you will need also to do the following: Edit /etc/hosts and /etc/hostname, replacing "raspberrypi" with "cacheberrypi". Loading Geocaches Use program "Geocaching Swiss Army Knife" (GSAK), export the geocache data to a file in Microsoft Streets & Trips format. 
Save the file on usb stick as "\cacheberrypi\nav.csv". Insert into the usb port on Cacheberry Pi, and watch LCD as the cache data is transferred. 

Export options & Geocache Display When exporting the data from GSAK, the cache description, waypoint name, and URL link format can be modified. Customize the data exported in these fields using GSAK's "Special Tags". When the Cacheberry Pi has found a nearby cache, the left side of the LCD will show the "cache description" on the top line, and the "URL Link" on the bottom. 

I recommend setting the fields as follows when exporting from GSAK: * Waypoint Name = "%code" * URL Link = "%Caches_FavPoints (%Dif/%Ter)" * Cache Description Format = "%Name by %By" Note: While the Cache description and URL Link can be set he Waypoint Name field MUST be %code.

 Now ready to take it out join the cigarette plug to the 12v to 5v3w convertor to which is connected to a usb to mini usb lead which is plugged into the pi, this will give you the correct voltage and power protection and protect it from being fried, i believe the one i use works from 24v so will work fine in a lorry which cigarette lighter socket is 24v. 

 Now the raspberry pi can do the following, Smart Search: depending on speed and direction of travel, Ability to maintain a database of 20k+ geocaches (after 25,000 caches it starts to slow down a bit), Easy syncing of cache lists with GSAK via usb stick, Automatic tracklog recording and syncing with usb stick,but i dont use this option and lastly Easy customization of settings in the 'cacheberrypi.cfg' file. Smart Search: depending on speed and direction of travel Ability to maintain a database of 20k+ geocaches Easy syncing of cache lists with GSAK via thumb drive Automatic tracklog recording and syncing with thumb drive Easy customization of settings in the 'cacheberrypi.cfg' file for things like imperial/metric settings, timezone, language etc.
When there isnt any caches nearby it will just show date, time, speed and distance of travel e.g. n, nne, sw, etc and when a cache turns up in the search will show you your speed and direction along with cache name d/t and distance to cache along with its bearing compared to you, i would like to change this to an arrow system soon, but for now im concentrating on playing with the cache finding programming to see if i can make it better.

 Future plans: add buzzer to beep countdown to cache, fit a four line lcd to display more info add arrow to display a button to ignore a cache or to find something else. finding away to show hint along bottom and make it scroll to without going over the top of distance, speed and direction.

 Thank you also for Mr Clement who originally wrote the program, Mr Whitcher for his forking of the project and tidying it up as well as for the countless emails back and forth about the display and other future ideas.