Monday, December 5, 2011

"Echo Box" using PICAXE 08M (Complete)

What is an "Echo Box" you ask? Simple. You tap on the box and a few seconds later the box echos those taps back to you. The video below shows the rigs operation. Keep reading if you want the build details.
-----

-----
I have programmed a PICAXE 08M microcontroller to monitor for current on a piezo disk. The piezo disk outputs a current when it is struck (or tapped). The PICAXE sample and holds the cadence of the taps with software. If there are no taps for about a second or so the program assumes the tapping is complete and echos the taps back to you on the box.

The piezo sits inside a tube of PVC pipe between two pieces of wine cork that are cut to barely touch the roof of the box. This does a great job of transferring the taps from the top of the box to the piezo input. Here is a picture of the piezo disk resting on top of a wine cork.

-----
And here is the piezo input disk in its final configuration with another piece of wine cork placed on top of it. Basically creating a "piezo sandwich" with wine cork.
-----
Below is how the input from the piezo traces out on the 'scope. A diode in parallel with the piezo protects the PICAXE from getting hit with a negative voltage spike. A 1M resistor also helps to tame the input and make it more predictable.
-----
A DC motor with an offset counter weight spins to shake the box and provide the feedback for the echo.
-----
The circuit perf board is shown below. The red LED is simply there to provide a visual clue that the piezo tap was processed by the PICAXE. It is used only for debug of the project and could be removed. You can also see two 470uF capacitors on the board. Take note that the motor will not get enough instantaneous energy to start without these capacitors. One final note, a transistor as heavy as the 2N6284 is not required, but I had one handy. The more common 2N2222 should be fine.
-----
The rig is powered with 5VDC provided by a rescued Blackberry charger. The headphone jack is not for audio; this jack is used to download the control program into the PICAXE 08M. This jack allows you to easily change the personality of the Echo Box.
-----
The completed Echo Box:
---
-----
Here are two videos of the rig working on the bench.




-----
For those that have hung in there so far with the details, the circuit schematic and code is shown below:
-----
; *******************************
; ***** www.whiskeytangohotel.com *****
; *******************************
; Project Name: Echo Echo
; [with thanks to AndyGadget & the PICAXE Forum]
;
; Start Date: November 15, 2011
; Completed: December 4, 2011
;
; *******************************

#picaxe 08m2
#com 11


' Assign names to pins, variables to registers,and constants.

symbol rnd = w6 'Word variable : Current random number
symbol kdel = w5 'Word variable : Delay between last and current knock input

symbol cnt1 = b0
symbol kcnt = b1 'Number of knocks
symbol pptr = b2 'Pointer to knock delay storage array

symbol tmp1 = b6 'Reusable variable
symbol tmp2 = b7 'Reusable variable

symbol mic = pin2 'Microphone input (can also be output)
symbol knock = 4 'Knock motor output
symbol led = 0 'Indicator LED for testing

symbol pstart = $50 'Start of storage area
symbol tmax = 800 'Time-out value for delay - About 1.5 seconds
symbol settle = 80 'Settling time for microphone


'This section is where the person knocks.
'The time between successive knocks is stored
' until there is a pause of 1.5 seconds or so.

do 'Start of main loop
kcnt = 0 'Initialise knock counter
input 2 'Define mic as input to detect knocks
do
for kdel = 1 to tmax 'KDel is counting loops to determine time between knocks
if mic = 1 then 'Detect HI on microphone input
inc kcnt 'Add 1 to number of knocks
high led 'Flash LED to help debugging
pause settle 'Wait for oscillations to stop
low led
kdel = kdel + settle 'Add settle time to loop counter for accuracy
pptr = kcnt * 2 + pstart'KCnnt is a word variable so need to add 2 to pointer
poke pptr,word kdel 'Write the delay from last knock to storage area
kdel = 0 'Reset kdel ready for next knock
end if
next kdel
loop until kdel >= tmax 'If no knocks for over TMax loops then leave loop
'This section will operate sepending on the number of knocks detected.
'If there are no knocks it will exit.
'The maximum number of knocks is 23 to fill buffer. Incorrect count after that.
select case kcnt

case 0 'Do nothing if no knocks have occurred
case 21 'Put Box in 'Irritate Mode'.
gosub twoknock 'gosub twoknow to confirm routine was entered.
wait 10 'Do nothing for xx seconds
gosub twoknock
wait 9
gosub twoknock
wait 8
gosub twoknock
wait 7
gosub twoknock
wait 6
gosub twoknock
wait 5
gosub twoknock
wait 4
gosub twoknock
wait 3
gosub twoknock
wait 2
gosub twoknock
wait 1
gosub twoknock

else 'Any other number of knocks will be echoed

for tmp1 = 1 to kcnt 'Loop for the number of knocks
pptr = tmp1 * 2 + pstart 'Step in twos through buffer
peek pptr,word kdel 'Read back delay value words from buffer
pause kdel 'Wait the delay time (in milli-seconds)
gosub DoKnock 'Perform a knock
next tmp1 'Loop for next knock
pause 200
endselect
loop


'This section contains the knocking routines

DoKnock:
high knock 'Turn on motor
pause 70 'Wait 70 milli-seconds
low knock 'Turn off motor
return

TwoKnock: 'More compact to do this as subroutine
pause 550 'Two knocks with timed delays between for tune
gosub doknock
pause 700
gosub doknock
pause 700
return
-----

Friday, November 11, 2011

PICAXE / MQ2 Gas Sensor Project in a Mouse

The project detects flammable gases (LPG, butane, propane, methane, methane, methane, methane, methane, alcohol, hydrogen, and methane.) via the MQ2 Gas Sensor. When a flammable gas is detected the frequency of the speaker beep increases. The whole enchilada is controlled by a PICAXE 08M uController and some custom code.
---
Here is a video of the system operating. Keep reading if you want the details.
---
The rig gets its power from a 5VDC USB port (Windows and Mac compatible ;) or a car USB charger). The MQ2 Gas Sensor is protected by a metal screen which can be seen in this photo of the finished product.

---
Here is a shot of the circuit board powered up. In the final version we had to cut off the excess PCB material to make all the gear fit into the mouse. Note the "headphone input jack" near the top. That is actually a programming port allowing us to easily reprogram the PICAXE if we want to change the rigs personality. Such as, make the speaker beep faster, louder, flash lights, etc. Also, you can see that the PICAXE is not plugged into the socket yet. We wanted to check for solder shorts and smoke first to avoid damage to the PICAXE.
---
Is all this stuff going to fit into the gutted mouse?
---
Of course, if you watched the video above, you know it all fit (just barely). The build schematic:
---
Here is a video of the rig working on the bench.  The current thinking at this time was to use a servo motor to move a needle over a calibrated meter.  In the final design the beeping speaker was used to reduce the size.
---
The source code for the PICAXE 08M is straightforward:
;
#picaxe08m
#com 11

main:
readadc C.2,b0 ; read the MQ2
sound B.1,(119,5) ; make a sound
w1 = 255 - b0
w1 = w1 * 5
pause w1 ; decrease pause between beeps if gas detected
goto main ; loop back to start
-----

Thursday, September 29, 2011

555 Timer Driven KiteCam

The objective was to put a camera on a kite and have it take a picture every 15 seconds on so.

We started with a Vistaquest VQ1005. It's a very cheap, small, light, 1.3 megapixel camera that is easy to take apart and hack. It also has a SD card expansion slot and can function as a webcam. BTW, you can see our LauchPad MSP430 uC hack of this same model camera here.
-------------------
Time to void the warranty. The Vistaquest VQ1005 comes apart easily with four small screws. We found a node on the circuit board that triggered the camera to take a picture when connect to the "-" lead of the battery; GROUND. We soldered a "trigger wire" from a 555 Timer to this node.
----------------------
We then needed a way to connect the trigger wire to GROUND automatically. We used a 555 timer chip to provide this function. A low power CMOS 555 can be purchased for about one dollar. If the Vistaquest VQ1005 does not take a picture in 60 seconds it will shut off, so we designed a RC network for the 555 timer that would trigger a picture about every 20 seconds. The circuit looked like this:
---------------
Then we breadboarded a prototype.
-------------------------
After cleaning up the prototype, the rig was cleaner, smaller, lighter.
----------------------
Here is the finished rig protected and ready for some kite crashing.
-------------------------
Here are a few vids taken with the setup:

Wednesday, September 28, 2011

AntCam Project


------------------------------------------------------
Objective:
Document the several week long tunnel building process of the ants with a time lapsed video.

Status/Notes:
July 29, 2008: Just press "play" in on the pic above to watch the video. Have your sound on. 119 hours and 29 minutes are compressed down to less than 100 seconds. No ants were harmed in the making of this video.

July 28, 2008: The ants have bored about as many holes as possible. Only a few ants have died.

July 23, 2008: 39 harvester ants are placed into the AntWorks to toil away.

July 18, 2008: The ants arrived today, but they were all dead :(. We're working on getting fresh ones.

July 11, 2008: Antworks arrives. Ants on order.

July 03, 2008: Antworks ordered.

July 01, 2008: Setup testing begins.

Setup:
The setup is simple. We have an old slow HP desktop running Windows XP. For a camera we have a standard $20 LogicTech wecam. We are running a fantastic free open source program called Dorgem that FTPs the images to our web host and saves the images to our hard drive. Very simple and very low cost.
-----

Sunday, August 28, 2011

PICAXE 18M2 Robotic Hand [Complete]

Using a PICAXE 18M2 uC, five servos, a few resistors and some random 'stuff' around the house, we built this robotic hand. Then we wrote some software to control the hand. Hardware wise, an input line on the PICAXE is held HIGH via a 10K ohm pull up resistor. This input line is pulled LOW upon pressing the red Normally Open button. While the PIXACE waits for a button press it happily generates random numbers that are associated with gestures the hand has been programed to perform. At the press of the red button the PIXACE uses that random number to call a gesture routine.

Here is a pic of the front of the hand. The toggle switch turns the rig on and off. You can also see the red button mentioned above. Note there are three servos mounted on the front side of a piece of plexiglass; two on the backside.
-----
This pic of the backside of the hand shows the two other servos. Wiring to the PICAXE is straightforward, but there are a lot of wires due to all the servos. Note the audio jack. That is actually a programming jack that allows you to download different software routines into the PICAXE and change the robot's personality.
-----
You may have notice a soft blue glow under the platform that holds the robot hand. We rescued a blue LED from something we had around the house. When the rig is powered on (5.25VDC) this blue LED glows.

-----
The video below shows the rig in action on a few gestures. Like I said before, these come up randomly. Here is what we got:
-----
The awesome site HackaDay.Com featured the hand before we were complete.
-----
I'll send the source code to anyone that is interested in seeing it.
-----

Saturday, August 20, 2011

Robot Hand Mimics Real Life Hand


PC webcam image monitored by program written in RobotSee. The image is processed and the appropriate subroutine is called upon recognition. The RobotSee program then outputs to the ColdFire uC to control five servos on a toy robotic hand to mimic the webcam image.
-----

Wednesday, August 17, 2011

VistaQuest VQ1005 Controlled by TI MSP430 LaunchPad

We show you how.


There are a lot of things about the TI MSP430 that I like. First of all, the price from TI is crazy cheap at $4.30!!! Hats off to TI for making their development kit so inexpensive that anyone who even wants to casually experiment with micro-controllers can do so. Even though it only cost $4.30, the MSP430 LaunchPad is a very capable micro-controller and the free SDK (Code Composer Studio) used to program the MSP430 is nice as well.

Long ago I broke open a VistaQuest VQ1005 and used a 555 timer to snap pics automatically. I wanted to replace the 555 timer with the TI MSP430 LaunchPad because 1) it would allow more programmable control over the delay between pics and 2) the additional I/O on the MSP430 would allow me to get around the VistaQuest VQ1005 wanting to go to sleep after 60 seconds on inactivity.

The integration of the VistaQuest VQ1005 to the MSP430 LaunchPad is one that is cheap and easy given some guidance. If you are looking for a uC project to get your feet wet, this hack is sure to work and will cost less than twenty bucks if you watch for deals on the VistaQuest VQ1005. By now almost every household has an old digital camera around, so it's easy to substitute an old 'free' camera for the VistaQuest VQ1005 if you want. The integration concept to the MSP430 LaunchPad is the same.

First, get a TI MSP430 LaunchPad from here and a VisaQuest VQ1005.

They will look like this:
----

If you don't know which is the MSP430 LaunchPad and which is the camera then you can stop reading now...

The first thing I did was solder header pins to the Vcc, GND, P1.5, and P1.7 "holes" on the MSP430 LauchPad. We are going to be connecting wires from the camera to those places. If you want, you can just solder the wires from the camera straight into the holes, but the header pins will allow you to unplug the camera from the MSP430 LaunchPad if you ever so desire.

Next open up the VistaQuest VQ1005. This is easy. You will remove four small screws on the outside case. Once inside you will see two PCB boards. The trigger board (the board that presses the button to take the pic) looks like this:


See the red circle labeled "T"? Solder a thin wire to that location. This is the trigger wire that will ultimately be connected to P1.5 on the MSP430 LaunchPad. We are going to use the MSP430 to bring this wire LOW (zero volts) to take a pic. Don't worry, the code to do this and more pics are below to help you with this.

Now we want to remove the VistaQuest VQ1005 "ON/OFF" control PCB. This is the same PCB that holds the camera lens and is attached with two small screws. Remove the screws and remove the PCB. See the red circle labeled "O" in the pic below? This is the "ON/OFF" control point. Solder a wire to that point. This wire will ultimately connect to P1.7 on the MSP430 LaunchPad. We are going to use the MSP430 to bring this wire LOW (zero volts) to make sure the camera is ON and ready to take a pic. Again; don't worry, the code to do this and more pics are below to help you with this.


Put the VistaQuest VQ1005 camera back together. It's as simple to put together as it was to take apart. Be careful not to pull off the wires you just soldered to the two PCBs. Depending on how you route your wires you may have to make a notch or two in the camera case.

We are almost done. See the pics below to guide you through how to connect up the VistaQuest VQ1005 to the MSP430. As you can see, I powered the whole operation with two AA batteries (3VDC). The one nice thing about the LaunchPad is that it has a USB port input that you could use to provide the power for the project. Basically, you would remove the two AAs and use your USB port to power the rig.

The pic below shows the (T)rigger wire from the VistaQuest VQ1005 attached to the MP430 LaunchPad P1.5 output pin. Also, the +3VDC power from the two AAs connected to the Vcc header pin we soldered to the MSP430 LaunchPad.
---
Below is a shot of the (O)n/(O)ff control wire from the VistaQuest VQ1005 attached to the MSP430 LaunchPad P1.7 output pin. You can also see the black wire that goes to the NEG terminal of the 3VDC AAs. Note that at the bottom right I have used the Vcc and GND header pins that were already on the MSP430 LaunchPad to power the VistaQuest VQ1005 camera. These wires simple go to the "+" and "-" place on the VistaQuest VQ1005 where the battery would connect. BTW, I know the VistaQuest VQ1005 uses one 1.5VDC battery to power it and we are pushing 3VDC into it. Don't worry about that, the VistaQuest VQ1005 has the smarts to handle this.

---
Below is a pic of the two AAs that provide the 3VDC power. The battery pack is held onto the MSP430 LanchPad with Velcro.

---
In the end it should all look something like this:
---
We tested on location where our cats relax in the sun. We used the 1000+ images that the rig took and made this short video:

---
Let us know if you give this a try and what your results are. Good luck, have fun. Please reference www.WhiskeyTangoHotel.Com if you found this useful.

Oh, one more thing... The code below makes it all happen.

The code flashes the red LaunchPad LED during camera power up.
The code flashes the green LaunchPad LED when a pic is taken.
The code alternates flashing the green and red LED as it waits to take the next pic. The LEDs alternate more rapidly as the VistaQuest VQ1005 gets closer to taking the next pic.

Modify it if you want.

////////begin MSP430 Code//////////

// This program interfaces the MSP430 Laucnpad uC dev board
// to a VistaQuest VQ1005 Digital Keychain Camera.
// This allows to camera to take picutes at pre-defined intervals
// automatically without any manual interaction.

// Cost: MSP430 Launchpad: $4.30 from Texas Instruments
// VistaQuest VQ1005: $5-10 from Walmart, eBay, etc

// Developed at: www.whiskeytangohotel.com / August 2011 / Open Source, use and modify

#include msp430g2231.h

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= BIT0; // Set Red LED (P1.0) to output direction
P1DIR |= BIT6; // Set Green LED (P1.6) to output direction
P1DIR |= BIT5; // Set Camera Trigger (P1.5) to output direction (Low is Take pic)
P1DIR |= BIT7; // Set Camera ON/OFF control (P1.7) to output direction (active LOW)

volatile long i; // General loop var
volatile long j; // General loop var

volatile long d; // d is delay between pics
d = 15000; // set the value of d per guidelines below
//d = 10000; about 15 secs between pics
//d = 15000; about 35 secs between pics
//d = 20000; about 60 secs between pics
//d = 40000; abput 4.5 mins between pic
//increase d for longer delay between pics

P1OUT |= BIT5; //need to start with tigger high (because LOW triggers camera

for (;;) // Start of Endless Loop
{

P1OUT &= ~(BIT0 + BIT6); // both LEDs off

P1OUT &= ~BIT7; // Force low to turn on camera
for (i=0; i<5 data-blogger-escaped-br="br" data-blogger-escaped-i="i"> { // Delay some while camera 'boots'
P1OUT ^= BIT0; // Flash/Toogle Red LED while 'booting'
for (j=0; j<2000 data-blogger-escaped-br="br" data-blogger-escaped-j="j"> } //

P1OUT |= BIT7; // Return camera control to High
for (i=0; i<5 data-blogger-escaped-br="br" data-blogger-escaped-i="i"> { // Delay some just 'because'....
P1OUT ^= BIT0; // Flash/Toogle Red LED while delaying
for (j=0; j<2000 data-blogger-escaped-br="br" data-blogger-escaped-j="j"> } //


P1OUT &= ~(BIT0 + BIT6); // both LEDs off

// Blink the Green LED to show a pic is being taken
// and allow some delay for disk write, etc.
P1OUT &= ~BIT5; // Drive Trigger signal low to take pic
for (i=0; i<100 data-blogger-escaped-br="br" data-blogger-escaped-card="card" data-blogger-escaped-delay="delay" data-blogger-escaped-etc.="etc." data-blogger-escaped-i="i" data-blogger-escaped-pic="pic" data-blogger-escaped-process="process" data-blogger-escaped-save="save" data-blogger-escaped-sd="sd" data-blogger-escaped-some="some" data-blogger-escaped-to="to"> {
P1OUT ^= BIT6; // Blink the Green LED
for (j=0; j<2000 data-blogger-escaped-br="br" data-blogger-escaped-j="j"> } // end Green Blink/delay for pic
P1OUT |= BIT5; // return tigger to high (because LOW triggers camera)

P1OUT &= ~BIT0; // Turn off Red LED and
P1OUT |= BIT6; // Green LED ON to set up for alternating Red/Green flash rountine below
// The loop below alternates the LaunchPad Green/Red LEDs; speeding up until pic is taken
// Time between pics is define by the value of "d" set above

for (j=1; j {
P1OUT ^= BIT0 + BIT6; // Toggle LEDs
for (i = 1; i<(d-j); i++); // A decreasing delay to make LEDs alternate faster until trigger
} //end loop that alternates the LaunchPad Green/Red LEDs


} // end of endless loop
} //main

-----

Tuesday, August 16, 2011

Earth Core Hexapod Robot


-----

CatScan Robot Hi-Tech Cat Toy w/PICAXE28 uC


-----

MSP430 uC to Toy Tank


---
The goal was to learn how to program and interface the MSP430 microcontroller with a toy tank and make it drive autonomously in a square after a button is pressed. The project demonstrates simple control of two DC motors (output) and the ability to process a button press (input) with the MSP430. There was no goal to create a pretty robot and I guess I got that done as well. ;)

The material list:
$12.00 toy tank,
$4.30 TI MSP430 LaunchPad,
$2.50 SN754410NE Quad Half H-Bridge

The program is written in C and uploaded into the MSP430 via the Code Composer Studio 4.1 software.

Get your own MSP430 LaunchPad micro controller here for only $4.30.

A few early build pics:
Original Tank (with AirSoft cannon)
---
Here it is five minutes later...
---
The remote control was removed from the tank. The motor wires were hooked straight into the motor driver chip that was controlled by the MSP430 LaunchPad.
---
Below is the source code for the project:
=================
//MSP430 rogram to make tank drive in a square after button push. June 11, 2011
//After the square is complete the tanks waits for a button push to repeat process.
#include msp430g2231.h

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction
P1DIR |= 0x40; // Set P1.6 to output direction

volatile long i;
volatile int j;

// RED LED in RIGHT motor. GREEN LED is LEFT motor

P1OUT = 0x41; // Stop motors (both LEDs ON) and
while ((P1IN & 0x08)); // wait for button press on P1.3


for (;;)
{

for (j=1; j<5 data-blogger-escaped-br="br" data-blogger-escaped-j="j"> {
P1OUT = 0x00; // RIGHT and LEFT OFF 'FORWARD'
for (i=0; i<100000 data-blogger-escaped-a="a" data-blogger-escaped-br="br" data-blogger-escaped-delay="delay" data-blogger-escaped-i="i" data-blogger-escaped-little="little">
P1OUT ^= 0x40; // LEFT ON (turn LEFT)
for (i=0; i<20000 data-blogger-escaped-a="a" data-blogger-escaped-br="br" data-blogger-escaped-delay="delay" data-blogger-escaped-i="i" data-blogger-escaped-little="little">
P1OUT =0x00; // Both OFF
for (i=0; i<50000 data-blogger-escaped-a="a" data-blogger-escaped-br="br" data-blogger-escaped-delay="delay" data-blogger-escaped-i="i" data-blogger-escaped-little="little">
} //end J loop

P1OUT =0x41; // Stop motors (both LEDs ON) and
while ((P1IN & 0x08)); // wait for button press


} //endless loop
} //main
-----

Multiple MSP430 Launchpad


-----

Another Useless Machine Build


-----

The "Ouchie" Box


-----

Perspective


-----

Installing an "always ON" Cigarette Lighter Port


-----