Converting a traffic light into a timer

elec_mech

Joined Nov 12, 2008
1,500
Tracecom,

Which IC(s) do you have handy? I've been curious to play with PICAXE's to help people here and this would be a good a time as any. I'm thinking this project will require at least a 14M, but I'm thinking about purchasing a few (8, 14, 18, 20) from Sparkfun. Any suggestions?
 

thatoneguy

Joined Feb 19, 2009
6,359
I use either the 08M2 for small stuff, or the PICAXE 20M2, that link is an excellent starter kit, has breadboard programmer, cable, PICAXE 20M2, and some starter parts for learning the basics. Aztec MCU is the best price for North America, Sparkfun overcharges and has a very limited selection.

I haven't seen any benefit of the 18M2 over the 20M2 (~0.1" difference in length), and the 14M2 has a few less features and is only ~0.3" shorter, all are the same width until you go to SOIC, which the 08M2 and 20M2 are readily available.

PICAXE M2 Comparison Chart
 

tracecom

Joined Apr 16, 2010
3,944
I have 08M, 08M2, 14M2, 18X, 18M2, 20M2, 20X2, 28X1. I was just looking to decide what to start with. We will need an output for each of the three lights and a buzzer. We will need an input for the start button and the reset button. Beyond that I am not sure; what about the time set buttons and the display?

BTW, I think you will find the prices much better at http://www.phanderson.com/ . I buy all my PICAXE stuff there; he is a contributor to the PICAXE community and ships really fast.

ETA: I just read thatoneguy's post. I am not familiar with Aztec MCU, so it wasn't my intention to contradict him. I tend to agree with him about the 20M2; it might be best to start with that. Who knows what will be added on in the design process?

ETA again: The 20M2 kit TOG linked to is a great deal. The USB programming cable from Rev-Ed costs about $24.
 
Last edited:

thatoneguy

Joined Feb 19, 2009
6,359
BTW, I think you will find the prices much better at http://www.phanderson.com/ . I buy all my PICAXE stuff there; he is a contributor to the PICAXE community and ships really fast
Is phanderson.com still shipping? Phil Anderson passed away a year or two back and that site was down for quite a while, but the store seems to be up again.

The owner of Aztec is a contributing member here, in Canada, they sell both arduino, nice PIC Kits with ZIF Sockets at low cost, and are fast with shipping with reasonable prices. Great selection in the dollar section too.
 

tracecom

Joined Apr 16, 2010
3,944
I did not know that Peter Anderson died, and have not ordered from his website since then. Things may have changed since then.

I see that the USB programming PCB on Aztec is from OMS. At one time, BillO (who posts here) was part of that company...may still be. Is that who you mean?
 

thatoneguy

Joined Feb 19, 2009
6,359
I did not know that Peter Anderson died, and have not ordered from his website since then. Things may have changed since then.

I see that the USB programming PCB on Aztec is from OMS. At one time, BillO (who posts here) was part of that company...may still be. Is that who you mean?
Yes, BillO is a large part of that site. The -AXE boards with ZIF sockets are handy for programming then slapping into a board, but the breadboard programmer is very handy as well.
 

tracecom

Joined Apr 16, 2010
3,944
I have the attached circuit breadboarded and working. As you can see, I am using LEDs to simulate the traffic lights; those same μC outputs will ultimately drive the 120 VAC lights. I have a representative pattern going:

Grn on for 10 seconds
Grn Off
Yel on for 8 seconds
Yel flashes 10 times in 2 seconds
Buzzer sounds 10 times in 2 seconds
Yel off
Buzzer sounds for 1 second
Red on for 10 seconds.
Red off

The code is far from elegant, but I am happy to have gotten this far today.
 

Attachments

elec_mech

Joined Nov 12, 2008
1,500
thatoneguy,

Thank you for the link and suggestions. I'm debating on buying the kit (certainly the best price I've seen on true complete kit with programming cable) or being cheap and buying just the chips and using an older serial to USB adapter I have or buying the chips and a USB programmer. The website you posted has great prices.

Tracecom,

Nice job. Sorry I haven't had a chance to put together a schematic for the digits side yet, work and home life have been busy recently. I forgot about the buzzer. My understanding was the OP wanted to have a four-digit display (MM:SS) settable via a minute and second button to set the total countdown time. Once set, the start/pause button would be pushed to begin countdown. The uC would monitor the time and turn on and off the lights at specific times programmed into the code (as you've done). Based on this, 11 I/O's are currently needed: 4 button inputs (start/pause, minute increment, second increment, reset), 3 light outputs, 3 serial lines for SPI communication to a display IC, and the buzzer output.

20M2 sounds like a good bet. I fully agree, having more I/O's is always better as the odds are more functionality may be needed later.

I haven't reviewed the PICAXE documentation in detail yet - have you programmed these to work with an SPI (serial) IC before? I'm still leaning toward the MAX7221. I have several from a small production project I plan to make in the future, but thanks to Mike's suggestions and PIC project, I'm going to look into running the digits from the PIC directly. In any event, I can spare a couple and send them to you if you'd like to give them a shot. I may have a 4-digit display I can send you too if interested. I'd still like to try my hand at a PICAXE, but it'll probably be a week before I can get my hands on some. 'Course, I could always attempt to write some code now and send it your way if interested.
 

tracecom

Joined Apr 16, 2010
3,944
Great progress! The schematic seems simple - I can actually understand it, heh.

You mean this USB cable, http://www.picaxe.com/Hardware/Cables/PICAXE-USB-Download-Cable/ - correct?

Might you post/send the code, I'm curious to see how much I can understand.
The beauty of a μC based project is that so much of the complexity is inside the chip.

Yes, that's the USB cable that I have, but if I didn't have it, I would be likely to buy the one that one guy linked to a couple of posts back. If you want to order something, that kit would be a good choice.

As to posting the code, right now I am embarrassed by it. Let me work on it some more.
 

tracecom

Joined Apr 16, 2010
3,944
Tracecom,

Nice job. Sorry I haven't had a chance to put together a schematic for the digits side yet, work and home life have been busy recently. I forgot about the buzzer. My understanding was the OP wanted to have a four-digit display (MM:SS) settable via a minute and second button to set the total countdown time. Once set, the start/pause button would be pushed to begin countdown. The uC would monitor the time and turn on and off the lights at specific times programmed into the code (as you've done). Based on this, 11 I/O's are currently needed: 4 button inputs (start/pause, minute increment, second increment, reset), 3 light outputs, 3 serial lines for SPI communication to a display IC, and the buzzer output.

20M2 sounds like a good bet. I fully agree, having more I/O's is always better as the odds are more functionality may be needed later.

I haven't reviewed the PICAXE documentation in detail yet - have you programmed these to work with an SPI (serial) IC before? I'm still leaning toward the MAX7221. I have several from a small production project I plan to make in the future, but thanks to Mike's suggestions and PIC project, I'm going to look into running the digits from the PIC directly. In any event, I can spare a couple and send them to you if you'd like to give them a shot. I may have a 4-digit display I can send you too if interested. I'd still like to try my hand at a PICAXE, but it'll probably be a week before I can get my hands on some. 'Course, I could always attempt to write some code now and send it your way if interested.
So, I guess we have settled on the 20M2.

The only display I have used with the PICAXE is an LCD with a serial to parallel converter. It worked really well; I'll attach a pic of it with a display from a time and temp module that I built. It used a three wire interface, power, ground, and signal.

As to the MAX7221, I already took a look at the datasheet, but I will study it some more. I didn't have a four digit cc 7 segment display, so I built one last night, so I would like to get a MAX7221. Meanwhile, I'll try to look into muxing the 7 segment displays with a PICAXE; I know it has been done, and I can probably find some code for it.
 

Attachments

thatoneguy

Joined Feb 19, 2009
6,359
20M2 sounds like a good bet. I fully agree, having more I/O's is always better as the odds are more functionality may be needed later.

I haven't reviewed the PICAXE documentation in detail yet - have you programmed these to work with an SPI (serial) IC before? I'm still leaning toward the MAX7221. I have several from a small production project I plan to make in the future, but thanks to Mike's suggestions and PIC project, I'm going to look into running the digits from the PIC directly. In any event, I can spare a couple and send them to you if you'd like to give them a shot. I may have a 4-digit display I can send you too if interested. I'd still like to try my hand at a PICAXE, but it'll probably be a week before I can get my hands on some. 'Course, I could always attempt to write some code now and send it your way if interested.
The 20M2 supports both SPI and I²C. I use I²C for MAX6956 LED Driver/LED Expander, posted in another thread here, an autonomous robot with sonar, IR Proximity, IR Range, and other functions, all based around a 20M2, and only ½ the code space is used. At 32Mhz, some delays still need to be used, even at 16Mhz, due to to IR and sonar read times. They are very powerful chips. The only downsides are all variables are global, and functions aren't supported, though subroutines are.

The editor simulation (which supports user variable injection/changes while simulating) prior to programming, and the full in circuit debugging while running is a HUGE advantage over the Arduino. Though the Arduino is more powerful than a PICAXE due to being programmed in compiled C, the "sketch" language has a steep learning curve, no simulation, less direct control of ports and I/O, and no in circuit debugging other than printing to serial terminal.

A PICAXE app can be completely built and tested without the hardware, just like a PIC, with only the hardware bugs and timing to finesse once the hardware is in place.
 

elec_mech

Joined Nov 12, 2008
1,500
Okay, here is a first cut at the schematic.

OP, please take a look and let us know if this is roughly how you envision the unit to operate.


Currently,
  1. Minute and second buttons are used to increment display by one minute and one second, respectively, each time they are pressed.
  2. Reset button clears the display and turns off all lights.
  3. Start/pause button is used to begin countdown as long as the displayed value is greater than 00:00. It will also stop the count and resume.
  4. When each light comes on, blinks and for how long will be programmed in and can only be changed by modifying the code. We will follow the sequence the OP originally mentioned and which is shown in the flowchart unless told otherwise.
The schematic is a first draft and is subject to change. Some notes:
  • R7 determines current to the display and will depend on the display selected.
  • Buttons are used with pull-down resistors. This may change to pull-ups if it makes programming for one reason or another easier.
  • Fuse values selected somewhat arbitrarily. 60W bulbs consume ~0.5A, so 1A was selected for some cushion. Let me know if you feel another value should be chosen.
  • For the sake of reducing parts variety, an opto-isolator is used to control the buzzer in the event it requires more current than the PICAXE can provide. Actual voltage used to power buzzer will be subject to buzzer selected.
  • Pins used on PICAXE were selected arbitrarily. Please let me know if the ones selected will not work for their intended purpose.
OP,


We can make selections for the parts if you're not too concerned about picking them out yourself. A few questions regarding parts:
  1. Would you prefer 1" tall digits with a MM.SS format or 0.39" tall digits with a MM:SS format? Both are about $2-3 from the source I have in mind and include all four digits.
  2. What color would you like the digits to be, e.g., red, green, yellow, blue, or white?
  3. What kind of buzzer do you have in mind? Little one to get attention or big one to make you flee for your life?
You'll also want to think about how you're going to build this, what to enclose it in, etc.
 

Attachments

tracecom

Joined Apr 16, 2010
3,944
The schematic looks good. You are correct in that VO4 may not be required; depending on the buzzer selected, we may need a BJT, MOSFET, or nothing at all.

I have been playing with some common Omron 1/4" buttons on the 20M2. Some of them will debounce with a 100 mS pause, but some require 150 mS.
 

tracecom

Joined Apr 16, 2010
3,944
Just noticed on the schematic.

"Leg" 19 (That's PICAXE lingo; they use "pin" for another purpose.) is usually reserved for Serial Out. Similarly, leg 2 is always reserved for Serial In.
 

tracecom

Joined Apr 16, 2010
3,944
We may have another issue. I am not sure, but I think hardware SPI may only be available on X series parts, e.g., 20X2. If we continue with the 20M2, it may require bit banging for communication with the MAX7221.
 
Top