![Page 1: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/1.jpg)
Fubar Labs Arduino Tutorial
Introduction to Arduino HW andIntegrated Development Environment
4/14/2018 Introduction to Arduino and IDE 1
![Page 2: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/2.jpg)
Hampton Sailer, HW Engineer
• 30+ years experience designing microprocessor basedcircuit boards.
• 25% of my time with software for debug
• 7 years website design,UI and backend
• TCP/IP Ethernet networking debug
• Lots of power wiring (120 volt) work
• Stage lighting and sound system work
• Home construction and renovation
• http://www.hamptonsailer.com
![Page 3: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/3.jpg)
Fubar Labs Arduino class
• Requirements: some programming experience, aLaptop, Arduino starter kit.
• Use as much ready made hardware – Arduino Uno
• Ready made PCB, daughter cards (shields), Sensors
• Detailed understanding of HW features
• Mostly a software learning experience
• Drive real world I/O, power, sensors, buttons, relays
• Networking, communication, user interface
• Follow through with IDE “Example” codes
• Follow http://www.tutorialspoint.com/
4/14/2018 Fubar Labs - Introduction to Arduino and IDE 3
![Page 4: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/4.jpg)
Class list
• Introduction to Arduino IDE, and Multifunction Shield
• Motor Control, DC Motor, Servo Motors, Stepper Motors
• Sensor part 1: Pyrotenic InfraRed detector, Temperature
• Sensors part 2: Ultrasonic distance, IR remote control
• LCD display and User Interface
• LED string programming class
• Communications: USB, Ethernet, others to a PC GUI
• Special Music Synthesizer Class, Fluxamashield
• Special Robotics build class -
![Page 5: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/5.jpg)
Why use Arduino?
• Arduino is a very popular single board microcontroller,hence very low cost. (~$8)
• Open source, anyone can duplicate, royalty free.
• Easy to understand software environment (IDE).
• Lots of primitives built in, little initialization.
• www.arduino.cc website has lots of support
• Hardware is easy to use, lots of documentation
• Microchip-ATMEGA328 at Digikey
• Many, ready made daughter cards, (Shields).
4/14/2018 Introduction to Arduino and IDE 5
![Page 6: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/6.jpg)
4/14/2018 Introduction to Arduino and IDE 6
At DigikeyATMEGA328
![Page 7: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/7.jpg)
![Page 8: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/8.jpg)
Arduino Uno R3 schematic
![Page 9: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/9.jpg)
Arduino 2560 Mega
• Atmel ATmega 2560
• 256K Bytes Flash
• 8K Bytes SRAM
• 54 Digital I/O
• 16 Analog input (12 bit)
• 4 UARTS
• 16 MHz clock speed
• Still an 8 bit CPU
• About $12 fromAmazon Vendors
![Page 10: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/10.jpg)
Arduino Duemilanove
• Atmel SAM3X8E ARMCortex-M3 CPU
• 512K Bytes Flash
• 96K Bytes SRAM
• 3.3 Volt only I/O
• 84 MHz clock speed
• 54 Digital I/O ports
• 4 UARTS, SPI, I2C
• 12 analog inputs (12 bit)
• 2 DAC outputs (12 bit)
• From Amazon $22
http://www.microchip.com/wwwproducts/en/ATSAM3X8C
![Page 11: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/11.jpg)
Arduino Shield stacking
• All pins busedtogether
• User must resolvepin conflicts
• Power deliveredto stacked boards
![Page 12: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/12.jpg)
Multifunction Shield
• 4 digit 7-segment LED displaymodule driven by two serial74HC595's
• 4 x surface mount LED's in aparallel configuration
• 10K adjustable precisionpotentiometer
• 3 x Independent push buttons• Piezo buzzer• DS18B20, LM35 temperature
sensor interface• Infrared receiver interface• Serial interface header for
convenient connection to serialmodules such as Bluetooth,wireless interface
• Amazon HiLetgo Shield
http://files.cohesivecomputing.co.uk/Hackatronics-Arduino-Multi-function-Shield.pdf
![Page 13: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/13.jpg)
Motor Control Shield
• Two L293 chips
• Dual “H” Bridge, each
• Total 4 “H” Bridges
• Run 2 stepper motors
• Up to 0.5 amp output
• Up to 30 Volts
• SPI serial device
• SPI select from digitaloutput
![Page 14: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/14.jpg)
LCD and button shield
• This is a basic 16 characterby 2 line black-on-greendisplayUtilizes the extremelycommon HD44780 parallelinterface chipset.Interface code is freelyavailable.Blue Backlight with whitewords.uses 4 Bit Arduino LCDLibrary.
How to use:Arduino_LCD_KeyPad_Shield
![Page 15: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/15.jpg)
Communication with Arduino
MidiController
RS-232Serial
USB Zigbee
Bluetooth
WiFi
Ethernet
ArduinoProcessor
![Page 16: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/16.jpg)
Networking Technologies
• GPS Global_Positioning_System
• GSM/GPRS General_Packet_Radio_Service
• SIMCOM_AT_Commands Cell Phone Shield
• Ethernet Shield Qunqi-W5100-Ethernet
• WiFi Shield Qunqi-Electronics-ESP8266
• Bluetooth Shield Wikipedia/Bluetooth
• ZigBee https://en.wikipedia.org/wiki/Zigbee
• XBee https://en.wikipedia.org/wiki/XBee
• LoRaWAN https://www.lora-alliance.org/
![Page 17: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/17.jpg)
Ethernet Shield
• Uses Wiznet 5100 chip
• http://www.wiznet.io
• Full TCP/IP stack on chip
• Uses SPI to interface
• RJ45 Twisted pairCategory 5 Ethernetcable, 10/100 Mbps
• https://www.gearbest.com
![Page 18: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/18.jpg)
Sensor Modules
• Ultrasonic module tomeasure distance
• http://www.circuitbasics.com/ultrasonic
• DHT11 Temperature andhumidity
• http://www.circuitbasics.comTemperature and Humidity
4/14/2018 Fubar Labs - Introduction to Arduino and IDE 18
![Page 19: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/19.jpg)
Motion detection Sensor
• PIR Pyrotecnic InfraRedsensor
• Adjustible sensitivity
• Adjustible Delay time tooff.
• Light control
• Alarm detection
• https://learn.adafruit.com/passive-infrared-proximity
4/14/2018 Fubar Labs - Introduction to Arduino and IDE 19
![Page 20: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/20.jpg)
4/14/2018 Fubar Labs - Introduction to Arduino and IDE 20
![Page 21: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/21.jpg)
Some Hardware Vendors
• Ebay, Aliexpress, Amazon, Sears, Walmart• https://www.adafruit.com/• https://www.sparkfun.com/• http://shieldlist.org/• www.jameco.com http://www.mpja.com/• www.digikey.com www.mouser.com• https://www.dfrobot.com/• http://www.apcmag.com/12-raspberry-pi-
alternatives.htm/• https://playground.arduino.cc/Main/Resources• https://www.tindie.com/browse/arduino/
4/14/2018 Introduction to Arduino and IDE 21
![Page 22: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/22.jpg)
Installing the IDE
1. Goto https://www.arduino.cc/en/Main/Software
2. Download the Arduino IDE
3. Open the *.exe file
4. Agree to licence agreement
5. Install all checked component SW items
6. Choose default folder to install SW, default is good
7. Click “Install”
8. Icon will be installed to your desktop.
9. Double click icon to startup IDE
4/14/2018 Introduction to Arduino and IDE 22
![Page 23: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/23.jpg)
Integrated Development Environment
• Set the board type
• Set the USB port
• Open example
• Edit Sketch code
• Upload Sketch
• User serial monitor fordebug
• Reset board to runagain
4/14/2018 Introduction to Arduino and IDE 23
![Page 24: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/24.jpg)
ArduinoLanguageReference
Arduino Official Library
Arduino Reference Libraries
Ardunio Playground LibrariesContributions from 3rd Parites
https://playground.arduino.cc/Main/LibraryList
https://www.arduino.cc/en/guide/libraries
http://arduino-info.wikispaces.com/Arduino-Libraries
![Page 25: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/25.jpg)
Arduino IDE built in examples
![Page 26: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/26.jpg)
General Program flow
//declarations
int buttonPin = 3;
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}
void loop() { // ... }
![Page 27: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/27.jpg)
Control statements, Setup, Loop
• Structure
• setup()
• loop()
• ; (semicolon)
• {} (curly braces)
• // (single line comment)
• /* */ (multi-line comment)
• #define
• #include
• Control Structures
• if
• if...else
• for
• switch case
• while
• do... while
• break
• continue
• return
• goto
![Page 28: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/28.jpg)
I/O Functions
• Digital I/O
• pinMode()
• digitalWrite()
• digitalRead()
• Analog I/O
• analogReference()
• analogRead()
• analogWrite() - PWM
• Advanced I/O
• tone()
• noTone()
• shiftOut()
• shiftIn()
• pulseIn()
• Time
• millis()
• micros()
• delay()
• delayMicroseconds()
![Page 29: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/29.jpg)
Arduino UARTThe following code will make Arduino send hello world when it starts up.void setup() {Serial.begin(9600); //set up serial library baud rate to 9600Serial.println("hello world"); //print hello world}void loop() { }After the Arduino sketch has been uploaded to Arduino,open the Serial monitor at the top right section of Arduino IDE.Type anything into the top box of the Serial Monitor and press send or “Enter”.This will send a series of bytes to the Arduino.The following code returns whatever it receives as an input.
void setup() {Serial.begin(9600); //set up serial library baud rate to 9600}void loop() {if(Serial.available()) { //if number of bytes (characters) available for readingSerial.print("I received:"); //print I receivedSerial.write(Serial.read()); //send what you read } }Notice that Serial.print and Serial.println will send back the actual ASCII code,whereas Serial.write will send back the actual text.
![Page 30: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/30.jpg)
Other important stuff
• External Interrupts
• attachInterrupt()
• detachInterrupt()
• Interrupts
• interrupts()
• noInterrupts()
• Communication
• Serial
• Stream
• Bits and Bytes
• lowByte()
• highByte()
• bitRead()
• bitWrite()
• bitSet()
• bitClear()
• bit()
![Page 31: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/31.jpg)
Math and character handeling
• Math• min()• max()• abs()• constrain()• map()• pow()• sqrt()• Trigonometry• sin()• cos()• tan()• Random Numbers• randomSeed()• random()
• Characters• isAlphaNumeric()• isAlpha()• isAscii()• isWhitespace()• isControl()• isDigit()• isGraph()• isLowerCase()• isPrintable()• isPunct()• isSpace()• isUpperCase()• isHexadecimalDigit()
![Page 32: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/32.jpg)
/* Define shift register pins used for seven segment display */#define LATCH_DIO 4#define CLK_DIO 7#define DATA_DIO 8
/* Segment byte maps for numbers 0 to 9 */const byte SEGMENT_MAP[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90};/* Byte maps to select digit 1 to 4 */const byte SEGMENT_SELECT[] = {0xF1,0xF2,0xF4,0xF8};
void setup () {/* Set DIO pins to outputs */pinMode(LATCH_DIO,OUTPUT);pinMode(CLK_DIO,OUTPUT);pinMode(DATA_DIO,OUTPUT);}
/* Main program */void loop() {/* Update the display with the current counter value */WriteNumberToSegment(0 , 0);WriteNumberToSegment(1 , 1);WriteNumberToSegment(2 , 2);WriteNumberToSegment(3 , 3);}/* Write a decimal number between 0 and 9 to one of the 4 digits of the display */void WriteNumberToSegment(byte Segment, byte Value){digitalWrite(LATCH_DIO,LOW);shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_MAP[Value]);shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_SELECT[Segment] );digitalWrite(LATCH_DIO,HIGH);}
http://playground.arduino.cc/Main/SoftwareI2CLibrary
![Page 33: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/33.jpg)
Free Arduino Tutorials
• https://www.arduino.cc/en/Tutorial/BuiltInExamples• https://www.tutorialspoint.com/• http://www.me.umn.edu/courses/me2011/arduino/• http://www.computerprogrammingbook.com/arduino/• https://playground.arduino.cc/Main/ManualsAndCurriculum• http://www.free-engineering-books.com/2014/10/the-largest-
collection-of-arduino-books.html• http://www.electronicshub.org/arduino-project-ideas/• https://randomnerdtutorials.com/arduino-step-by-step-
projects/• https://www.elprocus.com/• http://arduinolearning.com/code/multi-function-shield-
examples.php
4/14/2018 Introduction to Arduino and IDE 33
![Page 34: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/34.jpg)
Electronic Music
• https://www.youtube.com/watch?v=vCK--bs6FYY
• http://musicfromouterspace.com/
• http://www.paia.com/index.asp
• http://www.birthofasynth.com/index.html
• https://moderndevice.com/product/fluxamasynth-shield/
• https://www.sparkfun.com/products/10587
• https://modularaddict.com/shruthi-smr4filter-pcb
• https://mutable-instruments.net/archive/shruthi/build/smr4mkii/
• http://sensorium.github.io/Mozzi/
• https://encyclotronic.com/synthesizers/misc-instruments/minty-synth-20-r1130/
![Page 35: Fubar Labs Introduction to Arduino - Hampton Sailer to Arduino.pdf · • Arduino is a very popular single board microcontroller, hence very low cost. ... wireless interface ... USB](https://reader034.vdocument.in/reader034/viewer/2022051308/5afec9ab7f8b9a444f8f5090/html5/thumbnails/35.jpg)
Robot parts stores online
• http://www.robotshop.com/en/
• https://www.dfrobot.com/
• https://www.vexrobotics.com/
• https://www.bananarobotics.com/shop/