Saturday, June 23, 2012

"Etch a Sketch" Turned Temperature Data Logger

A friend of mine gave me an OKI office printer.  The thing was HUGE and after about five years it finally broke.  Next step, out comes the screwdriver to rescue any useful parts; of which where several stepper motors.  Since what I didn't know about stepper motors was a lot I searched for a "useful" way to learn about them.  I decided to connect two of the stepper motors to an "Etch a Sketch" and ended up with this rig that graphically logs temperature in a strip chart fashion.


Here is a video if you are not interested in the build details and just the want to see the result.  The beer was cold.  The water in the shot glass hot.  Hot makes the graph go up.  Cold makes the graph go down.  When the graph reaches the far right of the "Etch a Sketch" the stylus moves full left and the process repeats.  In the video a temperature measurement is taken (and graphed) every 750 milliseconds, but that can be adjusted to anything; one reading per hour for example. 


-----
The process of driving the steppers was not trivial in the beginning.  First, I had no documentation on these steppers.  The second being I had no idea how "noisy" and power hungry the steppers could be.    The documentation turned out not to be a big deal.  Via the magic of the internet I learned they were of 4-wire, bi-polar configuration.  An ohm meter is all that is needed to figure out the connection scheme. 

----
Close up of one of the OKI printer 4-wire bipolar stepper motors:

-----
Driving a stepper motor requires a microcontroller.  My choice for a microcontroller was the PICAXE 18M2.  
-----
A stepper motor is not like a 'common' DC motor.  You cannot just apply a current and have the stepper spin.  The current has to be applied in sequence across the four available wires.  You also have to control the polarity (direction) of the current.  That said, steppers motors take way more current than a microcontroller can provide.  An H-Bridge motor driver solves the problem by providing more available drive current for the stepper and the ability to switch current drive polarity.

I was familiar with the SN754410NE H-Bridge motor driver.  Plus, I had some in my kit.  So, originally I decided to use one SN754410NE to drive each stepper motor.  This was a mistake that added much frustration.  The stepper motors are incredibly noisy and current hungry.  The noise caused by the steppers and energy from their back EMF (I think) caused nothing to work reliably.  After seeing on a datasheet that L293D motor drivers have protection diodes and some other features, I gave them a try instead.  The L293D is pin compatible with the SN754420NE so the swap was easy.  After inserting the L293D's everything started moving forward as planned with controlling the steppers.


-----
Now that we can control the stepper motors via the PICAXE 18M2 and L293D's we still need to interface then some way to the "Etch a Sketch".  I had a clear plastic cube thats purpose was to protect a trophy baseball.  Since I didn't have a trophy baseball I dismantled the cube and used the two "C" shaped pieces to mount the steppers to with the help of a Dremmel tool and double sided sticky tape.
-----
After mounting the steppers motors, you still have to mechanically couple them to the "Etch a Sketch".  Rubber hose and zip tie wraps worked perfectly.
-----
After getting the mechanicals figured out a "test" pattern was programmed into the PICAXE.  The test worked on the first run so we grabbed the video camera to document the success.


-----
Now that the stepper motors make the "Etch a Sketch" draw, we still need a way to measure temperature.  The PICAXE 18M2 is used to read a DS18B20 sensor (picture below) via I2C bus for this:

-----
To manually position the "Etch a Sketch" stylus, two buttons are wired into the PICAXE 18M2:
-----
After all of that it is just code and software debugging. 

I have other plans for the rig.  Stay tuned!
-----
If you are still with me, here is the build schematic (click to enlarge):
-----

Sunday, June 3, 2012

Swim Heat Counter with PICAXE 08M2

A friend of mine had the exciting job of flipping cards to display heats at his daughter's swim tournament.  Not difficult to do, but it doesn't allow the much mobility for the person assigned to the job.  Wouldn't it be nice to modernize the task and make it wireless?
-----
With a PICAXE 08M2 microcontroller and a few servos the electrical part of the task is pretty simple.   Basically two buttons (a ONES place button and a TENS place button) pull an input to the PICAXE high, causing a subroutine to be called and the appropriate servo to move.  Adding wireless to the rig should be easy as well by re-purposing a cheap remote from a toy RC car to replace the two button/switches that cause the servos to move. 

Adding the mechanical digits will not be completely trivial, by my buddy says he is up to the challenge.
-----
 Short video of the rig in action.
-----
Schematic drawing of the build (click to increase size):
-----
PICAXE 08M2 Project Source Code.  Very simple:

#rem
 *******************************
 ***** www.WhiskyTangoHotel.Com  *****
 *******************************
    Project Name: Walker Swim Heat Counter

    Start Date: June 1, 2012
    
    Program Rev History: 
    This version steps the a ONES digit Servo and a
    TENS digit Servo in ten increments to "display"
    the numbers 00-99.

 ******************************* 
    PICAXE PE Rev: 5.5.1
#endrem

#picaxe08m2 ' using PICAXE 08M2 uC
#COM11 'programming on COM11

'min servopos value = 75
'center servopos value = 150
'max servopos value = 255

symbol Ones_Button = pinc.4 'input button for Ones digit.  Pull high to count
symbol Ones_Position = b0 'servo location var


symbol Tens_Button = pinc.3 'input button of Tens digit.  Pull high to count
symbol Tens_Position = b1 'servo location var

'b2 is variable used for math in calculating both servo positons

'Init some stuff...
let dirsC = %11000111  ' define I/O of PortC.  Not really required.

servo 1,150 ; initialise ones digit servo
servo 2,150 ; initialise tens digit servo
Ones_Position = 0
'Calculate and move Ones digit Servo to "display" 0
b2 = Ones_Position * 15 + 75
servopos 1, b2

Tens_Position = 0
'Calculate and move Tens digit Servo to "display" 0
b2 = Tens_Position * 15 + 75
servopos 2, b2

main: 'main loop continually checks if a button is pushed to move the Servos.
If Ones_Button = 1 then 'move servo for Ones Digit
gosub Change_Ones
endif

If Tens_Button = 1 then 'move servo for Tens Digit
gosub Change_Tens
endif

goto main 'loop and check for button presses


Change_Ones: 'Routine called when "Ones" button is pressed.
If Ones_Position = 9 then 'highest position is '9'.  Wrap to '0'
Ones_Position = 0
else
Ones_Position = Ones_Position + 1
endif
'Convert the Ones_Position into the correct servo location
let b2 = Ones_Position * 15 + 75
Select Case b0
Case 0
servopos 1, b2
Case 1
servopos 1, b2
Case 2
servopos 1, b2
Case 3
servopos 1, b2
Case 4
servopos 1, b2
Case 5
servopos 1, b2
Case 6
servopos 1, b2
Case 7
servopos 1, b2
Case 8
servopos 1, b2
Case 9
servopos 1, b2
endselect
pause 500 'delay 500mSec to allow the servo to move
return ' Change_Ones

Change_Tens: 'Routine called when "Tens" button is pressed.
If Tens_Position = 9 then 'highest position is '9'.  Wrap to '0'
Tens_Position = 0
else
Tens_Position = Tens_Position + 1
endif
'Convert the Tens_Position into the correct servo location
let b2 = Tens_Position * 15 + 75
Select Case b0
Case 0
servopos 2, b2
Case 1
servopos 2, b2
Case 2
servopos 2, b2
Case 3
servopos 2, b2
Case 4
servopos 2, b2
Case 5
servopos 2, b2
Case 6
servopos 2, b2
Case 7
servopos 2, b2
Case 8
servopos 2, b2
Case 9
servopos 2, b2
endselect
pause 500  'delay 500mSec to allow the servo to move
return 'Change_Tens
-----