PICAXE PICAXE 2014 NMRA Convention 2014 NMRA Convention Dave Bodnar Dave Bodnar July 17, 2014 July 17, 2014 Unique Electronic Devices, Animations and Controls That You Can Make Plus Gizmos, Gadgets, Tips & Tricks That You Can Use to Improve Your Railroad This presentation is available on-line at: www.trainelectronics.c om or www.davebodnar.com Revised 07-17-14
2014 NMRA Convention. Dave Bodnar July 17, 2014. This presentation is available on-line at: www.trainelectronics.com or www.davebodnar.com. Revised 07-17-14. PICAXE - What Is It?. A small microcontroller (is that redundant?) that can be programmed to do many tasks - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
PICAXE PICAXE
2014 NMRA Convention2014 NMRA Convention
Dave BodnarDave Bodnar
July 17, 2014July 17, 2014
Unique Electronic Devices, Animations and Controls That You Can Make
Plus Gizmos, Gadgets, Tips & Tricks That You Can Use to Improve Your Railroad
This presentation isavailable on-line at:
www.trainelectronics.com or www.davebodnar.com
Revised 07-17-14
PICAXE PICAXE
PICAXE - What Is It?PICAXE - What Is It?1. A small microcontroller (is that redundant?) that can
be programmed to do many tasks
2. A device that is so inexpensive that it can be dedicated to a single task
3. A device that is programmed from a PC with free software
4. A device that is programmed in the BASIC programming language (great for beginners!)
PICAXE PICAXE
PICAXE - What You NeedPICAXE - What You Need1. Computer with
serial port or …USB to serial adapter or …USB programming cable
2. Windows computer running free PICAXE software (Mac & Linux versions available, too)
3. Power source– 3 @ AA cells = 4.5 volts– 4 @ NiCads = 4.8 volts– 5 volt power supply (from retired cell phone)
PICAXE PICAXE
ProgrammersProgrammers
USB to Serial Adapter
SparkFun.com sells PICAXE cable – part # PGM-08312 for about $26.00
Or
Spark Fun’s USB to Serial – part # PGM-09260 for about $15.00
Details on use at www.trainelectronics.com
PICAXE PICAXE
Flashing Crossing LightsFlashing Crossing Lights
Remember: Don’t use a 9 volt battery or 4 fresh 1.5 volt AA cells!
5.5 volts maximum!
PICAXE PICAXE
Flashing Crossing LightsFlashing Crossing Lights
Radio Shack # 276-002 $15.00
PICAXE PICAXE
Flashing Crossing LightsFlashing Crossing Lights
PICAXE PICAXE
““Dead Bug” StyleDead Bug” Style
• Built on an 8 pin socket
• Can be doneto match theschematic
PICAXE PICAXE
Tip - SolderingTip - Soldering• A good iron makes
you a better solderer!– MPJA.com
– Item #ZD 929C – $46.95– Digital temperature readout
PICAXE PICAXE
Tip SolderingTip Soldering• A clean tip makes all the difference.
• MPJA.comitem # 31241 TL $2.95
PICAXE PICAXE
Flashing Crossing LightsFlashing Crossing Lights
Program 1:
Notes:– “start” is just a label telling the “goto” where to go– the program remains in the chip’s memory until it is
manually erased or overwritten.
high 1 ‘turn on LED 1 - pin out1low 2 ‘turn off LED 2 - pin out2
start: pause 500 ‘wait ½ second toggle 1 ‘switch LED 1 on pin out1 toggle 2 ‘switch LED 2 on pin out2goto start: ‘do it again
PICAXE PICAXE
Flashing Crossing LightsFlashing Crossing LightsProgram 2: modified to flash for 10 seconds and turn
off for 10
seconds
start:high 1 ‘turn on LED 1low 2 ‘turn off LED 2
For b0=1 to 20 ‘repeat 20 times pause 500 ‘wait ½ second toggle 1 ‘switch LED 1 toggle 2 ‘switch LED 2next b0 ‘back to looplow 1 ‘turn LED 1 offlow 2 ‘turn LED 2 offpause 10000 ‘stay here 10 secondsgoto start: ‘do it again
PICAXE PICAXE
Flashing Crossing LightsFlashing Crossing Lights
• Program simulation is built in!
PICAXE PICAXE
Flashing Crossing LightsFlashing Crossing LightsHardware modification for button or reed switch
activation:
PICAXE PICAXE
TipTipSalvage Magnets from old Hard DrivesSalvage 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!
PICAXE PICAXE
Flashing Crossing LightsFlashing Crossing LightsProgram 3: modified to flash 5 seconds on each
button push start:low 1 ‘turn off LED 1low 2 ‘turn off LED 2if pin3 = 1 then start: ‘if switch off go to top
flash: high 1 ‘LED 1 on low 2 ‘LED 2 offfor b0= 1 to 10 ‘do this 10 times pause 500 ‘wait ½ second toggle 1:toggle 2 ‘switch lights next b0 ‘do next of 10 loopsgoto start: ‘start from very top
PICAXE PICAXE
Two Sensors for CrossingTwo Sensors for Crossing• Add a second sensor so that the light goes
on when it passes one sensor…
…and goes off when it hits the other sensor.
Sensor 1 Sensor 2
PICAXE PICAXE
Two Sensors for CrossingTwo Sensors for Crossing
Program 4:
PauseBeforeStart: 'prevents detecting slow button pushlow 1 ‘turn off LED 1low 2 ‘turn off LED 2pause 1000 'pause 1 secondCheckButtons:b1=0:b2=0if pin3 = 1 and pin4 = 1 then CheckButtonsif pin3=0 then b1=1 ‘save which button hit first goto flashendif b2=1 ‘save which button hit firstFlash: high 1 ‘LED 1 on low 2 ‘LED 2 offFlashAgain: for w3= 1 to 250 'check for button before changing lights if b2=1 and pin3=0 then PauseBeforeStart if b1=1 and pin4=0 then PauseBeforeStart next w3 toggle 1:toggle 2 ‘switch lights goto FlashAgain: 'continue checking buttons
PICAXE PICAXE
Flashing Crossing Lights on Steroids!Flashing Crossing Lights on Steroids!
Program 5:
Symbol Tone = 100 'sets the tone frequency ( range 20 -127 )Symbol Quiet = 0 'set quiet toneSymbol Dit_length = 7 'set length of a dot (7 milliseconds)- yields 10wpmSymbol Dah_length = 21 'set length of a dash (21 mS = 3 dots long)Symbol Wrd_Length = 86 'set space between words (43 mS = 2 dashes, 6 dots)Symbol Character = b0 'set register for ch.Symbol Index1 = b6 'loaded with number of chs. in messageSymbol Index2 = b2 'counts the number of elementsSymbol Elements = b4 'set register for number of elements in ch.
Start:Identify: ' routine to lookup ch.& put its value into the ch. register for Index1 = 0 to 29 'cycle through lookup for times = number of ch. in messagelookup Index1,(0,1,0,1,0,0,100,0,2,0,129,0,129,0,3,0,132,0,35,0,67,0,195,0,4,0,0,1,0,1),Charactergosub Morse 'go to the ch. generation routine next 'loop back to get next ch. and load it goto Start 'return to start to wait for next input
Morse:let Elements = Character & %00000111 'look at 3 LS digits and load into Elements registerif Elements = 0 then Word_sp ' % means binary
Bang_Key: for Index2 = 1 to elements 'loop through correct no. of times for number of elements if Character >= 128 then Dah 'test MS digit of ch. If it is 1 goto the Dah sub routinegoto Dit 'if it is 0 goto the Dit sub routine
Reenter: let Character = Character * 2 'do a left shift on all the bits in ch. next 'loop back to get the next element gosub Char_sp 'go to sub routine to put in inter-ch. spacereturn 'return to Identify routine to get next ch. to send
Dit:sound 2,(Tone,Dit_Length) 'sound tone for dit length sound 2,(Quiet,Dit_Length) 'silence for dit lengthgoto Reenter 'return to look at next element of ch.
Dah:sound 2,(Tone,Dah_Length) 'sound tone for dah length sound 2,(Quiet,Dit_Length) 'silence for dit lengthgoto Reenter 'return to look at next element of ch.
Char_sp: sound 2,(Quiet,Dah_Length) 'send silence for dah length after ch.completely sentreturn 'return to get next character
Word_sp: sound 2,(Quiet,wrd_length) 'send silence for break between wordsreturn 'return to get next ch.
PICAXE PICAXE
Lighthouse or Airport BeaconLighthouse or Airport Beacon
• Design objectives– Gradually brighten a bulb or LED to near full
brightness– Momentarily flash to full brightness– Gradually dim until off– Delay for a set time– Repeat – Able to use LEDs or incandescent bulbs
PICAXE PICAXE
Lighthouse BeaconLighthouse Beacon
PICAXE PICAXE
Lighthouse BeaconLighthouse Beacon
• Parts– Adds one resistor and one transistor to the
original flasher circuit so that the PICAXE can control a higher power bulb or LED
– The most significant changes are to the software
– Rotates back & forth via servo– Only works when train is running and lights
are down• Light sensor• Power sensor
PICAXE PICAXE
Servos Come in Many SizesServos Come in Many Sizes
• Standard
• 9 gram
• 4.3 gram
• 1.5 gram
PICAXE PICAXE
It’s more fun to make it yourself than to buy it ready to go!
"I am always doing that which I "I am always doing that which I cannot do, in order that I may cannot do, in order that I may learn how to do it."learn how to do it."Pablo PicassoPablo Picasso