Arduino and the Radio Amateur

Embed Size (px)

Citation preview

Arduino and the Radio Amateur

Arduino and the Radio AmateurGary Sutcliffe, W9XTCopyright 2012 Gary C. Sutcliffe This presentation will cover a lot of topics quickly. There will be a lot of terms thrown out.For those who have a background in computers this talk will help identify what is unique about ArduinoFor those that this is all new:Dont worry about the details. Just try to get a general flavor for what is being discussedA red ! In upper corner means this is an important concept

Last Revision May, 2012

1Microcontroller Development SystemLow cost - ~$30Free development softwareUSB connection to ArduinoRuns under Windows, Mac, LinuxEasily expand hardware with stackable ShieldsHuge user communitySoftwareDesignsTutorialsForumsWhat is Arduino?Arduino is taking the world by storm. There are probably 500,000 or more Arduino or Arduino compatible systems out there.

Arduino makes it easier to develop microcontroller based projects.

2What is a microcontroller?MicroprocessorMicrocontrollerMultipurpose PCMACMemory is externalExtra circuitry to outside worldUsually has OS (Windows)

Single purposeMicrowave OvenTV remoteMemory inside chipPeripherals to outside world built inUsually does not have OS

A PC has a microcomputer chip, but it does not contain the memory, I/O, etc. These are all on the mother board or plug in boards. A microcontroller has these built in. Different microcontrollers offer different mixes of memory and peripherals.

Some of the lines are blurred. The chip in a smart phone may use external memory and use an OS, but have built in peripherals.

Program memory holds program if power lost. Sort of like the hard drive on a PC.Peripherals used to interact with outside world.

Microcontrollers come in different sizes 8, 16, or 32 bit, amount of memory, different peripherals, amount of I/O. Low end ones cost less than $1 in single quantity.

A microcontroller is generally programmed to run just one application Keyer, repeater controller, rotor control, etc.

3Microcontroller Peripherals

CommunicationsSerial (RS-232)SPII2CUSBEthernetCAN BusLIN BusTimingTimersCountersPWM

AnalogA/D Converter

Digital I/O PortsLCD control

Many classes of peripheralsNot every microcontroller has all of these peripheralsDont worry if you dont know what all of these are.4Arduino UNO Processor

There are a number of Arduino models and Arduino clones. The UNO is the current standard model. It costs about $30.The IC is an Atmel AVR microcontroller with 32K memory. The silver box in the upper right is the USB connector for programming. The thin black connectors on the top and bottom of the picture allow stacking of daughter boards called shields to expand the hardware.5Expand I/O with shieldsStackable shields expand I/Owww.shieldlist.org lists nearly 300 available shieldsMotor controlWiFi LCD DisplaysEthernetSensorsBluetoothMemoryLED matrixRelayGPSPrototype/developmentMany, many more!

The Unified Microsystems ATS-1 shield adds LCD, push buttons, programmable LED & buzzer. This boards only use two of the Arduino I/O lines leaving the rest available for your project.The daughter boards are called shields because they shield you from the hardware.

A lot of projects need a user interface. There are a lot of designs on the web showing how to connect the Arduino to an LCD display with buttons, LEDs, etc. The problem is they used almost all of the I/O lines and left very few left for the application. To solve this problem, I designed the ATS-1to use the serial lines so it only uses two lines to add all these functions. This leaves the rest of the I/O lines for sensors, output control lines, etc.6Free Development Software

The development software is a free download.The system lets you write the software, compile it and down load to the Arduino board.

Compile:Computers only understand very simple instructions: Add two numbers, compare two numbers, etc. Very tedious for humansHigh level languages have instructions like print a line of text, open a text file, etc.Compilers translate high level instructions to instructions computers can understand. A high level instruction can be just a few machine instructions or maybe thousands.

Some similar systems use interpreters instead of compilers. These are much slower since the microcontroller has to decode each program instruction then execute them each time.7Wiring Language - C/C++ Based, simplifiedFast - compiled, not interpretedBuilt in functions make it easy to use peripheralsDigital Input/OutputAnalog/Digital ConvertersSerial PortsI2C & SPI interfaceThousands of programs & examples on web

Arduino Programming LanguageDont worry if you dont understand what all these mean. What is important is:Designed to be easy to learn and useA lot of the low level complex work is done for youLot of programs, programming tutorials, & examples on the web

The built in peripheral control functions really make it easy for beginners. It often takes pros hours to do things on other systems a beginner can do in minutes on an Arduino.8Made up of a series of instructionsMake a calculationControl the output pinsCheck state of input pinsConfigure & control the microcontroller peripheralsMake decisions and control program direction

Computer ProgramsImportant thing is that a program is a set of instructions done in order.9LatherRinseRepeatSimple Computer Program!Important concept slide!

Similar to computer programSet of simple instructionsComputers programs are always a big loop. A computer is (almost) always executing instructions.Loop over and over- with computer you dont run out of shampoo

10Variables

XNameSwitch_State3.1415DaveON (1, HIGH)

RAM memory locations you can put information into and check laterYou need to define what type of data goes into variablesContents of RAM are lost when power is lost!!Important concept slide!Think of a variable as a box to store things. We can put something in one and later come back and see what it is or replace its contents with something else. There are different types of variables to hold different types of dataWe can change the value of a variable any time we want.

When the power is removed, all the boxes are emptied.11Digital signals can have only 2 states

ON 1TrueHigh5V at I/O pin

OFF0FalseLow0V at I/O pinDigital Input/Output Signals

Arduino has 14 digital lines that can be configured to be inputs or outputs.!Important to understand this slide!

Microcontrollers have pins dedicated for digital input and outputs. A pin can be set to be an input or an output it cant be both at the same time.An output pin will put either 5V or 0 V to the pin. It is used to control something outside the microcontroller.An input pin expects to see either 5V or 0V applied to the pin. It is used to check the state of something outside the microcontroller.

12 Think of a digital output line as a switch. Setting it HIGH is like turning the switch ON. Setting it LOW is like turning the switch OFF.

digitalWrite(5, HIGH); //Set Output #5 High Output will put 5V at the pin which can drive a relay, LED, transistor or other external device

digitalWrite(7, LOW); //Set Output #7 LowOutput pin will be 0V, turning off external device

Digital Output Programming!Important concept slide!

Dont try to remember the exact details of the code. Just get an idea of the types of things that are done in a program.

The digitalWrite() function sets the selected output pin high or low.The // means that what follows are comments or notes to describe what the code is doing.

13An external switch, sensor or other device can be connected to an input pin.The program can make decisions based on the value in X

X= digitalRead(12); // Reads Input #12 and set X to:1 if Input pin #12 is HIGH (5V)0 if Input pin #12 is LOW (0V)

Digital Input Programming!The digitalRead() functions check what voltage is present on the input pin and stores the value in a variable.

What do you get if 2.5V is applied? Cant tell. Voltages around the supply voltage give unpredictable resultsWhat do you get if 10V is applied? You open the smoke output port14

Simple I/O CircuitsInput: Read State of Switch Output: Turn LED On/OffA simple circuit withSwitch input on I/O 11. High if switch open, low if switch closed LED on I/O 10. If high, LED will be on. If low, LED is off.15//Turn on LED when switch closedint sw; // variable to hold state of switch

void setup() //do this 1 time when power is applied{pinMode(10, OUTPUT); //set pin to output to drive LEDpinMode(11, INPUT); //set pin to input to read switchdigitalWrite(11,HIGH); //Turns on internal pull up resistor}

void loop() //loop runs forever (or at least until we turn it off){sw = digitalRead(11);if(sw == 0) digitalWrite(10,HIGH); //turn on LED else digitalWrite(10,LOW); //turn LED off } /*** end of loop() ***/A Simple Arduino ProgramDont worry about details. Just try to understand the general reason for the steps.

Setup() is required and where you normally put the instructions to configure the Arduino hardware. It is executed once at start up.Loop () is required and where the main body of the program is put. The statements inside loop() will execute one by one forever.The {} curly brackets break up sections of code that go together.

This simple program turns an Arduino with about million transistors into a wire! Have to walk before we can run.16Google Ham Radio + Arduino gets 1,500,000 hits

Ham Radio Arduino ProjectsCW KeyersAPRSTNCAntenna SwitchingSatellite TrackingRepeater ControlRotor controlVoice keyerBeaconsQRSSMost Arduino users are not hams. There are thousands of non-ham projects

17Lets Make a CW Keyer!Morse is made of dits and dahs (dots and dashes)The basic unit of time is the dit. Dahs are 3 times as long as a dit. The space between dits & dahs in a character is one dit.18A Simple CW Keyer Shield

Only needs 3 resistors, two connectors and a transistor.

A CW paddle is connected to I/O pins 3 & 4 which are configured as inputs. Resistors R2 and R3 connect to +5V. This puts = +5V on the two input pints. If the paddle is not pressed, the dit and dah inputs will see 5V, a logical 1. If a paddle is pressed, a connection is made shorting the resistor to ground. The I/O pin will see 0V, or a logical 0.

I/O pin 5 is configured as an output. To effect a key down state, a logical 1 is put on the input. This drives 5V into the transistor which acts as a switch to key the transmitter. For key up state, a logic 0 (0V) is put on I/O pin 6. This turns off the transistor. The transistor is used because the microcontroller pin cant handle voltage and currents of the typical transmitter CW input.19// W9XT Simple Arduino Keyer // Give pins names easier to remember what they are for:const int Dit = 3; // Pin for Dit inputconst int Dah = 4; // Pin for Dah inputconst int KeyOut = 5; //Pin for keyer output

// variables will change:int ditTime = 120; // Dit time in msec for 10 WPM int padState; //holds state of paddle contact

void setup() { //do this once at power up // initialize the pins as inputs and outputs pinMode(Dit, INPUT); pinMode(Dah, INPUT); pinMode(KeyOut, OUTPUT); digitalWrite(KeyOut,LOW); //Make sure we start out key up }

Simple Keyer Program Part 1We assign names Dit, Dah, KeyOut to the pins because it is easier to remember than a bunch of pin numbers.

Create a variable ditTime that will hold the number of msec that will be used for the period of time for a dit.

Finally we set up the pins to be used as inputs and outputs. Note that we initially set the KeyOut output low so it wont power up keying the transmitter.

The above code executes once when power is applied or the Arduino is reset.20void loop(){padState = digitalRead(Dit); // Check for the dit paddle pushed if(padState == 0){ //pin low if paddle pressed. If low do this: digitalWrite(KeyOut,HIGH); //set Key down state delay(ditTime); //stay that way for 1 dit time digitalWrite(KeyOut,LOW); // now have to be key up for 1 dit time delay(ditTime); } padState = digitalRead(Dah); //now check for the dah paddle pushedif(padState == 0){ //pin low if paddle pressed. If low, do this: digitalWrite(KeyOut,HIGH); //set Key down state delay(ditTime* 3); //stay that way for 3 dit times digitalWrite(KeyOut,LOW); // now have to be key up for 1 dit time delay(ditTime); } } // end of loop()Simple Keyer Program Part 2This is the main loop. Ultimately all computer programs are a continuous loop that will continue to execute as long as the computer is powered up.

The first part determines if the dit paddle is pressed. If it is, it generates a key down period for the dit, followed by a one dit key up period to act as a space between the next dit or dah.

The second part looks for a dah press. It is the same as the dit code except that the key down period is 3 times as long.

The program endlessly keeps checking for dit and dah presses and generating the proper key up and key down periods.21The Arduino has Analog to Digital converter inputsAn A/D converter is like a digital voltmeter10 bit A/D gives a value between 0-1023With 5V reference, actual voltage = returned value * .0049V

We will use a potentiometer as a voltage divider to vary the voltage at an A/D pin. The voltage will determine the CW speed.Adding Speed Control with A/DNo one wants a keyer that only works at 10 WPM, so lets add a speed control.22

Voltage Divider Speed ControlMorse Timing Dit Period

Tmsec = 1200/WPM

5 WPM: T = 240msec40 WPM: T = 30msec

AD value @ 0V = 0AD value @ 5V = 1023

Equation to cover ~5 to ~40 WPMT = AD/5 +30

Note: Fastest speed is at 0V, slowest at 5V

We want keyer to handle 5WPM to 40 WPM.

This circuit is added to the keyer shield23void loop(){ //do foreverint rawAnalog; //holds A/D reading //update the CW speed new!! rawAnalog = analogRead(analogPin); //measure the voltage ditTime = (rawAnalog/5) +30; //Calculate the new dit time

// Check for the dit paddle pushed padState = digitalRead(Dit); if(padState == 0) //pin low if paddle pressed { digitalWrite(KeyOut,HIGH); //set Key down state delay(ditTime); //stay that way for 1 dit time digitalWrite(KeyOut,LOW); // now have to be key up for 1 dit time delay(ditTime); } //now check for the dah paddle pushed code not shown for clarity } //end of loopKeyer Program with Speed ControlThis builds on the old code. The dit and dah handling routines are unchanged. Some of the old code is not shown for clarity.

We configured analog pin 0 as an analog channel in setup code Not shownDeclared a new variable rawAnalog to hold the raw A/D value for use in calculating the length of a dit.

We added a line of code to read the voltage provided by our voltage divider pot and store it in the variable rawAnalog.Then we calculate a new ditTime. This is used for the timing control next time we get a dit or dah paddle press.24The speed control is not very good. Not much resolution at high speed. Could fix with softwareCould add weight control change dit/dah ratioAdd Mode B operationCould add stored messagesCould add ability to swap dit/dah inputs for leftiesAdd just about anything you can think of...Possible Keyer ImprovementsThis keyer is pretty crude but is a good example of a simple ham radio application.

Mode A and Mode B have different timing of when they recognize key closures. If you learn on one type of keyer it is hard to use the other kind.

The amount of features you could add are only limited by your imagination!25Advantages of ArduinoHistorical DevelopmentProgramming knowledgeElectronics knowledgeComputer architecture knowledgeExpensive development software & equipment

Arduino DevelopmentVery little experience to start hard work doneLow cost hardware ~$30Free SoftwareConcentrate on learning one area at a timeLots of resources on web

I have been working with micros since the mid 1970s as my main professional specialization. I have done hundreds of microcontroller apps from simple to very complex. There was a huge learning curve just to get to the point where you could do simple things.

Even though I have a lot of knowledge and equipment, I often use the Arduino for simple one off projects. In one project I figured it would take about 3-4 hours to wire up the circuit and program it. With the Arduino I wrote the software in about 5 minutes and wired up the external electronics in about 15 minutes. This was great since I only needed it for a couple of days.

Member of WCARC got an Arduino for Christmas. With no programming experience and average ham knowledge of electronics made a system to control stepper motors for controlling some equipment at work. This was done in a week doing it at night.26Great for beginnersInexpensiveMuch of the hard work is already doneLots of learning resources on the webStart simple and grow as you learn

What neat Arduino project will you come up with?

Arduino SummaryAlthough designed for students, the Arduino is great for pros for single, one off projects.27www.arduino.cc - Main Arduino sitewww.shieldlist.org list of available shieldsArduino sourceswww.digikey.comwww.mouser.comwww.sparkfun.comwww.newark.comRadio Shackwww.unifiedmicro.com LCD Shield www.w9xt.com micro interfacing tutorial

This program will be available on www.w9xt.com

Arduino ResourcesThe main Arduino sites has information on hardware, development software down load, forums, tutorials and more.

I am developing additional shields that may be available. Check the Unified Microsystems web site.

I have a series of tutorials on how to connect external electronics to microcontrollers like the Arduino. They are written for people with only very basic experience with electronics.28