picaxe 2014 nmra convention dave bodnar july 17, 2014 unique electronic devices, animations and...
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
PICAXE PICAXE
Lighthouse Beacon – 4 LEDsLighthouse Beacon – 4 LEDs
PICAXE PICAXE
Lighthouse Beacon – Halogen BulbLighthouse Beacon – Halogen Bulb
PICAXE PICAXE
How does a pin that is normally either ON or OFF provide variable voltage?
Lighthouse BeaconLighthouse Beacon
Pulsed
Width Modulation
Something about this should be bothering you!
?10% power
50% power
90% power
PICAXE PICAXE
Lighthouse BeaconLighthouse Beacon
Program #6
symbol bulb = 2
symbol some = 110
start:
pwmout bulb,0,0
b2=1
for b1=255 to 0 step -b2
b2=b2+3
pause some
pwmout bulb,b1,b2
next b1
b2=1
pwmout bulb, 255,1022 :pause 140
for b1=1 to 255 step b2
b2=b2+3
pwmout bulb,b1,b2
pause some
next b1
pwmout bulb,0,0
pause 2000
goto start:
PICAXE PICAXE
Lighthouse BeaconLighthouse Beacon
• The transistor makes it possible to drive a very bright bulb
• Substitute a motor for the bulb and you can control a train’s DC motor!
• The size of motor is only limited by the size of the transistor
PICAXE PICAXE
Garden Railways Garden Railways PICAXE ArticlePICAXE Article
April 2013 Issuepages 54-59
Contains a detailed introduction to the PICAXE and three single LED projects
PICAXE PICAXE
The Projects All Use the Same The Projects All Use the Same HardwareHardware
• PICAXE 08M2 (order from PHanderson.com - $2.65 each)
• 4-5 volt battery
• One LED and one current limiting resistor
• Two resistors for programming
PICAXE PICAXE
Can be Built on a Solderless Can be Built on a Solderless Prototype BoardPrototype Board
PICAXE PICAXE
Proto Board & Power SupplyProto Board & Power Supply
• BangGood.com sells a wireless prototyping board with jumpers & a power supply for less than $6 delivered!
• Excellent for experimentation and design
PICAXE PICAXE
Or on a Custom BoardOr on a Custom Board
PICAXE PICAXE
Animation with a Single LEDAnimation with a Single LED
• School Bus StrobeSymbol LED1 = c.2 'pin 5Symbol 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:
PICAXE PICAXE
Animation with a Single LEDAnimation with a Single LED• 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
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
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
PICAXE PICAXE
Tip - AdhesiveTip - Adhesive
Great for quick temporary or permanent connections– Similar to the “goo” on the
back of a new credit card– I use it in place of hot melt
glue– DOTS brand– Michaels (don’t forget the
40% off coupon!)
PICAXE PICAXE
Tip - ConnectorsTip - Connectors
We are always looking for ways to connect electrical devices together– Low voltage:– Deal Extreme
item # 15234– DX.com– $2.87 for 10
pair includingshipping!
PICAXE PICAXE
Tip – Heat Shrink TubingTip – Heat Shrink Tubing• Excellent for insulating joints & making
repairs• Soldering wires first is recommended but
not mandatory• Available in many colors – great trick for
identifying wires• Available in many diameters, too• Fry’s has an excellent supply, BangGood,
too!
PICAXE PICAXE
Animation with a Single LEDAnimation with a Single LED
• Fred (Flashing Rear End Device)
• You could use a PICAXE but DON’T
• It is much simpler & less expensive to use a flashing LED!
• Search eBay for:
flashing led 3mm red diffused
PICAXE PICAXE
Tip - Testing LEDsTip - Testing LEDs
• Just about any LED can be tested with a 3 volt lithium battery 2032, 2025, etc
• Touch the anode (longer wire) to the + side of the battery
• Touch the cathode
(wire by notch in LED)
to the - side
White LEDs are OK for long use at 3+ volts, Red, Green, Amber are not
PICAXE PICAXE
Garden Railways Garden Railways PICAXE Article 2PICAXE Article 2
August 2014 Issuepages 44-47
Multiple LED projects
PICAXE PICAXE
Animation with Multiple LEDsAnimation with Multiple LEDs
• Crossing Signal with 2 LEDs
• The LEDs flash “back & forth”
• Starts when power is applied
• Fixed ½ second rate
PICAXE PICAXE
Custom Circuit Board for up to 6 LEDsCustom 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
PICAXE PICAXE
Crossing Signal with Variable RateCrossing 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
PICAXE PICAXE
Crossing Signal with Variable RateCrossing 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
PICAXE PICAXE
Crossing Signal with Variable RateCrossing 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
The pause time between flashes is based on Pot reading
PICAXE PICAXE
Emergency vehicle lightsEmergency vehicle lights
• Only uses 5 of 6 LEDs• Simple set of flashing lights, pairs and single in
center
PICAXE PICAXE
WelderWelder
• Two LEDssimulate awelder
SETFREQ m32 'speed it up to 32 MHz
Symbol LED1 = c.1 ' var GPIO.2 'pin 6 WHITE
Symbol LED2 = c.2 ' var GPIO.1 'pin 5 BLUE
Symbol MinNumber =b1
Symbol RNDRange =b2
Symbol RNDResult =w8
Symbol RndNum =w7
Symbol Divisor =w6
Symbol Temp0 =w9
Symbol Temp1 =w10
top:
gosub getrndinrange
Temp0=rndresult/2:temp1=rndresult/12
pwmout c.2, temp0, Temp1'loopie 'use PWM to brighten the LED
gosub getrndinrange:
pwm c.1, rndresult, 50
Temp0=rndresult/7
pause temp0 'rndresult /7
goto top
GetRndInRange:
RndRange =120 'random range --- gives a range from 12 to 62
MinNumber =1 'min number
Random RndNum
Divisor = 65535 / RndRange
rndResult= RndNum / Divisor
rndresult = rndresult + MinNumber
return
PICAXE PICAXE
Six LEDs Can Make a Traffic LightSix 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”
PICAXE PICAXE
PICAXE Train ControllerPICAXE Train Controller
• Model Railroad Hobbyist magazine– June 2014– Free Subscription
http://model-railroad-hobbyist.com/
PICAXE PICAXE
Speed ControllerSpeed Controller• The PICAXE-based controller operates a
simple layout using the IR remote control to vary track power
• It can be used as a basic speed / direction controller
• …or it can be programmed to change direction based on time (easy point-to-point controller!)
PICAXE PICAXE
PICAXE Train RecorderPICAXE Train Recorder
• Model Railroad Hobbyist magazine– July 2014
Part 2
PICAXE PICAXE
Train RecorderTrain Recorder• The newest version automatically records
(at a rate of 50 recordings per second) a train’s movements so that you can play them back over & over
• A rather unusual but very cool thing to do!
• Makes station-stops and complex routes a snap!
PICAXE PICAXE
Train RecorderTrain Recorder
• Additional Components:– A memory chip to store activity (can store up
to 20 minutes of train movements!)– A potentiometer to control speed & direction– Optional: A relay to control a “stop block” that
keeps things in “sync”
PICAXE PICAXE
Latest ProjectLatest Project
• Train detection (for signals, etc)
• Uses a self-contained infrared sensor
• SuntekStore.com - search for "IR sensor switch" < $6.00 each
PICAXE PICAXE
AnimationAnimation
…can take many forms
…can add interest and variety to your layout
…surprises visitors
…is great fun!
PICAXE PICAXE
AnimationAnimation• Moving things is easy with the PICAXE as
it knows how to talk to model airplane servos
PICAXE PICAXE
ServosServos
• 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
PICAXE PICAXE
AnimationAnimation• By sending precisely timed pulses the
PICAXE can set the servo’s arm to a specific position and hold it there.
PICAXE PICAXE
ServosServos
The PICAXE can talk directly to a servo
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:
PICAXE PICAXE
AnimationAnimation• Only three wires go to the servo
– Two for power and 1 for control pulses– The SERVO command is built into the
PICAXE
PICAXE PICAXE
Tip – Tiny MotorTip – 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
PICAXE PICAXE
Tip – Tiny MotorTip – Tiny Motor• Different gear ratios available from
– www.banggood.com – Search for N20 DC Gear Motor– 3v-12v– 40-160 rpm– $4.55
PICAXE PICAXE
Tip – Dubro CollarsTip – Dubro Collars
• Ideal for connecting to motor shafts & to join piano wire for servos
• http://shop.dubro.com/c/aircraft_collars
• Easy to solder to brass control arms
PICAXE PICAXE
Tip – Tiny Volt MeterTip – 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”
• <$4.00 including shipping
PICAXE PICAXE
Tip – Step Down Voltage ConverterTip – Step Down Voltage Converter
• Suntekstore.com • < $5 shipped – some times on sale for less• http://www.suntekstore.com
search for DC-DC voltmeter
• Up to 2 amps without heat sink• Includes digital meter!• Adjust voltage with
screwdriver
PICAXE PICAXE
Servo ExamplesServo Examples
• Elephant
PICAXE PICAXE
Servo ExamplesServo Examples
• Outhouse
PICAXE PICAXE
Servo ExamplesServo Examples
• Water Spout
PICAXE PICAXE
Servo ExamplesServo Examples• Prairie Dogs
PICAXE PICAXE
Servo ExamplesServo Examples
• Scanning Spotlight
• Uses brightLED
• And twoServos
PICAXE PICAXE
Servo ExamplesServo Examples
• Eggliner– eyes blink– and move
PICAXE PICAXE
Servo ExamplesServo Examples• Children’s Hospital Searchlight
– 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
Remember:
PICAXE PICAXE
Your Ideas?Your Ideas?
• Questions?
PICAXE PICAXE