Arduino programs Arduino toolchain Cross-compilation Arduino sketches

Slides:



Advertisements
Similar presentations
ARDUINO CLUB What we’re really doing. BASICS The setup() and loop() functions.
Advertisements

Electrical team Arduino tutorial I BY: JOSHUA arduini
Lab7: Introduction to Arduino
Anurag Dwivedi & Rudra Pratap Suman.  Open Source electronic prototyping platform based on flexible easy to use hardware and software.
Embedded Sumo 1T4 – 1T5 UTRA.
1 Introduction to Coding. 2 Example Codes A lot of example codes are given with Arduino IDE A code can often be based on a previous example rather than.
Analog and Digital Measurements living with the lab 14 digital input / output pins 6 analog input pins © 2011 LWTL faculty team.
 Main Components:  Sensors  Micro controller  Motor drivers  Chasis.
Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
Arduino Part 1 Topics: Microcontrollers Programming Basics: structure and variables Digital Output Analog to Digital Conversion.
chipKit Sense Switch & Control LED
Microprocessors Tutorial 1: Arduino Basics
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
Introduction to the Arduino
Khaled A. Al-Utaibi  The Push Button  Interfacing Push Buttons to Arduino  Programming Digital Inputs  Working with “Bouncy”
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Microprocessors Tutorial 1: Arduino Basics
ARDUINO 1. Basics  Comments  /* * Blink * * The basic Arduino example. Turns on an LED on for one second, * then off for one second, and so on... We.
Microcontrollers, Microcomputers, and Microprocessors
Arduino libraries Datatekniker Udvidet hardware/software.
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.
Microcontroller basics Embedded systems for mortals.
Embedded systems and sensors 1 Part 2 Interaction technology Lennart Herlaar.
1 Introduction to Haptics Introduction to the Hapkit board Allison M. Okamura Stanford University.
ME 120: Arduino Programming Arduino Programming Part II ME 120 Mechanical and Materials Engineering Portland State University
Programming in Arduino Materials:Arduino Board Casperelectronics Pre Pres. Notes Photos from workshop?
:Blink Blink: Er. Sahil Khanna
Arduino “Getting Started” Instructor : Dr Matthew Miss Khin Yi Kyaw
1 Introduction to Coding. 2 Example Codes A lot of example codes are given with Arduino IDE A code can often be based on a previous example rather than.
Arduino.
Arduino Part 1 Topics: Microcontrollers
Getting Started: Building & Programming
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Assist. Prof. Rassim Suliyev - SDU 2017
Microcontroller basics
Val Manes Department of Math & Computer Science
Microcontroller basics
Microprocessors Tutorial 1: Arduino Basics
Arduino Programming Part II
UTA010 : Engineering Design – II
Cascade switching of an LED
European Robotic LABoratory
UCD ElecSoc Robotics Club 2017/2018
Arduino Part 1 Topics: Microcontrollers Programming Basics
INC 161 , CPE 100 Computer Programming
3.0 ARDUINO WORKSHOP PRESENTATION FOR STUDENTS IN 4º DEGREE OF COMPULSORY SECONDARY EDUCATION 3.0.
Lecture 2-2: Arduino Programming
Introduction to Arduino Microcontrollers
Roller Coaster Design Project
Introduction to Arduinos
Week 5: Microcontrollers
ARDUINO     What is an Arduino? Features 14 Digital I/O pins 6 Analogue inputs 6 PWM pins USB serial 16MHz Clock speed 32KB Flash memory 2KB SRAM.
IoT Programming the Particle Photon.
using the Arduino to make LEDs flash
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Welcome to Digital Electronics using the Arduino Board
analog and digital measurements
Programming 2: The Arduino IDE & First Sketches
CTY SAR FCPS Shawn Lupoli, Elliot Tan
I/O Programming with Arduino
Aeroponic Engineering and Vertical Farming
TI LaunchPad I/O Programming with Energia
Lab #1: Getting Started.
Arduino Uno circuit basics
Introduction to Arduinos
SAURABH GINGADE.
Arduino程式範例.
Introduction to Arduino IDE and Software
Interrupts.
Presentation transcript:

Arduino programs Arduino toolchain Cross-compilation Arduino sketches Classes Sketch structure Pins Input and output Blink example

Arduino toolchain

Verify and upload Libraries Code Combine & transform Compile Link HEX file creation HEX Upload

Combine and transform All program files are combined into one An #include is added to reference basic Arduino libraries Function prototypes are added A main() function is created

Cross-compilation

Compile and link avr-gcc is invoked to cross-compile the code Resulting code executes on AVR, not on Intel Generates an object file (.o) Object file is linked to Arduino library functions

Hex file creation and programming Avr-objcopy is invoked to change the format of the executable file A .hex file is generated from the .elf file

Arduino sketches

Arduino programs A program is called a sketch C++ program using Arduino library functions C++ is a superset of C All C programs are legal C++ C++ also includes classes

Object-oriented programming Organize your code through encapsulation Group together data and functions that are related User-defined type is specific to an application int type has data (the number) and functions (+, -, *)

Encapsulation example Specify and operate on 3 points int x, y; point p1; x1=0; y1=0; p1=newpoint(0,0); plot(x1,y1); p1.plot(); All data contained in one objects Reduced number of parameters Point-specific functions are easily identified

Classes

Classes and members class X { public: int m; int mf(int v){int old=m; m=v; return old;} }; X var; var.m=7; int z = var.mf(9);

Classes and members Declaration of a variable creates an object . operator used to access members Data and functions Functions can be defined inside the class

Classes in libraries We will Examples not need to know much about classes not define classes use classes defined in libraries Examples Ethernet.begin(mac) Serial.begin(speed); client.print(“Hello”); Serial.print(“Hello”);

Sketch structure

setup() function A sketch does not have a main() function Every sketch has a setup() function Executed once when Arduino is powered up Used for initialization operations Returns no value, takes no arguments void setup() { … }

loop() function Every sketch has a loop() function Executed iteratively as long as the Arduino is powered up loop() starts executing after setup() has finished loop() is the main program control flow Returns no value, takes no arguments void loop() { … }

Pins

Pins Pins are wires connected to the microcontroller Digital I/O Pins are wires connected to the microcontroller Pins are the interface of the microcontroller Pin voltages are controlled by a sketch Pin voltages can be read by a sketch Analog inputs

Output pins Output pins are controlled by the Arduino Voltage is determined by your sketch Other components can be controlled through outputs

Input pins Input pins are controlled by other components Arduino reads the voltage on the pins Allows it to respond to events and data

Digital vs. analog Some pins are digital-only Read digital input, write digital output 0 volts or 5 volts Some pins can be analog inputs Can read analog voltages on the pin Useful for analog sensors Analog-only pins are clearly labeled No pins can generate an analog output

Input and output

Input/output (I/O) These functions allow access to the pins void pinMode(pin, mode) Sets a pin to act as either an input or an output pin is the number of the pin 0-13 for the digital pins A0-A5 for the analog pins mode is the I/O mode the pin is set to INPUT, OUTPUT, or INPUT_PULLUP INPUT_PULLUP acts as input with reversed polarity

Digital input int digitalRead(pin) Example Returns the state of an input pin Returns either LOW (0 volts) or HIGH (5 volts) Example int pinval; pinval = digitalRead(3); pinval is set to the state of digital pin 3

Digital output void digitalWrite(pin, value) Example Assigns the state of an output pin Assigns either LOW (0 volts) or HIGH (5 volts) Example digitalWrite(3, HIGH); Digital pin 3 is set HIGH (5 volts)

Analog input int analogRead(pin) Example Returns the state of an analog input pin Returns an integer from 0 to 1023 0 for 0 volts, 1023 for 5 volts Example int pinval; pinval = analogRead(A3); pinval is set to the voltage on A3 (0 for 0 volts, 1023 for 5 volts) The pin must be an analog pin

Blink example

Delay void delay(msec) Example Pauses the program for msec milliseconds Useful for human interaction Example digitalWrite(3, HIGH); delay(1000); digitalWrite(3,LOW); Pin 3 is HIGH for 1 second

Blink example Blink is the generic simple example for embedded systems Like “hello, world” FileExamples01.BasicBlink Causes an LED to blink LED is built-in, so no wiring required Connected to pin 13

Blink sketch void setup() { pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delat(1000);

Lab

State change detection example Connect to Tinkercad at http://tinkercad.com and log-in. Go to Circuits and click “Create new circuit” button. Drag-and-drop the State change detection example from “Arduino””State change detection”. Examine the code and guess what it does. Start simulation to check if your guess was correct. It counts the number of button press and turns on the built-in LED at every 4 presses.

Neopixel example Connect to Tinkercad at http://tinkercad.com and log-in. Go to Circuits and click “Create new circuit” button. Drag-and-drop the Neopixel example from “Arduino””Neopixel”. Examine the code and guess what it does. Start simulation to check if your guess was correct. It sequentially turns on the Neopixel LEDs with randomly varying colors.

Neopixel with a button Combine “State change detection” and “Neopixel” to have your simulator do the following. When your Arduino is turned on, the Neopixel is sequentially turned on with random colors. Neopixel color changes when the number of button press increases (that is when the button status changes from “Released” to “Pushed”).