MODEL RAILROADING WITH ARDUINO - Pcrnmra

Transcription

MODEL RAILROADINGWITH ARDUINODave FalkenburgSilicon Valley Lines Model Railroad Club

WHAT IS AN ARDUINO?

WHAT IS AN ARDUINO? Arduinois an open-source electronics prototyping platformbased on flexible, easy-to-use hardware and software. It'sintended for artists, designers, hobbyists, and anyoneinterested in creating interactive objects or environments. Alittle programmable computer platform designed helppeople “make things go.”http://www.arduino.cc/

WHAT IS OPEN SOURCE? Source NoCode is Publicly AvailableSecrets Hidden from Developers License Different “LikeControls How Code Can Be UsedCode & Projects Use Different LicensesPlaying Poker With Everyone’s Cards Face Up”

THERE IS EVEN A MOVIE http://vimeo.com/18539129

HARDWARE Basedupon widely available 8-bit Micro-controllers Single-chip OpenHardware Schematics KitsComputers as powerful as the early PCsavailable under various licensing termsand Built-up Boards from 15 to 80 Expandwith “Shields” (Stackable Boards)

HARDWARE 13digital I/O pins 6can be PWMed (digital dimmer) 6 Analog Canalso be used as extra digital I/O pins 6V-12V EasilyInputsPower Supply or 5V from USBExpandable & Customizable to add features

SOFTWARE

SOFTWARE Works Openwith Windows, Mac OS X, and LinuxSource Freeto Download & Use Source ProgramCode AvailableHardware via USB or Serial Port

SOFTWARE C-likeLanguage Programs Idealfor Hobbyists, Artists, and Explorers Rapid Easyfor the Arduino are called “Sketches”Prototyping of small projects is the goalto use “Libraries” developed by others DCC, Communications, LEDetc.

SOFTWARE Allthe “grunt work” is done for you by Arduino Onlytwo functions to create setup() loop() Sketchbook: initialize inputs & outputs: run over and over again until power is removedand examples to build upon, too.

“BLINKY” SKETCH

/*Blink: Turns on an LED on for one second, then off for one second, repeatedly.* LED connected from digital pin 13 to ground.* Note: On most Arduino boards, there is already an LED on the board connected topin 13, so you don't need any extra components for this example.Created 1 June 2005By David d on an orginal by H. Barragan for the Wiring i/o board*/int ledPin 13;// LED connected to digital pin 13// The setup() method runs once, when the sketch startsvoid setup(){pinMode(ledPin, OUTPUT);}// initialize the digital pin as an output:// the loop() method runs over and over again, as long as the Arduino has powervoid loop(){digitalWrite(ledPin, HIGH);delay(100);digitalWrite(ledPin, LOW);delay(100);}// turn the LED on// turn the LED off

ARDUINO “SHIELDS”

MOTOR SHIELDhttp://www.adafruit.com/

SOUND EFFECTSWAV ShieldMP3 Player com/

RELAY SHIELDhttp://shop.evilmadscientist.com/

CONNECTING WIRESAdafruit Proto-screwshieldhttp://www.adafruit.com/

“PATCH 4/index.html

NEED MORE I/O?Centipede Shield (64-GPIO)MuxShield IIhttp://macetech.comhttp://mayhewlabs.com/

ETHERNETEthernet ShieldArduino Ethernet*http://www.arduino.cc/

MESH NETWORKINGArduino Wireless ShieldXBee Shield

WIFI 84.95!!! 69.95!!!

MICROCHIP RN-XV WIFIXBee Form-Factor WiFi Module 24.95 34.95

“ELECTRIC IMP” WIFI 19.95 29.95(The “Imp” is actually a cloud-programmed WiFi Micro)

BLUETOOTH 4.0http://redbearlab.com

SPECIAL EFFECTS

SPECIAL EFFECTSNOTE: This is an mbed, notan Arduino; probably shouldre-shoot the video.

EFFECTS YOU CANNOT BUYSperry Rail Service Inspection Vehicle

ARDUINO & YOUR LAYOUT

MIX AND MATCH An Arduino Chubbcan connect to existing Model Railroad ElectronicsSMC12 for using digital output to control Tortoise DCCOD,TeamDigital DBD22, and NCE BD20 Detectors

LED SIGNALS

CONNECTING LEDS Anode ( , long leg) of LED to 5V (or 3.3V) Cathode (-, short leg, flat side) of LED to DIGITAL I/O Pinthrough a 470Ω resistor (330Ω for 3.3V)5V470ΩI/O470ΩI/O Anode ( , long leg) to DIGITAL I/O Pin through a 470Ωresistor (330Ω for 3.3V) Cathode (-, short leg, flat side) to Ground

SWITCHING 12V CIRCUITSI/OI/ONPN Transistor as Low Side Switch

LOTS MORE ingWithHardware

DIVING INTO CODE

MAKING FIREint ledPin 13;// LED connected to digital pin 13void setup(){pinMode(ledPin, OUTPUT);}void loop(){int dark;for (dark 0;dark 1000;dark ) {if (dark 500) {digitalWrite(ledPin, HIGH);// set the LED dPin, LOW);// set the LED offdelay(random(10 dark,50 dark));}}

AN ARC WELDERint ledPin 13;// LED connected to digital pin 13void setup(){pinMode(ledPin, OUTPUT);}void loop(){int i,count;count random(10,60);for (i 0;i count;i ) {digitalWrite(ledPin, HIGH);delay(random(60));digitalWrite(ledPin, // set the LED on// set the LED off// wait a random bit of time

A GRADE CROSSING

BUILDING THE HARDWARE Arduino WAVUnoShield SDCard Adafruit OpticalProto-screwshieldDetectors (e.g., IRDOT or NightScope ) WalthersCrossing Signal

BASIC STRATEGY If TrainDetected (IRDOTs connected to Digital Inputs): PlayBell Sound Loop & Blink Crossing Lights (LEDs) If TrainNo Longer Detected: Lights SourceOff; Stop Bell Sound LoopCode Available Here:https://github.com/railnerd/grade-crossing/

STATE MACHINE SIDEBAR Simple DoingIf Then Sequences are EasyComplex, or Multiple Things at Once is Harder (Blinking, Playing RequiresBreaking Up the Work you Do Computer IfSound, Reading Detectors)Folks Do This With “State Machines”you are a non-programmer, this can be mind blowing

GRADE CROSSING SKETCH#include WaveHC.h //WaveShieldFunctions#include WaveUtil.h //ArduinoPinAssignments#defineEB DETECTA0#defineWB DETECTA1#defineLED LEFTA2#defineLED RIGHTA3//GlobalStateenum{kIdle ommon,kOccupied};intinterlockingState kIdle;intdeactivateTimer 10000;

ng//Setupdetectorinputs,andenableon- ‐chip 20KpullupresistorspinMode(EB DETECT,INPUT);pinMode(WB DETECT,INPUT);digitalWrite(EB DETECT,HIGH);digitalWrite(WB torifroadisfouled//SetupLEDoutputspinMode(LED LEFT,OUTPUT);pinMode(LED ardsetupSDCard();turnOffLEDs();}

le:if((digitalRead(EB DETECT) LOW)&&(digitalRead(WB DETECT) HIGH)){interlockingState kEastboundApproach;}elseif((digitalRead(WB DETECT) LOW)&&(digitalRead(EB DETECT) HIGH)){interlockingState nterlockingState lockingState kApproachCommon;break;.

LOOP().casekApproachCommon:deactivateTimer 10000;interlockingState ctorsareshowingclearif((digitalRead(WB DETECT) HIGH)&&(digitalRead(EB DETECT) HIGH)){deactivateTimer- ‐- gState kIdle;}}else{deactivateTimer 10000;}break;default:break;}}

LED onRoutines//voidanimateLEDs(void){enum{kLEDsOff tate kLEDsOff;intledTimer 0;voidturnOffLEDs(void){digitalWrite(LED RIGHT,HIGH);digitalWrite(LED LEFT,HIGH);ledState kLEDsOff;}if(ledTimer)ledTimer- ‐- ‐;casekLEDsOff:ledTimer ate kLEDLeftOn;ledTimer 10000;digitalWrite(LED LEFT,LOW);digitalWrite(LED dState kLEDRightOn;ledTimer 10000;digitalWrite(LED LEFT,HIGH);digitalWrite(LED RIGHT,LOW);}break;}}

WHAT ELSE CAN YOU DO? PushButtons Photocells Current ServoMotors Stepper MP3DetectorsMotorsPlayback Chips RFIDReaders OtherComputers WiFi Ethernet

COOL STUFF Seth Neumann’s RFID del-Railroading-20130123.pdf Chuck DCCCatania: Simple Signals With ArduinoSniffer:http://www.mynabay.com/arduino DCC Throttle: http://www.oscale.net/en/arduino control.html

NEW THINGS

NEW STUFF Morepowerful boards with ARM processors now available Due: http://arduino.cc/en/Main/ArduinoBoardDue Teensy3.0: http://www.pjrc.com/store/teensy3.html

OPENLCB, TOO.http://railstars.com/hardware/io/io-duino/

RASPBERRY PI AnotherDeviceGame Changing 700MHz ARMLinuxComputer for 25/ 35! FullLinux System withGPIO, I2C, SPI, etc. Lookfor a Clinic Soon

WRAP UP

GETTING MORE HELP OnlineResources:http://arduino.cc Arduini YahooGroup:Arduini@yahoogroups.com TechShop BooksClasses

USEFUL LINKS http://www.arduino.cc/ http://spikenzielabs.com/ http://www.sparkfun.com/ http://techshop.ws/ http://www.adafruit.com/ http://learn.adafruit.com/category/learn-arduino http://moderndevice.com/Just Google/Bing/Yahoo for“Arduino” in your favoriteweb browser!

Q&A

WHAT IS AN ARDUINO? Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments. A little programmable