Pages

Friday, October 18, 2013

The Pumpkin Project: Part Two

Today we have the build pictures and code. There will be a final post covering the final set up on Halloween so keep an eye out for that. It will include video of the final setup.

The Hardware:
1 - PIR sensor -  http://www.adafruit.com/products/189
1 - 15ft phone wire -from Wal-mart
6 - LED flicker candles - from Target
5 - red flicker LEDs -
http://shop.evilmadscientist.com/productsmenu/partsmenu/576
10 - 220Ω resistors - from that compartment in my tool box
6 - Some random proto boards - https://www.sparkfun.com/products/8885 and https://www.sparkfun.com/products/8847
1 - Arduino Uno
1 - Raspberry Pi
1 - Powered Speakers - had some laying around
1 - Wireless card - had 3 laying around

The Build:
The first step was taking apart some cheap flicker led candles and clearing out space inside. After the led is removed the post holding the led can be removed from inside and the plastic guide for the power switch can be removed too. You will also want to remove the contacts from the battery housing and look free CR2032s. The last prep step is to drill a hole for the second led and the wire.




















The PIR sensor is just a standard pir from adafruit. I connected the jst cables to some phone line and run that back to the arduino. To get it mounted I cut a pass through for the connector where I wanted the sensor and used toothpicks through the mounting holes to hold it in place.

Now for the assembly. Each candle will need one yellow and one red flicker led and some 220Ω resistors. The diagram will look something like what is seen in the diagram. You have a resistor to vcc a resistor to ground the diodes connected in series and the pin connection for the arduino between the LEDs. The way this circuit works is when the pin is high no voltage can pass through the yellow diode since the diode is being reverse biased. When the pin goes low the red diode will be reverse biased.


For this project I decided to use phone line since it would keep my wires nicely bound and give me the 3 leads I needed. To keep things clean I just cut back the fourth wire. For the arduino side I built a harness for the lights. The main board has a ground and 5v bus and connector pins for providing ground and 5v to the harness as well as a pin for the PIR sensor input.




The Code:
On the arduino side we have code that will pass a value over serial when the pir sensor is triggered. The value is random and will tell the pi what dialog chain to run through. It will also wait for a clear signal from the pi before starting a new chain. During a chain the uno will parse a 5 character string to determine which pumpkins should be talking. The code can be seen below and on github at: https://github.com/igetio/PumpkinsV1/blob/master/arduino/PumpkinV1/PumpkinV1.ino


For the pi the code will play a dialog chain based on what the arduino says. When it strarts a chain it will tell the uno what pumpkin to light and will play an audio file. When the audio is done it will tell the uno to light the next pumpkin in the chain. When the chain is complete it will then wait 20 seconds before sending an all clear to the arduino starting the process over. The code can be seen below and is on github at: https://github.com/igetio/PumpkinsV1/blob/master/python/talkingPumpkinsV1.py


I have also included the audio files for the project on the github repository. If you have questions about the audio files they are pitch tempo and level shifted to some degree or another. https://github.com/igetio/PumpkinsV1

Thursday, October 10, 2013

The Pumpkin Project: Part One

So, it has been some time since I posted. I have a big update coming. I have finally started work on my talking pumpkin project. Soon I am expect to receive the last few pieces and that will let me start the final build.

Overview:
The pumpkin project is something I dreamed up this time last year having seen the thousand's of other pumpkin projects I thought why not build my own. What I have is a PIR sensor (more on that choice later) an uno and a pi. When the PIR gets tripped the uno sends a signal to the pi and a playback of a script is started. When the playback is over the pi tells the uno to start watching the PIR again. Yep, that's right, it's another talkingnpumpkin project.

The How:
So I ended up using a pi for audio and for managing the playback of the conversations. One of the "exciting" pieces of this project was getting the pi and uno to talk via serial over USB. Getting them talking was simple enough. Realizing that python does not like serial readline to end in \r\n meant some work and time spent wondering why my if statements didn't work. On the other side of things was the uno which can output serial as ASCII but only reads in one char at a time and compares it natively as hex code. After getting the two devices actually talking and handing control to each other things went much faster.

On to the sensor, the reason I used a PIR sensor, aside from them being cheap and me having one on hand, was the space where I am setting up this year is inside a screened in porch and people will be coming up a bent staircase to get to the door. When testing the PIR and an ultrasonic sensor the ultrasonic sensor was not getting good readings through the screen and its field of vision was too narrow.

The Build Plan:
It always comes down to time and money. I was hoping to do some work with wireless but have not had the money to get that up and running. My original plan was for 3 pumpkins but we actually ended up with 5. The plan for this year is to use phone line to wire up each pumpkin. In the interest of keeping the build simple this year I went with 2 different color flicker LEDs one for idle (yellow) and one for speaking (red). In a coming post the build instructions and code. Note: that this time I choose not to have the LEDs flicker in sync with the sound this is to minimize the number of pins used for this solution, knowing that my long term plan is to use a mesh network at which point I can switch to a more advanced logic.

What's Next:
Next steps are to build this thing and get the scripts (audio) recorded. After that I will put up more detailed instructions on what I did and some video of it running. For now I have some pictures of the pumpkins.