Intro: A Raspberry Pi Controlled Two Faced Clock
This instructable shows how to use a 'Simple but Strong Plastic Box', (https://www.instructables.com/id/A-Simple-but-Strong-Plastic-Box/) from my previous Instructable, to make a Two Faced Clock which uses a Raspberry Pi to control two stepper motors.
I'll not explain how to make the box itself, but will show how to measure, mark and make the holes for the stepper motor drive shaft.
At the end will be links to github where my sample code can be found and down loaded.
The photos here show the two faced clock as it looks completed and also as it is wired to an older Raspberri Pi Model B and also a newer Raspberry PI 2 Model B.
Step 1: What You Will Need
To build this you will need the following:
1. A Raspberry Pi - any version (A/A+/B/B+/2)
2. Optional: if using an A/A+/B you will probably need a powered USB 2.0 Hub
3. A Stepper motor controller board (such as this one: http://4tronix.co.uk/store/index.php?rt=product/product&keyword=stepper%20motor&category_id=0&product_id=318)
4. 2 small stepper motors (I used 28BYJ-48 as these are cheap and easy to find: http://4tronix.co.uk/store/index.php?rt=product/product&keyword=stepper%20motor&category_id=0&product_id=196 - you do not need the small controller board offered here)
5. 2 plastic game spinner pointers (such as these: http://www.ebay.co.uk/itm/Plastic-Game-Spinner-Pointers-71mm-Classroom-Resources-/201397554255?hash=item2ee43acc4f)
6. A4 sized Polystyrene sheet (suggested thickness 2mm)
cut into the following sizes
a. 1 off - 90mm * 180mm for the clock faces
b. 2 off - 30mm * 180mm for the sides of the clock body
c. Optional: 2 off - 30mm * (90mm(-2 * thickness of sheet)) for the top and bottom of the clock body
7. Polystyrene angle (such as this: http://www.ebay.co.uk/itm/PLASTRUCT-ANGLES-Range-Polystyrene-Plastics-for-Scale-Models-Weld-Paint-/351150518899?var=&hash=item51c233b273 I use the AFS-10P type - Plastruct 90507)
Step 2: Tools Needed
This is a list of the tools you'll need to use
1. Small needle files
2. drill and 9mm drill bit
3. plastic glue or super glue (cyanoacrylate)
4. hot melt glue gun with glue stick (not the sort for wood)
5. Metal ruler
6. Sharp Knife (like a Stanley knofe or similar)
7. A fine marker/pen to mark the plastic sheet
Step 3: Marking the Clock Face for the Mounting Hole
This step describes a simple method for marking the centre and making the holes to mount the stepper motors.
It uses the 180mm x 90mm piece of plasticard/plastic sheet which should be cut to size. This is all detailed in my other instructable about making the plastic boxes.
Note: If you have already glued the sides then use a marker or pen which you can erase from the front, otherwise do all your work on the back of the face side.
- Mark out the face into two halves, making each half 90mm x 90mm
- Now draw a line from corner to corner in each half, this should create a 'X' which crosses in the middle of each half.
- Make a mark where the lines cross, this is where the hole will be made for the stepper motor output shaft.
- Use a 9mm drill bit to make the hole. I sometimes use a 2mm or 3mm to make the hole first as it's then easier to guide the larger drill bit through.
Now is the time to glue the sides onto the rear of the face assuming you didn't already do this.
Mount the stepper motors through the holes
Hold them in place with the hot melt glue
Note: I use hot melt glue here because it sets quickly and can be removed quite easily
Step 4: Adding the Hands
In this step, you will need to use the needle file to widen the hole in the spinner so that it will fit over the output shaft of the stepper motor.
The first photo shows a pair of spinners, one before the widening and one after. It only takes a few minutes of careful filing to achieve the desired result.
The second shoto shows a pair of spinner mounted.
If you don't like the idea of filing the spinner hands them you could glue them on but this isn't quite as good as widening the holes and the spinners are made of a type of plastic which doesn't glue very easily and will always make a weak bond. Alternatively you could hold them in place with a material like Milliput (or Games Workshop's Green Stuff) or even Sugru.
Step 5: Add the Stepper Motor Controller and Wire Things Up
Now we come to the Raspberry Pi itself.
- Make sure power is disconnected from the Pi.
- Put the stepper motor controller onto your Pi.
- Add power to the stepper motor controller:
- if using a Pi Model B+ or a Pi2, use a spare USB port
- if using a Model A/A+ or B, connect via a Powered USB hub
Download my sample programs from github, there are two programs each of which will be explained in the next steps.
The first program is called reset.py: https://github.com/tanj666/reset
The second program is called pytime.py: https://github.com/tanj666/pytime
You will need your web browser to download the programs.
Step 6: Reset.py
This program allows you to set the position of the hands.
You will need to set the two hands to the 12 o'clock positions for the second program, pytime.py, to work correctly.
- When you use the program it will ask for a delay time. This is the time between the stepper motors moving a single step and should be in the range 3 to 50. A larger value means a longer delay. As even a small movement of the hands requires several steps of the motor, using a large value is useful only for watching the change of the status lights of the stepper motor controller board if it has them.
- The second input is to decide which motor, the answer will need to be L for left motor, R for right motor or B for both motors.
- After this you will need to tell the program if the hands are to move, C for Clockwise or A for Anticlockwise
- Finally you need to say how many degrees the hand/s are to move in degrees.
Each hour is 30 degrees apart. Each minute is 6 degrees apart. You can use this move the hands to the various points around the faces to mark the hours and minutes positions of each of th clock faces as shown in photo.
This program could be used for educational purposes for telling the time.
From a terminal window, change to the directory where you stored the program, then use the following command to start the program:
sudo python reset.py
Step 7: Pytime.py
This second program uses the system clock on the Pi to move the hands to show the time.
It uses a pygame interface for very simple control of the program, this shows a black window with the title. With this as the active windows, pressing the 'ESC' key (or CTRL+C) will stop the program. Watch what happens when you do!
- NOTE: Before you use this program, make sure that you set the hands to the 12 o'clock positions using reset.py. This is because the program does not know what the position of the stepper motors is when it starts and so has to assume the 12 o'clock position.
From a terminal window, use the following command to start the program:
sudo python pytime.py
Runner Up in the
Raspberry Pi Contest