Docsity

Programming the Arduino board, Summaries of Engineering

Toggle sidebar
bg1
The Arduino board
•The Arduino family consists of popular, low-cost
development boards based on various Atmel AVR
microcontrollers
•The particular model used in this class is the Duemilanove,
which uses an ATmega328P microcontroller with a
simplified USB interface provided by an FT232 bridge
Arduino Development Board
•The board incorporates 5v and 3.3v LDO regulators to provide regulated voltage
sources using either USB bus power or an external power supply of 7-12 volts
•There are also indicator LED’s for power and serial activity, as well as a single user
LED on pin 13
•The microcontroller pin-nodes are made accessible by 0.10” female headers on the
sides of the board
•Pins are grouped according to function and are labeled at the foot of the pins
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Programming the Arduino board and more Summaries Engineering in PDF only on Docsity!

The Arduino board

  • The Arduino family consists of popular, low-cost development boards based on various Atmel AVR microcontrollers
  • The particular model used in this class is the Duemilanove, which uses an ATmega328P microcontroller with a simplified USB interface provided by an FT232 bridge

Arduino Development Board

  • The board incorporates 5v and 3.3v LDO regulators to provide regulated voltage sources using either USB bus power or an external power supply of 7-12 volts
  • There are also indicator LED’s for power and serial activity, as well as a single user LED on pin 13
  • The microcontroller pin-nodes are made accessible by 0.10” female headers on the sides of the board
  • Pins are grouped according to function and are labeled at the foot of the pins

Arduino Duemilanove

ATMega328p 8-Bit Microcontroller Clock speed: 16 MHz

Memory 32 KB flash memory (including 2 KB for bootloader) 2 KB SRAM for holding variables 1 KB EEPROM for saving data

Operating Voltage : 5 V

Power Supply 5V regulated supply via USB, host PC ( Range: 7-12 V, Limits: 6-20 V ) Vin: regulated external power, or Battery (9V)

Power Output Pins: 5V: regulated 5V at 40 mA max 3V3: regulated 3.3 V, 50 mA max via on board FTDI GND: ground

The ATMEGA328P datasheet along with other app notes can be found at:

  • http://www.atmel.com/dyn/products/product_card.asp?part_id=4198&ca

tegory_id=163&family_id=607&subfamily_id=

Other sources of information are available from the AVR development

community:

  • http://www.avrfreaks.net/
  • http://forums.adafruit.com/viewforum.php?f=37&sid=a1565239d19ca

75c6a411f47b0cc

  • http://www.freeduino.org/
  • http://forum.sparkfun.com/viewforum.php?f=

Note :

  • Aside from the supporting circuitry and an installed bootloader, the

Arduino board is just an ATMEGA328 processor

  • Most codes written for any ATMEGAxx8x microcontroller is likely to work

for Arduino with little modification

Arduino Family of Products

Arduino - HomePage:

  • http://arduino.cc/

It provides links to:

  • Buy
  • Download
  • Getting Started
  • Learning
  • Reference
  • Hardware
  • FAQ

Arduino Information

Arduino Programming

Programs are called sketches

Written in a C language subset

Every sketch requires 2 structural commands

void setup() { } // command runs once at the beginning of operation

void loop() { } // command runs a repeating loop after setup

// One-line comment /* Multi-line comment */

For a language reference and a list of libraries, check:

http://arduino.cc/en/Reference/HomePagePrograms

Arduino Code Library

Useful functions

pinMode() -set pin as INPUT/OUTPUT

digitalWrite() -set a digital pin (HIGH/LOW)

digitalRead() -read a digital pins state (HIGH/LOW)

analogRead() -read analog pin

analogWrite() -write an analog value

delay() -wait specific amount of time (ms)

millis() -get current counter time

Serial Commands

serial.begin(baud rate) -start serial communication with PC

serial.println(value) -print value to PC

serial.print(“…”, value) -print value without line

serial.read(“…”, value) -read value from PC with concatenation

Examples:

pinMode(2, INPUT);

digitalWrite(2, LOW);

val=digitalRead(2);

val=analogRead(2);

analogWrite(2,val); //val=0-

delay(value); //e.g., 1000 samples

Programming Arduino with Matlab

Arduino can be interactively programmed in Matlab

  • Arduino support from Matlab:
    • http://www.mathworks.com/academia/arduino-software/arduino-matlab.html
    • http://www.mathworks.com/matlabcentral/fileexchange/32374-matlab-support- package-for-arduino-aka-arduinoio-package/all_files
    • http://www.mathworks.com/matlabcentral/fileexchange/24638-arduino-meets- matlab

For more information, see:

  • MATLAB webinar and interactive tutorial:
    • http://www.mathworks.com/matlabcentral/fileexchange/27843-arduino-io- package-slides-and-examples
    • http://www.mathworks.com/company/events/webinars/wbnr43537.html

Arduino Application in Servo Motor Control

Arduino Target Tools Information

“Arduino Target” tools for Simulink:

  • URL: http://www.mathworks.com/matlabcentral/fileexchange/24675-arduino-target

Two approaches to compile your Simulink model to run on an Arduino:

  1. With only Simulink (including the student version) you can use the Simulink Support Package for the Uno/Mega described here: http://www.mathworks.com/academia/ arduino-software/arduino-simulink.html
  2. If you have Simulink Coder and Embedded Coder you can use this target which supports Duemilanove/Uno/Mega, allows the development of custom driver blocks, supported processor-in-the-loop execution, and provides access to the generated C code: http://www.mathworks.com/matlabcent ral/fileexchange/

Arduino Target Programming

Arduino Target blocks:

Example:

A Simulink model that solves the Arduino Blink Challenge. The controlled circuit switches between four modes: all LEDs off, all LEDs on, LEDs blinking simultaneously, and LEDs cycling at a specified frequency. This model is included with Arduino Blink Challenge Simulink Models.

Arduino Analog Input Measure voltage of analog input pin Arduino PWM Generate PWM on analog output pin Arduino Digital Input Get logical value of digital input pin Arduino Digital Output Set logical value of digital output pin Arduino Serial Receive Get one byte of data from serial port Arduino Serial Transmit Send buffered data to serial port Arduino Standard Servo Read Get shaft position of servo motor Arduino Continuous Servo Write Set shaft speed of servo motor Arduino Standard Servo Write Set shaft position of servo motor