The Arduino Micro-controller G4NAQ SHIREHAMPTON A.R.C.
Topics What is a microcontroller? What is an Arduino? Current Models of Arduino Sensors / Shields Kits Arduino Development Environment Programming the Arduino Compiling Sketches Demonstration Projects A Club Project Amateur Radio and the Arduino Useful Books & Links
What is a microcontroller? A small computer on a single circuit board often referred to system on a chip Contains a CPU, memory and I/O interfaces typically used for embedded control purposes or data analysis. The memory can be RAM, Flash or a one time program ROM Microcontrollers are used in automatically controlled products and devices, such as automobile engine control systems, implantable medical devices, remote controls, office machines, appliances, power tools and toys. The Raspberry Pi is more of a computer on a board and has more memory and a faster processor
What is an Arduino? A micro-controller board based on the ATMEL AVR RISC chip with an on-board power supply and USB port AVR stands for Alf (Egil Bogen) and Vegard (Wollan)'s RISC processor who were its 2 Dutch inventors The AVR was one of the first microcontroller families to use on-chip flash memory for program storage, as opposed to one-time programmable ROM, EPROM, or EEPROM used by other microcontrollers at the time An Open Source hardware platform which enables any company to produce versions of the Arduino
Current Models of Arduino All basically the same with a different board dimensions, processors, RAM and I/O configuration a bit like PC s! UNO MEGA LilyPad Nano Mini
Arduino board comparison Name Processor Operating/Input Voltage CPU Speed Analog In/Out Digital IO/PWM EEPROM [kb] SRAM [kb] Flash [kb] USB LilyPad ATmega168V ATmega328P 2.7-5.5 V / 2.7-5.5 V 8MHz 6/0 14/6 0.512 1 16 - Mega ATmega2560 5 V / 7-12 V 16 MHz 16/0 54/15 4 8 256 Regular Type B Uno ATmega328P 5 V / 7-12 V 16 MHz 6/0 14/6 1 2 32 Regular Type B Mini ATmega328P 3.3 V / 3.35-12 V 5 V / 5-12 V 8 MHz 16 MHz 6/0 14/6 1 1 32 6 pin header Nano ATmega168 ATmega328P 5 V / 7-9 V 16 MHz 8/0 14/6 0.512 1 1 2 16 32 Mini
The Arduino UNO R3 This is currently one of the most common types and in its 3 rd revision Atmel ATmega328P Microcontroller 14 digital input/output pins 6 with PWM (next page!) 6 analogue inputs 16 MHz quartz crystal Type B USB connection 2.1mm DC power socket (but can be powered via the USB socket) ICSP header (serial interface) Reset button Typically costs from 3-8 on ebay supplied with a USB cable
Digital I/O Pulse Width Modulation (PWM) Pulse Width Modulation, or PWM, is a technique for achieving analogue results with a digital means Digital control is used to create a square wave, a signal switched between on and off. The on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by changing the portion of time the signal is on versus the time the signal is off The duration of "on time" is called the pulse width. To achieve varying analogue values, you change, or modulate, that pulse width. Only relevant when the pin is used for output e.g. If you repeat this on-off pattern fast enough with an LED the result is as if the signal is a steady voltage between 0 and 5v controlling the brightness of the LED.
Arduino R3 Board (~ 7)
Sensors and shields Shields are boards that can be plugged on top of the Arduino PCB Sensors are boards or components used in conjunction with the I/O ports
Example Sensors & Shields available Weather Station Gas Humidity Photocell Temperature Water Switching Capacitive touch Joystick Hall effect Push button Reed switch Relays Sound Ultrasonic Misc Cellular shield CNC shield Robot shield Ethernet shield Data Logger (SD card) shield Midi shield Display (LCD, TFT & OLED) WiFi networking shield XBEE networking shield
Dupont Cables / Jumper Wires Essential wiring tool when experimenting & avoids a lot of time with a soldering iron Use with headers pins Strips available 10 30cms typically 99p Easiest way to link sensors to the Arduino pins Used to link breadboards or vero boards
Kits Lots of kits available from ~ 20 on ebay and consist of the microcontroller, shields, patch cables or breadboards with components Normally supplied with a tutorial with sample code provided to demonstrate each of the sensors
Arduino development environment Free software from www.arduino.cc referred to as the IDE (Integrated Development Environment) Constantly being developed Supported on Windows, Mac OS X and Linux Arduino programs or code are referred to as a sketch Written in C A sketch must contain at least the 2 sections of code as per the screen
Arduino \ C Coding Concepts Structure the use of curly brackets { }, ; line terminator, /* block comments */, // line comments and functions Functions a concise block of code normally written to perform a specific function. Arduino sketches contain a setup() and loop() function as a minimum Data types Byte (0-255), Integer (-32767 to 32768), Long (32 bit), Float (32 with a floating point) Character strings and arrays Variables must be declared before you can reference them Variable scope - where you define a variable in the sketch defines where it can be used/referenced Global variables - defined before the setup() can be referenced anywhere Local variables - defined inside a function can only be referenced by that function http://playground.arduino.cc/uploads/main/arduino_notebook_v1-1.pdf Note: C does contain a goto statement but its use is discouraged!
Arduino libraries Libraries provide extra functionality for use in sketches, e.g. working with hardware or manipulating data. A number of libraries come installed with the IDE, but you can also download or create your own. Ethernet GPS LCD Displays SD Card Servos WiFi
First steps.. Install the IDE Download he Arduino IDE from https://www.arduino.cc/en/main/software Install the IDE, no options to worry about
First steps.. Plug in the Arduino Plug in the Arduino to a spare USB port Windows should automatically install a new device In the control panel the Arduino will show up under the next available serial port Launch the IDE and from the tools menu select the type of Arduino you connected and the COM port. The Board Info option will then interrogate it return the following
Serial Interface You can t attach a monitor to the Arduino The easiest way to work around the lack of a monitor is the serial interface which is part of the Arduino IDE This is all a bit antiquated & reminds me of packet radio you basically have to tell the computer which COM port you are going to use & what the speed is for the data between the PC and the Arduino only saving grace is you don t have to set any other COM port settings which historically are a pain.. When you open the interface its basically a separate window & a terminal interface The demonstrations will show you more..
Compiling code Verify (the tick) Checks the syntax of the sketch Checks the presence of any libraries requested Upload (the right arrow) Converts the sketch into a machine language If no errors then uploads the machine code to the Arduino Automatic Execution Arduino resets itself & the code automatically runs! Code will keep running until the Arduino is powered off The next time power is applied it runs again and will keep running until overwritten by a new compiled sketch Other buttons are new sketch, open sketch & save sketch & open the serial terminal
Sample Code Sample code normally the same as required with the kits is installed automatically when you install the IDE.
Learning C / C++ Its inevitable at some point you will have to code something yourself even if its only the logic around how to interpret the results from a sensor. Lots of books but buy / read one specifically for Arduino programming There are lots of web sites for Arduino tutorials, the Arduino programming handbook is free & can be downloaded from http://playground.arduino.cc/uploads/main/arduino_notebook_v1-1.pdf Lots of sample code for use with the Arduino and samples with each sensor The Raspberry Pi Magazine (The MagPI) has created a really useful beginners guide https://www.raspberrypi.org/magpi-issues/essentials_c_v1.pdf
Programming & C / C++ challenges Think about what you are trying to achieve and break it down into blocks this makes it easier to write and test each part rather than a long rambling piece of code (which is also harder to maintain!) Write it down on paper possibly as a flowchart Search the Internet for sample code which may avoid having to invent it all Put comments in your code to make understanding it clearer to you & anyone else who wants to experiment with it Print off and check the code before compiling it checking for missing or extra ;, unbalanced parentheses, undefined or inappropriately defined variables Compiler Errors probably the most challenging to resolve at times, a single mistake can cause the compiler to generate 10 s of error messages most of which are then very misleading Debugging use the serial interface to track where you are in your sketch/program if there are problems
Demo 1 Temperature Sensor Arduino Nano + adapter A DHT11 combined temperature and humidity sensor
Demo 2 Home Alarm PIR A PIR Sensor which measure infrared light from nearby objects. When an object passes in front of the sensor the temperature in the sensor's field of view will change. The sensor converts the resulting change into a change in the output voltage. An LED which lights when the PIR detects movement\heat Ultrasonic sensors which bounce a signal off nearby objects The terminal (window on the PC) used to display results including the distance of the object detected by the ultrasonic sensors
Demo 3 Morse Tutor Fixed 5 character groups just like the old Datong Morse Tutor Vero board with pull down resistors on the digital pins to stop them floating 4 way switch to select A-Z, Numbers, Mixed, Mixed + Punctuation 2 * 10k pots Speaker Speed / Inter character gap Inter group gap Future additions Improve the audio using an external amp Display to replace terminal interface Variable audio tone frequency with another 10k pot + <10 lines of code
Demo 4 Morse Decoder Borrowed code based on a sketch from http://skovholm.com/cwdecoder Modified to support the I2C bus interface I2C Bus with 16*2 line LCD Display Microphone LED which flashes received morse Future additions Understand the code a bit! Connect the audio to receiver & remove the LED
Demo 5 The Finale! Project 3 sends CW Project 4 decodes it!
What next? A club Project? A WSPR Beacon Controller based on article by W3PM / GM4YRE? Weather Station @ SARC displaying information on the club website? (if we fix the Internet link!) DF Controller similar to the device built by Colin and attached to a UV5R? Other ideas?
RSGB / ebay Amateur Radio Arduino Books Recommended ~ 25 Members Price ~ 24 Members Price ~ 18 from Wordery
Useful Arduino Sites https://www.arduino.cc/ https://www.adafruit.com/ https://arduino-info.wikispaces.com/ On ebay search for Keyestudio