PICAXEPIC 1 1 2014 Amherst Railroad Hobby Show Dave Bodnar January 24, 2014 Amherst, MA PICAXE Workshop Enhancing your Railroad with Microcontrollers This.

Slides:



Advertisements
Similar presentations
Sensing and Control.
Advertisements

JED Microprocessors Pty Ltd Presenting the JED T430 low-cost Projector Controllers Nov 22nd, 2009.
Microprocessor Motor Control Spring Introduction  Stamp projects Robots  Sensors  Motor control  Logic Rocketry  Reading acceleration (“g”
PIC Programming with Logicator
Fair Use Building and Research Labs Presents
MICROCONTROLLERS MODULE 2 Programming, Controlling and Monitoring.
Basic Stamp II is kinda cool Bytes of EEPROM(non-volatile) - Clock speed of 20 MHz. - Holds 600 lines of code in EEPROM - executes an average of.
New Human Computer Interfaces Amnon Dekel HUJI – CSE, Spring 2007 Class 3 March
Old control system ( ) MVRT. Main Circuit Breaker Connected to the red wire (power) of the battery When turned off, all power is cut off and robot.
Digital I/O Connecting to the Outside World
Introduction.
Lecture – 7 Basic input and output
Pulse Width Modulation (PWM) LED Dimmer Circuit
Introduction to Arduino Prepared by R. Lamond.  “Arduino is an open-source electronics prototyping platform based on flexible, easy- to-use hardware.
Fischertechnik ® Interface Connections. The Serial Interface Connects the Computer with the fischertechnik ® model
Embedded Programming and Robotics
Electrical Electricity Fuses Relays Solenoids Electrical Testing
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
RM2C Understanding Connections on the Robot Control Board (RCB).
Dean Brock, Rebecca Bruce and Susan Reiser, CCSC SE 2009 Using Arduino Material taken from Todbot blog Bionic Arduino Todbot blog Bionic ArduinoTodbot.
BASIC Stamp Editor Once installed, the Stamp Editor will be available on your desktop, and as a menu option under Start  Program Files  Parallax Inc.
Objectives How Microcontroller works
2015 East Coast Large Scale Train Show
1 Applied Control Systems Technology. 2 Pin configuration Applied Control Systems.
Segway Controller Notes. = connection on top layer of circuit board = connection on bottom layer of circuit board Ground Plane: Areas enclosed by the.
Controlling the Outside World
Programming the CheapBot-14. Start the Editor Set the Mode.
JMC – Joint Motion Controller Complete guide to building and testing each JMC.
10/10/ Controlling YOUR ROBOT. 10/10/2015 Basic Stamp  Basic Stamp Input - output pins Interpreter Chip Power supply: 5 Volts voltage Memory: EEPROM.
Tweaking Your Simon Adding a photoresistor and changing code Instruction by Pete Lewis and Linz Craig.
Overview What is Arduino? What is it used for? How to get started Demonstration Questions are welcome at any time.
2014 NMRA Convention Dave Bodnar July 17, 2014
2014 Amherst Railroad Hobby Show
CSC522 Embedded Systems Introduction to Circuit Design.
2013 NMRA Jamboree Dave Bodnar April 27, 2013
Automatic accident avoiding system PROJECT MEMBERS MUTHUKUMAR.K (05ME33) SAKTHIDHASAN.S (05ME39) SAKTHIVEL.N (05ME40) VINOTH.S (05ME56) PROJECT GUIDE:
Slide Menlo Drive Suite 100 Rocklin, CA
Basic Stamp OEM module By Wilmer Arellano. 2  The BASIC Stamp 2 OEM is a discreet component version of the BS2 which may be purchased in kit form. 
INTERNET OF EVERYTHING SDU 2016 Week 4. Simple Digital and Analog Inputs  The Arduino’s ability to sense digital and analog inputs allows it to respond.
PICAXEPIC National Garden Railway Convention Dave Bodnar June 6, 2013 Cincinnati, OH Electronics, Microcontrollers & Trains Electronic Gizmos,
An introduction to PIC’s for KS3 and KS4. Mr Rooks Hetton School.
Mechanical Components and Programming Ken Youssefi Introduction to Engineering – E10 1.
FlowArm PLTW Programming
Class Parts List Breadboard 1 Wire kit 1 Red LEDs 3 Green LEDs 3 Yellow LEDs 1 Photoresistor 1 xPiezo sensor 1 Button 3 Slide button, switch 1 Reed switch.
Having fun with code, using Arduino in a middle school CS classroom
ARDUINO BASED UNDERGROUND CABLE FAULT DETECTION
PICAXE Microcontroller
Prototyping with Microcontrollers and Sensors
Microprocessors Tutorial 1: Arduino Basics
An Arduino Workshop A Microcontroller.
Microcontroller Applications
Arduino Development for Beginners
Introduction to Handshaking Communication with SSC-32U
Fair Use Building and Research Labs Presents
Arduino - Introduction
Programming Scratch to Control a K’NEX Fairground Ride
FlowArm PLTW Programming
Administrative stuff Turn in your HW #3!
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
Interface Connections
Programming Boe-Bots (Part 1)
How to avoid catching things on fire.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Welcome to Digital Electronics using the Arduino Board
Controlling YOUR ROBOT
Basic Electronics Part Two: Electronic Components.
Fair Use Building and Research Labs Presents
Lab #1: Getting Started.
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
2019 Investing Now Summer Program
Presentation transcript:

PICAXEPIC Amherst Railroad Hobby Show Dave Bodnar January 24, 2014 Amherst, MA PICAXE Workshop Enhancing your Railroad with Microcontrollers This presentation is available on-line at: or Revised

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

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

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

PICAXEPIC 5 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

PICAXEPIC 6 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.

PICAXEPIC 7 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

PICAXEPIC 8 8 Software – what we need PICAXE software from Includes editor, simulator and programming software Manuals available under Help

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

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

PICAXEPIC 11 Other Components Transistors Resistors Potentiometers LEDs

PICAXEPIC 12 Circuit Board Components: –up to 6 LEDs –2 trigger switches –2 potentiometers –6 power transistors –5 volt regulator

PICAXEPIC 13 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

PICAXEPIC 14 Manuals There are three manuals that are accessible from the programming environment Click Help to show them

PICAXEPIC 15 Install 1 LED Plug one red/black lead to the pins labeled as LED1 Red wire to +

PICAXEPIC 16 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 ") 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?

PICAXEPIC 17 Simulation is Built In!

PICAXEPIC 18 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 ") 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?

PICAXEPIC 19 Add Potentiometer for speed and timing Examine schematic for potentiometer and discuss wiring and use Discuss code that used ReadADC command to get pot value and set speed Modify code to use 2nd pot to determine time of flashing after trigger Discuss different trigger methods (push button, reed switch, small RC unit)

PICAXEPIC 20 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 ") 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?

PICAXEPIC 21 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

PICAXEPIC 22 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 ") 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

PICAXEPIC 23 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 ",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

PICAXEPIC 24 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 ",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

PICAXEPIC 25 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 ") 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?

PICAXEPIC 26 Add 2nd trigger for start & stop of crossing Examine schematic and discuss role of 2nd trigger Examine code and identify how it uses two variables to remember direction of train’s travel

PICAXEPIC 27 Program #8 – Morse Code Change message Don’t forget the !

PICAXEPIC 28 Single White LED Install a white LED (clear body) Connect to LED1 on board

PICAXEPIC 29 Program #9 - Lighthouse #TERMINAL ' 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 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 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 'PAUSE a bit with LED off SERTXD ("pausing DONE",13,10) GOTO start 'do it again!

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

PICAXEPIC 31 2 White LEDs Connect a white LED to LED1 Connect another white to LED2

PICAXEPIC 32 Program #10 – Ditch Lights 'd. bodnar #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

PICAXEPIC 33 Install 6 LEDs Connect Red to LED1 and LED4 Connect Amber to LED2 and LED5 Connect Green to LED3 and LED6

PICAXEPIC 34 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 #11- Traffic light with 6 LEDs #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 ") 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

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

PICAXEPIC 36 #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!

PICAXEPIC 37 #14 - Strobe light 'School Bus-top Strobe 'd. bodnar ' 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 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:

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

PICAXEPIC 39 #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

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

PICAXEPIC 41 #16 - Servo Control Must add 3 pin cable (+5, ground, signal) 'd.bodnar 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:

PICAXEPIC 42 #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)

PICAXEPIC 43 Troubleshooting How to manually install USB drivers - link.us/article/?faqid=451http:// link.us/article/?faqid=451 Use Options (View / Options) to set proper chip Use View / Options Serial Port to check programming hardware Test power through 7805 and to PICAXE pins with meter Measure resistance of resistors in programming interface Test for shorts between pins