Overview

It knows if you have been Naughty or Nice!

The Naughty or Nice machine is simply a bit of fun for the holidays. The machine works by taking a photo of the hand placed on the bottom plate. Using the openCV python computer vision library to count the number of red colour pixels, and display the result on the LCD screen. A little showmanship is used to entrain people while they are waiting for the results of the test. I created the “Naughty or Nice” machine for Christmas 2013, first of all I thought about hacking our Christmas tree, but everyone hacks their Christmas tree, then I had the idea for a “Naughty or Nice” meter, checked online and found that Ben Heck had beat me too that idea, sometime later I had the idea about making the meter interactive, and the idea for the “Naughty or Nice” machine was born.

The “Naughty or Nice” machine is built around the Raspberry Pi camera module, a Raspberry Pi model A, Adafrut USB/serial LCD screen and an Arduino driving RGB LEDs, Adafruit Neopixels. The project is cased in a frame made with Makerbeam and laser cut Perspex panels.

 

Make It!

Warning: This build involves soldering and high voltages

If you're new to soldering have a look at this guide

https://learn.adafruit.com/adafruit-guide-excellent-soldering

The cable between the LV panel and it’s transformer plus the EL panel itself has a high potential (high voltage between 60 VAC to 120 VAC) be careful not to damage the cable and panel when installing it, see the Adafruit EL guide for details 

https://learn.adafruit.com/el-wire

Parts

  • Raspberry Pi
  • Raspberry Pi camera module
  • Adafruit USB/serial LCD display
  • 2 x Adafruit Neopixel bars
  • Arduino Uno
  • RGB LED Arduino Shield - by Re-Innovation
  • Adafruit blue EL panel plus power transformer
  • buck converter or hacked car 12V to USB converter
  • 12Vdc PSU  2 amps or more
  • 12V 2.1mm barrel socket
  • 0.1” plug and sockets plus cable or you could use jumpers as required
  • RGB LED strip
  • short USB to micro USB lead
  • stripbroad
  • 2 x 10K resistors surface mount or through the hole
  • 2 x 1K resistors or surface mount or through the hole
  • 2 x push buttons

The Case

I used Makerbeam for the frame and laser cut Perspex panels for the sides. You can use almost anything, from a cardboard box, wooden box or a fake ginger bread house, for your frame. The case should be at least 200mm high with a base large enough to fit a hand in. The Raspberry Pi is mounted on the top panel with the camera looking down and the Arduino is mount under the panel. The EL panel is mounted between the bottom panel and the base.

The LCD screen

Solder together and test the USB/serial LCD kit, following the instructions here

https://learn.adafruit.com/usb-plus-serial-backpack

Neopixel Sticks

Solder the two neopixal bars together, making sure that the power and data connections are same as in the photo. Solder 3 wires, to the 5v, 0v and data in connections, they need to be longer enough to connect to the Arduino.

Hacked Car USB Adaapter

Hack the car USB adapter, by removing the case and plug. Solder cables to the plug connection points, you removed, the centre pin is 12v and the side plates are ground (0v)

The Switches

I used stripbroad and service mount resistors for the switches in this build, you can do the same or use through hole resistors. The copper has to be removed behind the 1K resistor.

Preparing your Raspberry Pi

It is best to use the latest version of Raspbian you can find the latest version on the Raspberry Pi website, follow the instutions there. I personally like the noobs install method. When you have installed Raspbian, when your Raspberry Pi starts for the first time, the config apt starts, select advanced options and enable the i2c option, then enable the camera module, exit and make sure Raspbian is up to date by entering the following at the command line. Your Raspberry PI will need to be connected to the internet to do this and to download the required software and modules.

sudo apt-get update

sudo apt-get upgrade 

Install the picamera python module, if you are using the latest version of Raspbian the picamera module is already installed. For instructions follow this guide on the Raspberry Pi website by following this link.

 http://www.raspberrypi.org/learning/python-picamera-setup/

 install the openCV python module by entering the following at the command line

sudo apt-get install libopencv-dev

sudo apt-get install python-opencv

 download the bootup program plus the control program for the Raspberry Pi to your home folder from git. enter the follow at the command line

wget https://github.com/Corteil/NorN_4/archive/master.zip
unzip master.zip
cd master
cp NN-0-04-4.1.py ~/NN-0-04-4.1.py
cp NN-0-04-4.1.py ~/run.py
cd ~
sudo rm -r NorN_4-master/
rm master.zip

Next we need to modify the rc.local file to start running run.py when the Raspberry Pi starts up. first of all we need to make a backup of the file, enter the following at the command line. 

sudo cp etc/rc.local etc/rc.local.old

if you need to restore the old file enter enter the following at the command line

 sudo cp etc/rc.local.old etc/rc.local 

Now to modify the rc.local file by entering at the command line.

 sudo nano /etc/rc.local

and adding the following before "exit O"

python /home/pi/run.py

and save by holding ctrl O, press enter to accept and then ctrl X to exit

follow the guide on the hobbytronics website to disable the console on the serial port.

http://www.hobbytronics.co.uk/raspberry-pi-serial-port

Preparing your Arduino

Install Arduino and add the Adafruit libraries for the Adafruit_WS2801.h and Adafruit_NeoPixel.h for Arduino. you can find them at https://github.com/adafruit

If you are new to the world of Arduinos, I would suggest that you follow the first few guides by Simon Monk on the learn.adafruit.com starting with the first lession.

https://learn.adafruit.com/category/learn-arduino 

next upload NorN_4.ino sketch to your Arduino using your normal method. You can download sketch from here

https://github.com/Corteil/NorN_4

 install the RGB strip sheild, contect the RGB strips to the sheild and NeoPixel sticks. you will not be able to test until the Arduino and Raspberry Pi are conected together.

NOTE: you could use just a NeoPixel strip instead of the RGB sheild and RGB strip, the Arduino sketch would required adjusting if this was done.

Connect the Arduino SDA and SCL lines to the Raspberry Pi plus connect grounds of both devices together.

Arduino

A4
A5
GND

 

--->
--->
--->

Raspberry Pi

3
5
GND

Putting It All together

Build your case, fixing the Raspberry PI, Arduino, LCD display, Neopixals plus the RGB strip in place.

The EL panel is installed behind the transparent blue base in my case, this is to protect it, take care with the power connections, making sure that the cable and joints are OK.

Connect the connected the RGB LEDs strips following the screen print markings to the shield, and the Neopixels 5V, 0V to the Arduino’s 5V, 0V and the data in is connected digital pin 12. Using the TLL serial connection on the LCD display, connect the JST cable to the backpack and then connect to the Raspberry Pi's GPIO pins as follows: Red wire goes to +5V, Black wire goes to Ground, White data wire goes to pin 6 (TxD) or you can solder a header on and use jump wires instead.

Fit the power socket and connect with wires to the power in on the Arduino shield, and also feed the hacked 12v to USB converter or the buck converter, use the USB lead to power the Raspberry Pi from the usb socket on the USB converter. Connect the feed for the EL transformer to the socket, you may need to use some form of connector blocks to be connect all the required feeds.

Connect the Arduino SDA and SCL lines to the Raspberry Pi plus connect grounds of both devices together.

Arduino

A4
A5
GND

 

--->
--->
--->

Raspberry Pi

3
5
GND

Fit and connect the switches, to the Raspberry Pi GPIO pins  the red wires goes to a 3v3 pin and the black wires to a 0V pin, The first switch's signal wire is connected to pin 23 and the second is connected to pin 24

How To Take a Reading

Instructions for use.

 

  1. When the "Naughty or Nice" machine first starts press the bottom button. 
  2. Place hand on the bottom plate inside the machine, up to your wrist
  3. Press bottom button
  4. Remove hand when instructed
  5. Wait for your Naughtness rating
This guide was first published on Dec 18, 2014. It was last updated on Dec 18, 2014.