picaxe 2013 nmra jamboree dave bodnar april 27, 2013 unique electronic devices, animations and...

63
PICAXE PICAXE 2013 NMRA Jamboree 2013 NMRA Jamboree Dave Bodnar Dave Bodnar April 27, 2013 April 27, 2013 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 04-26-13

Upload: reynard-wilcox

Post on 17-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Slide 1Revised 04-26-13
Unique Electronic Devices, Animations and Controls That You Can Make Plus Gizmos, Gadgets, Tips & Tricks That You Can Use to Improve Your Railroad
Set up on table at start:
Mars light, light house & Morse code on foam – should run from one battery or power supply
PICAXE
PICAXE
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
PICAXE
PICAXE
Animation with a Single LED
Used in an introductory article in the current issue of Garden Railways Magazine
For more information on PICAXE see YouTube video links on
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
Show cables (mouse, USB & DB-9) #5 ok
PHANDERSON.COM has solderless development kit for around $20.00 (+/- depending on cable / psupply)
Show & pass around programming cable – can also be made from DB9 (from Hosfelt) and old computer wires – if Internet available go to PICAXE.com and/or PHAnderson.com
PICAXE
PICAXE
USB programming cable
Power source
Show cables (mouse, USB & DB-9) #5 ok
PHANDERSON.COM has solderless development kit for around $20.00 (+/- depending on cable / psupply)
Show & pass around programming cable – can also be made from DB9 (from Hosfelt) and old computer wires – if Internet available go to PICAXE.com and/or PHAnderson.com
PICAXE
PICAXE
Tip
– part # PGM-09260
Show cables (mouse, USB & DB-9) #5 ok
PHANDERSON.COM has solderless development kit for around $20.00 (+/- depending on cable / psupply)
Show & pass around programming cable – can also be made from DB9 (from Hosfelt) and old computer wires – if Internet available go to PICAXE.com and/or PHAnderson.com
PICAXE
PICAXE
Tip
Modern Devices sells a similar board for
about $14.00
Show cables (mouse, USB & DB-9) #5 ok
PHANDERSON.COM has solderless development kit for around $20.00 (+/- depending on cable / psupply)
Show & pass around programming cable – can also be made from DB9 (from Hosfelt) and old computer wires – if Internet available go to PICAXE.com and/or PHAnderson.com
PICAXE
PICAXE
pages 54-59
Contains a detailed introduction to the PICAXE and three single LED projects
PICAXE
PICAXE
PICAXE
Two resistors for programming
PICAXE
PICAXE
PICAXE
PICAXE
PICAXE
PICAXE
School Bus Strobe
Symbol Dlay = 12
Mars Light
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:
GOTO Start: 'repeat
ShortFlash: 'a label
For Loopie = 0 to 100 step 1 '100 steps from off to bright
brightness=255-loopie
pause Dlay
next loopie
for loopie = 100 to 0 step -1 'repeat above backwards
brightness=255-loopie
LongFlash: 'do the longer flash
For Loopie = 0 to 255 step 1 '255 steps from off to bright
brightness=255-loopie
for loopie = 255 to 0 step -1 'repeat above backwards
brightness=255-loopie
Morse Code Beacon
I found the code by searching Google for:
PICAXE Morse code
Lighthouse – more than just on & off!
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
sertxd ("pausing DONE")
PICAXE
PICAXE
You could usa a PICAXE but DON’T
It is much simpler & less expensive to use a flashing LED!
Search eBay for:
Fixed ½ second rate
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!
Detailed review of schematic – note pin 6 is “out1” and pin 5 is “out2” – note also that the 22k & 10K to ground are necessary on any board, programmable or not!
Reinforce using 5 volts or less – NOT 9 VOLT BATTERY! Define Ground! Some don’t know what it is.
PICAXE
PICAXE
Supports:
#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
PICAXE
PICAXE
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
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
Symbol PotValue = b2
Symbol Dlay =w3
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
PICAXE
PICAXE
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
PICAXE
PICAXE
Tip
Salvage 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
Tip
Item number 67488
10 for $2.99
Add switch & resistor to solderless proto board
Discuss need for 10K pull up resistor to give positive shift from + 5 to ground on button push & to protect against dead short if it were not there
PICAXE
PICAXE
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
‘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
Add switch & resistor to solderless proto board
Discuss need for 10K pull up resistor to give positive shift from + 5 to ground on button push & to protect against dead short if it were not there
PICAXE
PICAXE
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 1
Sensor 2
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
endif
Flash:
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
Symbol LED1 = b.2
Symbol LED2 = b.4
Symbol Trigger2 = pinc.3
Symbol Trigger1 = pinc.4
PICAXE
PICAXE
Using High Power LEDs and Bulbs
Adding a transistor switch to each output allows it to control much higher power devices
High output LEDs
high led1
pause Dlay
low led1
pause 70
next b1
pause Dlay2
high led2
pause Dlay
low led2
pause 70
next b1
pause Dlay2
goto top:
high led3
pause Dlay
low led3
high led5
pause Dlay
low led5
pause Dlay3
next b1
pause Dlay2
high led2
pause Dlay
low led2
pause Dlay3
high led4
pause Dlay
low led4
next b1
pause Dlay2
goto top:
Symbol Dlay = 8
Symbol Dlay2= 100
Symbol Dlay3= 50
high led1
pause Dlay
low led1
high led6
pause Dlay
low led6
pause Dlay3
next b1
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”
PICAXE
PICAXE
Animation
…surprises visitors
Servo demo board with power supply #14a (foam) #14b (spout)
PICAXE
PICAXE
Animation
Moving things is easy with the PICAXE as it knows how to talk to model airplane servos
PICAXE
PICAXE
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
PICAXE
PICAXE
Animation
By sending precisely timed pulses the PICAXE can set the servo’s arm to a specific position and hold it there.
PICAXE
PICAXE
Servos
Start:
sertxd (#temp," ")
sertxd (#temp," ")
Two for power and 1 for control pulses
The SERVO command is built into the PICAXE
PICAXE
PICAXE
Surprisingly high torque
http://www.suntekstore.com item # 14002627
Less than $6.00
Tip – Dubro Collars
Ideal for connecting to motor shafts & to join piano wire for servos
Approx 1” x ½” x ½”
Search eBay for:
$6.99 + $2.00 shipping
Pass connectors around
Use a 10 watt / 12 volt bulb as a load
Pass connectors around
Servo Recorder
For more complex servo movements the train recorder has been modified to operate one or two servos
Ideal for
One each on others
Only works when train is running and lights are down
Light sensor
Power sensor
Standard
Servos can easily uncouple cars
Uses a simple PICAXE controller and some type of radio control
RC can be Revolution receiver
Can be an inexpensive keychain transmitter & its small receiver
PICAXE
PICAXE
Train 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 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
It’s more fun to make it yourself than to buy it ready to go!
"I am always doing that which I cannot do, in order that I may learn how to do it."
Pablo Picasso
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
40% off coupon!)
Pass connectors around
Testing LEDs
Just about any LED can be tested with a 3 volt lithium battery 2032, 2025, etc
Touch the anode (longer
battery
to the - side