Jan’s Raspberry Pi Advice Machine

Update: Click here for a newer Version, implemented with Arduino.

A few months ago I stumbled  upon Nick’s Blog. He built an Advice Machine based on the credit card sized micro computer „Raspberry Pi“ and some additional hardware. I was totally impressed about his work and driven to build a similar machine on my own. Unfortunatly I never found detailed information like code snippets or wiring pof his work. He just published that he was using the coin acceptor CH-926, the LCD 16×2 character Display and a Sparkfun thermal Printer. I ordered all that parts but left them lying over a year due to not having the time and motivation to get myself into that new matter (I had only a little knowledge about electronics and never worked before with Raspberry’s GPIO interfaces). Then came a day when I helped as a volunteer at my old scout association at the local christmas market. The scouts were selling „Glühwein“ and „Bratwurst“ to get some extra money for their next summer camp. Because it’s more fun to drop money into the cash box instead of giving it out I was trying to find a way to keep people’s glass deposit of 2 Euros in our hands. Just asking for a donation was embarrassing and unimaginative. This was when I remembered the machine as a way to give our customers a little gift for their donation and to put a little smile on their faces.


Here is the partslist of my machine

  • Raspberry Pi Model B 512 MB
  • LM2596 Step-Down Switching Regulator
  • Coin counter CH-926
  • Adafruit 2×16 LCD character display
  • Sparkfun Thermal Printer
  • Raspberry Pi expansion board v2.2
  • Breadboard
  • A couple of jumper wires
  • 1 Resistor (1k Ohm)
  • LED Push Button (6 V)
  • DC 5V power supply with 3A
  • DC Power Jack
  • (Optional: Active Buzzer)

I bought all the parts on Ebay or Amazon. As a case I used a wooden box from a local furnishing store. And here it is in action:

IMAG1017

Wiring


Here is a wiring map of my advice machine.

Advice_Machine

I split the power supply in two circuits – one for the 9V powered parts (Coin counter and thermal printer) and one with 5 Volts for the breadboard which powers the button, the LCD display and even the Raspberry Pi via its GPIO pins. The LM2596 is really easy to use. You connect it to the 9V power source on its input side and take a tension tester on the output side. Now you simply rotate the embedded potentiometer with a screw driver until there are 5V on the output. Thats how it looks inside

IMAG1083 IMAG1082 IMAG1084 IMAG1085

Next step is to „train“ the coin counter. The model CH-926 can identify up to 6 different coins. A tutorial can be found here: Multi coin CH 926 – Sampling My setup sends 1 impulse for 10ct, 2 for 20ct, 5 for 50ct, 10 for 1 Euro, 20 for 2 Euro. All other coins are rejected.


Source Code


Update: Click here for better Arduino version of my advise machine.

The software is written in Python. It was my first experience with that programming language so please forgive me for its lack of elegance. There are excellent code examples for the printer and the LCD provided by adafruit on github. I used the following files for my project:

Here is my additional code. Download the full package here.

Set up Raspberry Pi


I am using a Raspbian Linux. There is not much work to do. Install python image library For image processing I need an additional python library. It can be installed with the following command:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-imaging python-imaging-tk

Setup to start when Raspberry boots I recommend to run the python script in a screen-terminal. Read more about screen.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install screen

Copy the following lines into a new file in /etc/init.d/ named advice.sh

#! /bin/sh
### BEGIN INIT INFO
# Provides: <advice-machine>
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts advice machine
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin

. /lib/init/vars.sh
. /lib/lsb/init-functions
# If you need to source some other scripts, do it here

case "$1" in
 start)
 sudo screen python /usr/share/adafruit/webide/repositories/my-pi-projects/advise_machine/advise_machine.py
 log_begin_msg "Starting my super cool service"
# do something
 log_end_msg $?
 exit 0
 ;;
 stop)
 log_begin_msg "Stopping the coolest service ever unfortunately"

 # do something to kill the service or cleanup or nothing

 log_end_msg $?
 exit 0
 ;;
 *)
 echo "Usage: /etc/init.d/<your script> {start|stop}"
 exit 1
 ;;
esac

Execute the following command:

sudo chmod 755 /etc/init.d/advice.sh
sudo update-rc.d advice.sh defaults

The script should now be started on machine boot.