User Tools

Site Tools


rtes:topics:arduino:start

This is an old revision of the document!


Intro to Arduino

store-cdn.arduino.cc_uni_catalog_product_cache_1_image_520x330_604a3538c15e081937dbfbd20aa60aad_a_0_a000111_featured.jpg
Fig.: Arduino M0 Pro. CPU: ATSAMD21G18, 32-bit ARM Cortex M0+

Technical data (Arduino M0 Pro processor)

  • Microcontroller: ATSAMD21G18, 32-bit ARM Cortex M0+
  • Embedded debugger
  • Operating voltage: 3.3 V
  • Input voltage: 7 - 12 V
  • Input voltage, max.: 6 - 20 V
  • Digital I/O pins: 20 (2 PWM)
  • UART: 1
  • Analogue input pins: 6, 12-bit ADC channel
  • Analogue output pins: 1, 10-bit DAC
  • DC per I/O pin: 7 mA
  • Flash memory: 256 KB
  • SRAM: 32 KB
  • 32-bit real-time counter (RTC) with clock/calendar function
  • 32-bit CRC generator
  • Two-channel Inter IC Sound (I2S) interface
  • Peripheral touch controller (PTC)
  • Clock speed: 48 MHz

https://store.arduino.cc/arduino-m0-pro

Lecture Notes

Keywords

Lab / Exercises

Background: ARM Cortex M0+ Processor

www.arduino.cc_en_uploads_guide_m0pro_usb_ports.jpg

We will use the next generation Arduino M0 Pro for this course. Its core is an ARM Cortex M0+ processor which make it faster and more powerful than the Arduino UNO based on the AVR-8-bit core.

The CPU used is ATSAMD21G18 having been designed by the former company Atmel which now has been taken over by Microchip.

Setting up the Arduino IDE tool chain

Please follow the instructions on Getting started with the Arduino M0 Pro.

0. General Basic Commands

We have to learn the following commands:

pinMode(pin, mode) 
myval = digitalRead(pin)
digitalWrite(pin, value)
myval = analogRead(pin)
analogWrite(pin, value)
delay(ms)
Serial.begin(baudrate)
Serial.println(data)
map(value, fromLow, fromHigh, toLow, toHigh)

Keywords: Arduino IDE, directories, libraries, code files, compile, upload, terminal (monitor)

<note> For the following exercises use the
Arduino Online Language Reference and the
Programmers Notebook (pdf) by Brian Evans. </note>

1. Digital Output

Write a program which lets and LED blink “SOS” in Morse code:

. . .   - - -  . . . 

(three short, three long, three short blinks). The LED is connected to pin 13. By default all pins are input so you have to define the pin direction to be an output explicitly. Use digitalWrite(pin,HIGH) and digitalWrite(pin,LOW).

Write two functions void morse_S() and void morse_O() and use for next loops for the loops within the functions.

Write two functions void blink_short() and void blink_long() including the pauses (LED off).

2. Digital Input

<note important> ATTENTION: 3.3V or 5V?
Some Arduino platforms use 3.3V as supply voltage or VCC (not 5V). In this case you might damage the microcontroller if you connect 5V to its pins! The input voltage would exceed the supply voltage (overvoltage). Avoid this! Some microcontrollers with 3.3V VCC have 5V tolerant inputs but this is not generally the case! Read the MC datasheets. </note>

  • How to connect switches to ditital inputs: Why do we have to use pull-up or pull-down resistors?
  • How to use and activate internal pull-up resistors of ATmega328 GPIO pins
  • If buttonPressed() then … else … endif
  • Switches are prone to bouncing. How can we demonstrate bouncing? Oscilloscope …
  • How to debounce?

3. Analog Input

  • Resolution of ADC? How many bits? How many different amplitude values?
  • Connect a potentiometer to an analog input of Arduino:
    The outer pins are connected to GND and VCC, respectively.
    The middle terminal is connected to the ADC.
  • Read the values from the ADC and write them to the serial port.
  • What are min and max values?
  • How many bits resolution does the ADC have?
  • Use the function map() to transform the ADC values to an interval of 0 to 100.

4. Analog Output

The “old” AVR microcontrollers such as ATmege328 (used with Arduino UNO) do not have a real analog output. To work around this limitation a method called Pulse Width Modulation (PWM) is used. A square wave signal of fixed frequency is generated and provided at a port pin (digital output). The pulse width (o.g. on-time) of the square wave can be changed whereas the total signal period T is kept constant (as a result of constant frequency). The ratio $r = on-time / period$ is called duty cycle.

  • Use the function “analog_out()”.
  • Resolution of PWM? How many bits? How many different amplitude values?
  • Read values from a potentiometer (10 bit), map the values to an 8 bit range and use the scaled value for a PWM output. Dim a LED.

5. Serial Communication (UART)

6. Bus systems

  • SPI
  • TWI (two wire interface), I2C
  • 1-Wire

7. Interrupts, Timers

8. Libraries

Homework

Literature

rtes/topics/arduino/start.1508237602.txt.gz · Last modified: 2017/10/17 10:53 by admin