Arduino/Raspberry Pi based Dancing Clock
(→Comment, Questions, Contributions?)
|Line 281:||Line 281:|
Email me [[russ_hensel]], or use the talk page for this topic. All feedback is welcome.
Email me [[russ_hensel]], or use the talk page for this topic. All feedback is welcome.
[[category:projects]][[category:Serial Communications]][[category:Microcontroller]] [[:]]
Latest revision as of 17:10, 16 January 2018
This is a rework of an earlier PIC based project, see: PIC based Stepper Motor Dancing Analog Clock
This is an article started by Russ Hensel, see ["http://www.opencircuits.com/index.php?title=Russ_hensel#About My Articles" About My Articles] for a bit of info. The page is just begun, the project is 90% complete, it is the last 10% that kills you.
 next all copied from earlier article, in process editing it
- Name: Arduino/Raspberry Pi based Dancing Clock
- Purpose: An amusing analog clock, see below.
- Status: This is a draft. Code works but still in refinement, code available, email the user russ_hensel. Also still refining the project.
- Technology: Stepper Motors, Arduino, Raspberry Pi C++ and Python
- Author: russ_hensel ( where you can find an email address to reach me )
- License: Open source and object code.
This is an analog clock, with real hands driven by stepper motors. A clock for the confused dyslexics among us, for more information on Dyslexia see DAM ( Mothers Against Dyslexia ). Because stepper motors are quite powerful the clock could be made quite large, 3 feet in diameter is probably within reach still using inexpensive ( salvage ) stepper motors. The project description both the hardware and the software.
- None yet,
 Major Parts
- 2 Stepper Motors -- probably can be salvaged from printers or 5 1/4 disk drives ( where I got mine )
- Arduino -- mine is a nano, but pretty much anything with 8 io pins should do
- Low side Driver Chip -- but any transistors with reasonable beta and enough current handling capacity could be substituted.
- Raspberry Pi -- I think any model will do, or use any PC that can run Python.
- Case -- With a bit more work than I have done you could have a really nice case. I am working on an oak one now
- Clock Face -- Some good artwork here could make a really good looking clock, anyone willing to send me an high quality graphics file?
- Circuit Board -- Right now mine is built mostly on a proto board, but I have designed but not tested printed circuit boards suitable for single sided, toner transfer, fabrication.
- Python 3.6, could be adapted to 2.7 where it was originally developed, but I have finally moved on
- Wire, usb cables, misc boards, including if you wish prototyping boards ( how sloppy ).
 What it Looks Like
The current case, face, and hands are pretty rough, I am working on better ones, but it may be a bit of a wait.
Still photo: see above.
Video of a couple of minutes, running at 10x but the motion of the hands in real time ( minute ticks by in 6 not 60 seconds ) Short Video of Clock
|Hour hand/ Minute Hand||Hour hand is of conventional layout, but only changes hour on the hour. The minute hand is more like an elevator floor indicator, rotates 180 degrees, moves to the next minute on the minute.|
|Special effects -- Dancing||Hour and minute hands may "dance" at special times, see the video at: Short Video of Clock|
|Power / timekeeping||Powered from outlets, timekeeping based on the powerline ( which is long term very accurate (( less power outages )) ).|
|Optional Serial Interface||For debugging and demo of special effects|
|Dual Stepper motors||Salvage from printers and floppy drives. Independent drive of each hand.|
The circuit does not need much explanation beyond the schematic and parts list. Here is just an overview.
To make it really easy to fabricate the printed circuit boards I seperated the power supply from the processor board.
For parts I used used my junk box, when it fails consider SparkFun and Futurlec. Or..... See: Supplier.
To see the circuit and board in detail download the files and view in Eagle, the free version is fine.
 Power Supply
 Power Supply
12 volt 1 amp ( better 2 amp ) wall wart and an additional regulator module to go from 12 v to 5 v
 Processor Board
 Processor Schematic and Board
Nothing very fancy here. The 60 Hz input is fed to the port x interrupt. This lets the PIC keep time. The hands are not moved during the interrupt instead flags requesting hand movement are set and the main loop moves the hands.
Invalid states for the mode can easily happen with a rotory switch when the wiper is not fully in position. Because of this not all possible states on the mode input are used.
The stepper control is half step. The activation of the coils is determined by an array which hold the 8 different activations of the coils. My stepper motor has 200 full steps ( 400 half steps ) per revolution. You should be able to adjust the code for different steppers. Much of the steppeer code is very similiar to that in Stepper Motor Tester which may or may not have a better explanation of the code which drives the stepper motor.
For the serial interface code see Serial Communications Library -- BoostC and 16F877A
I have tried to have pretty good comments in the code, any comments on the comments ( helpfull one please ) let me know.
 Building the Clock
My first case is just a 3/4 inch board with a thinner ( about 1/4 inch ) board mounted perpendicularly to it for the face of the clock. Mounting the stepper motors can be problematic as the ones I encountered had no mounting tabs or holes. What I finally came up with is to drill a fairly large hole ( about 1 inch ) that matches a slightly raised cylinder around the shaft. Then bolt a plate across the back of the motor and sandwich the motor up against the hole. It holds well, centers up nicely, and is easy to take apart.
The face is just a piece of light cardboard with the face drawn on it. Be as creative as you can. You should be able to do better than my attempt. My hands are bamboo skewers from the kitchen drawer. They are pushed perpendicularly through a short piece of aquarium tubing which then slips over the motor shaft. Seems to work pretty well.
You should be able to make a much better looking clock, I am working on one and will report back later.
 Running the Clock
 Without the Serial Interface
 With the Serial Interface
This interface is not necessary but can be very useful for playing around with the clock, or debugging new version of the code. To use the serial interface you will need a cable, and perhaps a level shifter ( the Stepper Tester Stepper Motor Tester has a max232 level shifter, this circuit does not, you can get a level shifter as a seperate component or even built into a cable ). You will also need a serial terminal, generally a program for your PC. For information on a good terminal program see PC-Microcontroller Communications#Serial_Communications_from_a_PC_to_Microcontrollers
Notes on terminal program set up.
- Baud rate should be 19.2K 8N1
- Most terminal programs can be set to treat a carriage return as a carriage return line feed. Do it.
Some terminal programs will not transmit in lower case ( all our commands are lower case ) unless specially set to do so. Set it to allow lower case.
The clock should send debugging information about once a minute ( maybe ). It will also inform you of the changing of modes with the mode switch.
Then send an ! to the clock, the clock should respond with "Stopped; turn on serial mode" and you can then use the commands in the following table.
|!||Stop whatever is running, enter serial control mode.|
|Hn<cr>||set clock to hour n ( n is one or two digits ) and move the hands, but no dancing.|
|Mn<cr>||set clock to minute n ( n is one or two digits ) and move the hands, but no dancing.|
|R<cr>||Report on clock status|
|Dn<cr>||Dance the clock to hour n ( n is one or two digits ). Only move thg hour hand. Use to review debug the dance.|
|A<cr>||Adjust the hands to their 0 positions ( 12:00 ). If they are not correctly line up use the J and Y commands below|
|Yn<cr>||( Y is above the H ) adjust the hour hand by an amount n, where n is a signed number from about -100 to 100.|
|Jn<cr>||( J is above the M ) adjust the minute hand by an amount n, where n is a signed number from about -100 to 100.|
|X<cr>||Exit serial control, return to control by mode switch|
 Additional Ideas
- Add a chime perhaps using an D to A converter and small amp and speaker.
- Add an LED to show the clock is powered or running, make blink at 1 hz if that pleases you ( I do not like the blink ).
- Work on more dances.
- The mode control is based on inputs that are pulled down, the chip has an option for weak pull up on the port, using this and pulling down with the mode switch would get rid of a bunch of resistors on the board.
- Add battery backup to keep the internal time ( but not the hands ) running during a black out.
- Make it really big; the motors would probably drive a 3 foot diamater unit.
- For a related project see: Stepper Motor Tester
- Some clever gears might let you mount the hour and minute hands around the same axis, maybe start from some cheap clock or clock movement.
- Clock faces and hands can be bought ( google it ). Maybe they could be usefully incorporated.
 Modifications You May Need to Make
Motors vary, you want to know what the voltage, current, and step size is for your motor. The stepper tester project Stepper Motor Tester can be useful for this. It should give you the number of steps and tell you if your voltage is suitable. The motor only runs from time to time so some overvoltage is probably ok. If the number of half steps is different from 400 you can change the program and the layout of the minute hand to accomidate. A 7.5 degree per step motor has 96 half steps per rotation, use 60 of thes for a minute hand which will now swing over 180 degrees, I think you can still fit this on the dial. Not that the circuit for both the stepper tester and the clock are good for only 500ma so motors that use more than this will need a different driver. Comments in the code should help you modify the code for different numbers of steps and/or different dial layouts.
Will be at GitHub soon?
 Comment, Questions, Contributions?
Email me russ_hensel, or use the talk page for this topic. All feedback is welcome.