1 / 63

2013 NMRA Jamboree

2013 NMRA Jamboree. Dave Bodnar April 27, 2013. This presentation is available on-line at: www.trainelectronics.com or www.davebodnar.com. Revised 04-26-13. Introduction. This is my fourth Jamboree presentation Our focus today is on animation, especially using light and movement

Télécharger la présentation

2013 NMRA Jamboree

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. 2013 NMRA Jamboree Dave Bodnar April 27, 2013 This presentation isavailable on-line at:www.trainelectronics.com or www.davebodnar.com Revised 04-26-13

  2. Introduction • This is my fourth Jamboree presentation • Our focus today is on animation, especially using light and movement • Most projects are operated by PICAXE microcontrollers, a device that we have covered in each of the other talks

  3. PICAXE - What Is It? • A small microcontroller (is that redundant?) that can be programmed to do many tasks • An device that is so inexpensive that it can be dedicated to a single task • A device that is programmed from a PC with free software • A device that is programmed in the BASIC programming language

  4. PICAXE - What You Need • Computer with serial port or … USB to serial adapter or … USB programming cable • Windows computer running free PICAXE software (Mac & Linux, too) • Power source • 3 @ AA cells = 4.5 volts

  5. Tip USB to Serial Adapter Spark Fun sells PICAXE cable – part # PGM-08312 for about $26.00 Or Spark Fun’s USB to Serial – part # PGM-09260for about $15.00 Details on use at www.trainelectronics.com

  6. Tip USB to Serial Adapter #2 Modern Devices sells a similar board for about $14.00 Details on use at www.trainelectronics.com

  7. Garden Railways PICAXE Article April 2013 Issuepages 54-59 Contains a detailed introduction to the PICAXE and three single LED projects

  8. The Projects All Use the Same Hardware • PICAXE • 4-5 volt battery • One LED and one current limiting resistor • Two resistors for programming

  9. Can be Built on a Solderless Prototype Board

  10. On a Drilled Prototype Board

  11. Or on a Custom Board

  12. Animation with a Single LED Symbol LED1 = c.2'pin 5 Symbol Dlay = 12 top: high led1 pause Dlay low led1 pause 100 high led1 pause Dlay low led1 pause 400 high led1 pause Dlay low led1 pause 100 high led1 pause Dlay low led1 pause 1000 goto top: • School Bus Strobe

  13. Animation with a Single LED ShortFlash: 'a label For Loopie = 0 to 100 step 1 '100 steps from off to bright brightness=255-loopie pwmout c.2, brightness, loopie 'light the LED pause Dlay next loopie for loopie = 100 to 0 step -1 'repeat above backwards brightness=255-loopie pwmout c.2, brightness,loopie sertxd (#loopie, " ") pause Dlay next loopie return • Mars Light #NO_DATA 'speeds up programming #PICAXE 08M2 'identify the chip SETFREQ m32 'speed it up to 32 MHz SYMBOL Loopie = b2 'label variable b2 as Loopie SYMBOL Brightness = b1 'label b1 as Brightness SYMBOL Dlay = 2 'set constant Dlay to 2 Start: Gosub ShortFlash 'do the shorter flash routine Gosub LongFlash 'do the longer flash routine GOTO Start: 'repeat LongFlash: 'do the longer flash For Loopie = 0 to 255 step 1 '255 steps from off to bright brightness=255-loopie pwmout c.2, brightness, loopie pause Dlay next loopie for loopie = 255 to 0 step -1 'repeat above backwards brightness=255-loopie pwmout c.2, brightness,loopie pause Dlay next loopie return

  14. Animation with a Single LED • Morse Code Beacon • 137 lines of code • Takes up about ½ of the 08M2’s memory! • I found the code by searching Google for: PICAXE Morse code

  15. Animation with a Single LED SETFREQ m32 'speed it up to 32 MHz (8x normal) SYMBOL Loopie = b2 'label variable b2 as Loopie SYMBOL Brightness = b1 'label b1 as Brightness SYMBOL Dlay = 150 'set constant Dlay to 150 Start: For Loopie = 0 to 100 step 1 '100 steps from off to bright brightness=255-loopie pwmout c.2, brightness, loopie 'use PWM to brighten the LED pause Dlay 'pause a bit next loopie 'get the next item in for/next pwmout c.2, 255,1023:pause 1000 'flash to full bright briefly for loopie = 100 to 0 step -1 'repeat above backwards brightness=255-loopie pwmout c.2, brightness,loopie pause Dlay next loopie sertxd ("pausing") pwmout c.2,255,0 low c.2 pause 65000 'pause a bit with LED off sertxd ("pausing DONE") goto start 'do it again! • Lighthouse – more than just on & off!

  16. Animation with a Single LED • Fred (Flashing Rear End Device) • You could usa a PICAXE but DON’T • It is much simpler & less expensive to use a flashing LED! • Search eBay for: flashing LED

  17. Animation with Multiple LEDs • Crossing Signal with 2 LEDs • The LEDs flash “back & forth” • Starts when power is applied • Fixed ½ second rate

  18. Flashing Crossing Lights • We will use the 14 pin PICAXE 14M2 • Same as 08M but with more input and output pins • About $1.00 more than the 08M Remember: Don’t use a 9 volt battery or 4 fresh 1.5 volt AA cells! 5.5 volts maximum!

  19. Flashing Crossing Lights

  20. Custom Circuit Board for up to 6 LEDs • A custom multi-LED board was designed and fabricated • Supports: • up to 6 LEDs • two trigger switches • two potentiometers • option for power transistors for each LED

  21. Crossing Signal Software #NO_DATA 'speeds up programming a bit #TERMINAL 4800 ' open terminal at speed 4800 baud after programming Symbol LED1 = b.2 'pin 11 Symbol LED2 = b.4 'pin 9 sertxd (13,10,"Simple Crossing Signal - d. bodnar 4-16-2012") ' show name on terminal Initialize: ' do this only once High LED1 ' LED1 is ON Low LED2 ' LED2 is OFF Start: ' LABEL so the GOTO knows where to go! 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 (500/1000ths) goto start: ' go back to Start and do it again

  22. Crossing Signal with Variable Rate • A Potentiometer can be read by the PICAXE • Its setting can be used to change the speed of flashing or how long it flashes or any other variable that changes its behavior

  23. Crossing Signal with Variable Rate • When the pot is rotated to one extreme the wiper on the pot shows 5 volts • At the other extreme it is 0 volts • With proportional voltages in between • This translates to a value between 0-255 in the PICAXE with the READADC command

  24. Crossing Signal with Variable Rate Symbol LED1 = b.2 'pin 11 Symbol LED2 = b.4 'pin 9 Symbol Pot1 = pinb.1 'pin 12 Symbol PotValue = b2 Symbol Dlay =w3 sertxd (13,10,"Simple Crossing Signal - d. bodnar 4-16-2012") Initialize: ' do this only once High LED1 ' LED1 is ON Low LED2 ' LED2 is OFF Start: ' LABEL so the GOTO knows where to go! readadc b.1, PotValue sertxd ("pot=",#PotValue,13,10) Toggle LED1 ' if LED1 is on turn it off, if off turn on Toggle LED2 ' same for LED2 Dlay=PotValue*2 ‘double the pot reading pause Dlay' pause based on pot reading goto start: ' go back to Start and do it again Pause between flashes is based on Pot reading

  25. Crossing Signal with Trigger • To be really useful a crossing signal needs to be started by a switch of some sort • This can be a pushbutton or a reed switch and magnet

  26. TipSalvage Magnets from old Hard Drives • Virtually all computer hard drives have strong (rare earth) magnets in them • Remove case & carefully remove platters and other parts that are in the way • Caution: some platters are GLASS! Fragile and easily converted to SHARP pieces!

  27. Tip • Harbor Freight sells small rare earth magnets • Item number 67488 • 10 for $2.99

  28. Flashing Crossing Lights Hardware modification for button or reed switch activation:

  29. Flashing Crossing Lights Software modification for button: ‘ORIGINAL CROSSING PROGRAM – CONTINUOUS BLINKING Symbol LED1 = b.2 'pin 11 Symbol LED2 = b.4 'pin 9 Initialize: ' do this only once High LED1 ' LED1 is ON Low LED2 ' LED2 is OFF Start: ' LABEL so the GOTO knows where to go! 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 (500/1000ths) goto start: ' go back to Start and do it again Symbol LED1 = b.2 'pin 11 Symbol LED2 = b.4 'pin 9 Symbol Trigger1 = pinc.3 'pin 4 StayHere: if Trigger1 = 1 then StayHere: Initialize: ' Set up LEDs for flashing High LED1 ' LED1 is ON Low LED2 ' LED2 is OFF For B1 = 1 to 30 'repeat things between here and Next B1 30 times (each cycle takes 1/2 second) 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 (500/1000ths) Next B1 'go back and get the next B1 until it equals 30 Low LED1 'turn LED1 off Low LED2 'turn LED2 off goto StayHere: ' go back to Initialize and do it again

  30. Two Buttons for Crossing • Add a second reed switch so that the light goes on when it passes one switch… …and goes off when it hits the other. Sensor 2 Sensor 1

  31. Two Buttons for Crossing CheckButtons: b1=0:b2=0 ‘zero variables that store which button came first if Trigger1 = 1 and Trigger2 = 1 then CheckButtons ' no hit if Trigger1 = 0 then b1=1 'save which button hit first goto flash 'skip ahead and start blinking endif b2=1 'save which button hit first Flash: high LED1 'LED 1 on low LED2 'LED 2 off 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 toggle LED1:toggle LED2 ‘switch lights goto FlashAgain: 'continue checking buttons Software mustrememberwhich switch is hit first Symbol LED1 = b.2 Symbol LED2 = b.4 Symbol Trigger2 = pinc.3 Symbol Trigger1 = pinc.4 PauseBeforeStart: low LED1 low LED2 pause 1000

  32. Using High Power LEDs and Bulbs • Adding a transistor switch to each output allows it to control much higher power devices • High output LEDs • Incandescent bulbs • Motors

  33. Emergency Light Flashers Symbol LED1 = c.2 Symbol LED2 = c.0 Symbol Dlay = 4 Symbol Dlay2= 100 top: for b1=1 to 5 high led1 pause Dlay low led1 pause 70 next b1 pause Dlay2 for b1=1 to 5 high led2 pause Dlay low led2 pause 70 next b1 pause Dlay2 goto top: Red / Blue / White on police car Two LED version

  34. Emergency Light Flashers pause Dlay2 for b1=1 to 5 high led3 pause Dlay low led3 high led5 pause Dlay low led5 pause Dlay3 next b1 pause Dlay2 for b1=1 to 5 high led2 pause Dlay low led2 pause Dlay3 high led4 pause Dlay low led4 next b1 pause Dlay2 goto top: Or six LED version Symbol LED1 = b.2 'pin 11 Symbol LED2 = b.4 'pin 9 Symbol LED3 = b.5 'pin 8 Symbol LED4 = c.0 'pin 7 Symbol LED5 = c.1 'pin 6 Symbol LED6 = c.2 'pin 5 Symbol Dlay = 8 Symbol Dlay2= 100 Symbol Dlay3= 50 top: for b1=1 to 5 high led1 pause Dlay low led1 high led6 pause Dlay low led6 pause Dlay3 next b1

  35. Six LEDs Can Make a Traffic Light • A pair of traffic lights can be controlled with the six LED circuit board • Each light can be addressed individually • The two triggers can be used cycle the lights • The pots can be used to vary cycle time or “yellow on time”

  36. Animation …can take many forms …can add interest and variety to your layout …surprises visitors …is great fun!

  37. Animation • Moving things is easy with the PICAXE as it knows how to talk to model airplane servos

  38. Servos • A servo is made up of a small motor and set of gears • A string of control pulses precisely position the servo’s arm • They are commonly used to operate control surfaces on model planes, boats and cars

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

  40. Servos SYMBOL Temp = b0 SYMBOL ServoPin = c.2 ‘pin 5 Start: FOR Temp = 225 TO 75 Step -1 sertxd (#temp," ") SERVO ServoPin, Temp PAUSE 15 NEXT Temp sertxd (13,10) FOR Temp=75 TO 225 Step 1 sertxd (#temp," ") SERVO ServoPin, Temp PAUSE 15 NEXT Temp sertxd (13,10) GOTO Start: The PICAXE can talk directly to a servo

  41. Animation • Only three wires go to the servo • Two for power and 1 for control pulses • The SERVO command is built into the PICAXE

  42. Tip – Tiny Motor • Gear head motor a bit larger than a penny • Surprisingly high torque • http://www.suntekstore.com item # 14002627 • Less than $6.00 shipped • Ideal for many animations

  43. Tip – Dubro Collars • Ideal for connecting to motor shafts & to join piano wire for servos • http://shop.dubro.com/c/aircraft_collars

  44. Tip – Tiny Volt Meter • Powered from voltage being measured – 4 to 30 volts • Approx 1” x ½” x ½” • Search eBay for:“Ultra Mini size LED Volt Meter” • $6.99 + $2.00 shipping

  45. Tip – Tiny Volt Meter • Makes a nice track voltage tester • Use a 10 watt / 12 volt bulb as a load

  46. Servo Examples • Elephant

  47. Servo Examples • Outhouse

  48. Servo Examples • Water Spout

  49. Servo Examples • Prairie Dogs

  50. Servo Recorder • For more complex servo movements the train recorder has been modified to operate one or two servos • Ideal for • dual axis searchlight • dual servo bear animation

More Related