1 / 39

2014 Amherst Railroad Hobby Show

2014 Amherst Railroad Hobby Show. Dave Bodnar January 24, 2014 Amherst, MA. This presentation is available on-line at: www.trainelectronics.com or www.davebodnar.com. Revised 01-24-14. Introduction - What is a PICAXE?. History Developed in Great Britain Designed for use in schools

niran
Télécharger la présentation

2014 Amherst Railroad Hobby Show

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2014 Amherst RailroadHobby Show Dave Bodnar January 24, 2014 Amherst, MA This presentation isavailable on-line at:www.trainelectronics.com or www.davebodnar.com Revised 01-24-14

  2. Introduction - What is a PICAXE? • History • Developed in Great Britain • Designed for use in schools • Financed by energy companies

  3. Introduction – What are its Capabilities? • Has all of the capabilities of a computer • Input • Output • Memory • Control

  4. Introduction - What are its Limitations? • Voltage must be controlled • Requires a computer for initial programming • Expects correct syntax in programs

  5. What is needed to use a PICAXE? • Hardware – circuit, PICAXE • Software – free from PICAXE.com • USB programmer • Computer – Windows, Mac or Linux • Power – 3-5 volts from batteries or plug in adapter

  6. How can it be used in a model railroading environment? – • Lights – usually LEDs but others, too • Motors – control speed & direction of rotation • Animations – only limited by your imagination! • Servos – for turnouts, animations, signals • Sound – controls external sound boards • Control – can operate a train, switches, signals, etc.

  7. Hardware – what we need • PICAXE – many types available – using 14M2 for this workshop • Components to complete a basic circuit – two resistors, voltage regulator, programming header, power supply (battery or plug-in) • Windows computer – operating system may be as old as XP (not Windows ME!) • Programmer – USB to 3 pin servo plug

  8. Software – what we need • PICAXE software from http://picaxe.com • Includes editor, simulator and programming software • Manuals available under Help

  9. Pre-Wired PICAXE Circuit Board • This schematic shows the circuit’s parts

  10. Voltage Regulator • A 7805 voltage regulator and filter capacitor are used to convert higher voltages to 5 volts

  11. Circuit Board • Components: • up to 6 LEDs • 2 trigger switches • 2 potentiometers • 6 power transistors • 5 volt regulator

  12. Other Components • Two programming resistors and a 3 pin connection to the programmer • Pin 1 helps you to orient the chip in its socket • What do the current limiting 470 ohm resistors do? • You must properly orient LEDs & 2N2222 (NPN) transistors

  13. Manuals • There are three manuals that are accessible from the programming environment • Click Help to show them

  14. Install 1 LED • Plug one red/black lead to the pins labeled as LED1 • Red wire to +

  15. First Program #TERMINAL 4800 'start terminal at 4800 baud #NO_DATA 'don't download data - speeds up programming #PICAXE 14M2 'identify the chip being used SYMBOL LED1 = b.2 'pin 11 SERTXD (13,10,"One Flashing LED - d. bodnar 8-14-2013") Top: TOGGLE LED1 'if it is on turn off, if off turn on PAUSE 500 'wait for 1/2 second GOTO Top: • How can we change the speed of flashing? • How can we change which LED flashes?

  16. Simulation is Built In!

  17. Program #2 – add a potentiometer #TERMINAL 4800 'start terminal at 4800 baud #NO_DATA 'don't download data - speeds up programming #PICAXE 14M2 'identify the chip being used SYMBOL LED1 = b.2 'pin 11 SYMBOL Pot1 = pinb.1 'pin 12 SYMBOL Rate = w13 'word variable to store flash rate SERTXD (13,10,"One Flashing LED - rate set by pot - d. bodnar 8-14-2013") Top: TOGGLE LED1 ' if it is on turn off, if off turn on READADC b.1, Rate SERTXD ("Rate = ", #Rate, 13,10) 'show rate reading on terminal Rate = Rate * 10 'make Rate 10 times larger PAUSE Rate GOTO Top: What is the range READADC returns? Why is SYMBOL using W13, a word variable?

  18. Program #3 – add a trigger #TERMINAL 4800 'start terminal at 4800 baud #NO_DATA 'don't download data - speeds up programming #PICAXE 14M2 'identify the chip being used SYMBOL LED1 = b.2 'pin 11 SYMBOL Pot1 = pinb.1 'pin 12 SYMBOL Trigger1 = pinc.4 'pin 3 SYMBOL Rate = w13 'word variable to store flash rate SERTXD (13,10,"One Flashing LED - rate set by pot - d. bodnar 8-14-2013") Top: IF Trigger1 = 1 THEN SERTXD ("Waiting...",13,10) GOTO Top: ENDIF TOGGLE LED1 ' if it is on turn off, if off turn on READADC b.1, Rate SERTXD ("Rate = ", #Rate, 13,10) 'show rate reading on terminal Rate = Rate * 10 'make Rate 10 times larger PAUSE Rate GOTO Top: What is the advantage of having “Waiting” sent to the terminal while no trigger is seen? What is the disadvantage?

  19. Change to 2 Red LEDs • Pry green LEDs from 2 white sockets • Install two red LEDs • Be sure to align longer LED lead (anode) with red wire • Shorter LED lead (cathode) to back wire • Install on LED1 and LED2

  20. Program #4 – two LEDs #TERMINAL 4800 'start terminal at 4800 baud #NO_DATA 'don't download data - speeds up programming #PICAXE 14M2 'identify the chip being used SYMBOL LED1 = b.2 'pin 11 SYMBOL LED2 = b.4 'pin 9 SERTXD (13,10,"Simple Crossing Signal - d. bodnar 8-14-2013") Initialize: HIGH LED1 ' LED1 ON LOW LED2 ' LED2 OFF Top: ' just a LABEL TOGGLE LED1 ' if LED1 is on turn it off, if off turn on TOGGLE LED2 ' same for LED2 PAUSE 500 ' PAUSE for 1/2 second GOTO Top: 'Do it again

  21. Program #5 – add a timer #TERMINAL 4800 'start terminal at 4800 baud #NO_DATA 'don't download data - speeds up programming #PICAXE 14M2 'identify the chip being used SYMBOL LED1 = b.2 'pin 11 SYMBOL LED2 = b.4 'pin 9 SERTXD (13,10,"Timed Crossing Signal - d. bodnar 8-13-2013",13,10) Initialize: HIGH LED1 ' LED1 ON LOW LED2 ' LED2 OFF FOR B1 = 1 TO 20 'repeat things between here and NEXT B1 20 times SERTXD ("B1 = ",#b1,13,10) ' display value of B1 on terminal TOGGLE LED1 TOGGLE LED2 PAUSE 500 NEXT B1 'go back and get the NEXT B1 until it equals 20 SERTXD ("Pausing for 10 seconds",13,10) LOW LED1 'LED1 off LOW LED2 'LED2 off FOR B1 = 1 TO 10 SERTXD ("PAUSE = ",#b1,13,10) PAUSE 1000 'PAUSE for 1 second NEXT B1 GOTO Initialize: 'do it again

  22. Program #6 – Start on Trigger #TERMINAL 4800 'start terminal at 4800 baud #NO_DATA 'don't download data - speeds up programming #PICAXE 14M2 'identify the chip being used SYMBOL LED1 = b.2 'pin 11 SYMBOL LED2 = b.4 'pin 9 SYMBOL Trigger1 = pinc.4 'pin 3 SERTXD (13,10,"Crossing Signal start with trigger - d. bodnar 8-13-2013",13,10) StayHere: SERTXD ("No Trigger Seen",13,10) IF Trigger1 = 1 THEN StayHere: 'no button - keep looking Initialize: HIGH LED1 ' LED1 ON LOW LED2 ' LED2 OFF FOR B1 = 1 TO 20 'repeat things between here and NEXT B1 20 times SERTXD ("B1 = ",#b1,13,10) ' display value of B1 on terminal TOGGLE LED1 TOGGLE LED2 PAUSE 500 NEXT B1 'go back and get the NEXT B1 until it equals 20 LOW LED1 'LED1 off LOW LED2 'LED2 off GOTO StayHere: 'do it again

  23. Program #7 – 2 Triggers #TERMINAL 4800 'start terminal at 4800 baud #NO_DATA 'don't download data - speeds up programming #PICAXE 14M2 'identify the chip SYMBOL LED1 = b.2 'pin 11 SYMBOL LED2 = b.4 'pin 9 SYMBOL Trigger2 = pinc.3 'pin 4 SYMBOL Trigger1 = pinc.4 'pin 3 SERTXD (13,10,"Two Trigger Crossing Lights - one starts, other stops - d. bodnar 8-14-2013") PauseBeforeStart: 'prevents detecting slow button push or restart LOW LED1 LOW LED2 PAUSE 1000 CheckButtons: SERTXD ("No Trigger Seen",13,10) b1=0:b2=0 'clear variables IF Trigger1 = 1 AND Trigger2 = 1 THEN CheckButtons ' no button hit if Trigger1 = 0 THEN SERTXD ("Trigger 1 hit first",13,10) b1=1 'save which button hit first GOTO Flash 'skip ahead and start blinking ENDIF SERTXD ("Trigger 2 hit first",13,10) b2=1 'save which button hit first Flash: HIGH LED1 LOW LED2 FlashAgain: FOR w3= 1 TO 100 'check for button before changing lights IF b2=1 AND Trigger1=0 THEN PauseBeforeStart IF b1=1 AND Trigger2=0 THEN PauseBeforeStart NEXT w3 SERTXD ("toggling!",13,10) TOGGLE LED1:TOGGLE LED2 GOTO FlashAgain: Explain “FlashAgain” routine How can you slow flashing?

  24. Program #8 – Morse Code Change message Don’t forget the !

  25. Single White LED • Install a white LED (clear body) • Connect to LED1 on board

  26. Program #9 - Lighthouse FOR loopie = 150 to 0 step -1 'repeat backwards SERTXD (#loopie, " ") PWMDUTY LED1, loopie PAUSEUS Dlay 'PAUSE a bit IF Loopie > 75 THEN Dlay = Dlay +135 ELSE Dlay = Dlay +45 ENDIF NEXT loopie SERTXD (13,10,"pausing",13,10) PWMOUT c.2,255,0 LOW c.2 PAUSE 15000 'PAUSE a bit with LED off SERTXD ("pausing DONE",13,10) GOTO start 'do it again! #TERMINAL 38400 ' faster due to oscillator change SETFREQ #NO_DATA 'speeds up programming #PICAXE 14M2 'identIFy the chip SETFREQ m32 'speed it up to 32 MHz SYMBOL Loopie = b2 'label variable b2 as Loopie SYMBOL Dlay = w10 SYMBOL LED1 = b.2 'Pin 11 SERTXD (13,10,"New Lighthouse - 8-14-13 - d. bodnar",13,10) PWMOUT LED1,150,150 Start: Dlay=20000 FOR Loopie = 0 TO 150 SERTXD (#loopie, " ") PWMDUTY LED1, loopie 'use PWM to brighten the LED PAUSEUS Dlay 'PAUSE a bit IF Loopie > 75 THEN Dlay = Dlay -135 ELSE Dlay = Dlay -45 ENDIF NEXT loopie 'get the NEXT item in fir/NEXT SERTXD (13,10, "BRIGHT ") PWMOUT LED1, 255,1023:PAUSE 1000 'flash to full bright briefly

  27. Lighthouse Beacon Something about this should be bothering you!? Pulsed Width Modulation How does a pin that is normally either ON or OFF provide variable voltage? 0 volts 1.25 volts 2.5 volts 3.75 volts 5 volts

  28. 2 White LEDs • Connect a white LED to LED1 • Connect another white to LED2

  29. Program #10 – Ditch Lights 'd. bodnar 1-16-14 #picaxe 14M2 #terminal 4800 Symbol LED1 = b.2 'pin 11 Symbol LED2 = b.4 'pin 9 SYMBOL minimum = 1 SYMBOL maximum = 400 SYMBOL speed = b6 pwmout LED1, 255, 1000 pwmout LED2, 255, 1000 top: readadc b.1, speed:speed=speed / 5 min 5 for w0= minimum to maximum step speed sertxd (#w0," ",#speed,13,10) pwmduty LED1, w0 w1=maximum-w0+minimum pwmduty LED2, w1 next w0 readadc b.1, speed:speed=speed / 5 min 5 for w0= maximum to minimum step -speed sertxd (#w0," ",#speed,13,10) pwmduty LED1, w0 w1=maximum-w0+minimum pwmduty LED2, w1 next w0 goto top

  30. Install 6 LEDs • Connect Red to LED1 and LED4 • Connect Amber to LED2 and LED5 • Connect Green to LED3 and LED6

  31. #11- Traffic light with 6 LEDs Top: 'One red and Two green gosub AllOff high Red1 high Green2 w3=0 StayHere: w3=w3+1 sertxd (#w3," ") if Trigger1 = 1 and w3< 1000 then StayHere: low Green2 high Yellow2 pause 4000 low Yellow2 high Red2 low Red1 high Green1 w3=0 ButtonStillOn: w3=w3+1 sertxd (#w3," ") if Trigger1 = 1 and w3< 1000 then ButtonStillOn: StayHere2: if Trigger1 = 0 then StayHere2: low Green1 high Yellow1 pause 4000 low Yellow1 high Red1 low Red2 high Green2 ButtonStillOn2: if Trigger1 = 0 then ButtonStillOn2: goto top: AllOff: low Red1:low Yellow1:low Green1 low Red2:low Yellow2:low Green2 return #NO_DATA #TERMINAL 4800 Symbol Red1 = b.2 'pin 11 Symbol Yellow1 = b.4 'pin 9 Symbol Green1 = b.5 'pin 8 Symbol Red2 = c.0 'pin 7 Symbol Yellow2 = c.1 'pin 6 Symbol Green2 = c.2 'pin 5 Symbol Trigger1 = pinc.4 'pin 3 Symbol Trigger2 = pinc.3 'pin 4 Symbol Pot1 = pinb.1 'pin 12 Symbol Pot2 = pinb.3 'pin 10 sertxd (13,10,"Traffic Light Test - d. bodnar 4-17-2012") Initialize: for b1= 1 to 1 high Red1 pause 300 high Yellow1 pause 300 high Green1 pause 300 high Red2 pause 300 high Yellow2 pause 300 high Green2 pause 300 low Red1:low Yellow1:low Green1 low Red2:low Yellow2:low Green2 pause 1000 next b1 ButtonStillOn2: if Trigger1 = 0 then ButtonStillOn2: goto top: AllOff: low Red1:low Yellow1:low Green1 low Red2:low Yellow2:low Green2 return

  32. #12 - Emergency vehicle lights • Only uses 5 of 6 LEDs • Simple set of flashing lights, pairs and single in center

  33. #13 - Movie Marquee Lights • Uses all six LED outputs to drive 6, 12, 18, 24, etc LEDs • Lights a single LED (or set) at a time • Programs can create many different effects!

  34. #14 - Strobe light high led1 pause Dlay low led1 pause 100 high led1 pause Dlay low led1 pause 1000 high led2 pause Dlay low led2 pause 100 high led2 pause Dlay low led2 pause 400 high led2 pause Dlay low led2 pause 100 high led2 pause Dlay low led2 pause 1000 goto top: 'School Bus-top Strobe 'd. bodnar 3-28-13 ' looks best when used with very bright ' white LED driven by a 2n2222 #NO_DATA Symbol LED1 = c.2 Symbol LED2 = c.0 Symbol Dlay = 5 top: high led1 pause Dlay low led1 pause 100 high led1 pause Dlay low led1 pause 400

  35. High power LEDs • 2N2222 on boards will handle ½ amp for a short time • Replace with Mosfet or TIP101 for higher current LEDs or bulbs

  36. #15 – Small Motor Control • Bypass 470 ohm resistor (why?) • Too little current allowed with it to drive motor • Add diode (why?) • Back EMF will eventually kill the transistor

  37. Animation • By sending precisely timed pulses the PICAXE can set the servo’s arm to a specific position and hold it there.

  38. #16 - Servo Control Must add 3 pin cable (+5, ground, signal) 'd.bodnar 01-19-14 SYMBOL CCWMax = 240 SYMBOL CWMin = 60 SYMBOL Middle = 128 SYMBOL Cervo= b.2 ‘ Why not call it Servo – why use a misspelled word? SYMBOL CdS = b.4 'pin 9 Symbol Light = b4 servo Cervo,Middle ; initialize servo pin 8 sertxd ("this is a test of the servo unit on new Multi-LED board - LED1 pin",13,10) again: readadc CdS, Light for b2=CWMin to CCWMax servopos Cervo,b2 sertxd ("Servo ",#b2,13,10) pause 50 next b2 for b2=CCWMax to CWMin step -1 servopos Cervo,b2 sertxd ("Servo ",#b2,13,10) pause 50 next b2 GoTo Again:

  39. #16 - CDs Light Sensor • A Cadmium Sulfide Photocell can be attached directly to the trigger • Use to sense motion or to turn things on/off as ambient light changes • Also works with a phototransistor (more sensitive)

More Related