Introduction To Microcontroller Arduino Tutorial
Introduction To Microcontroller Arduino Tutorial
Introduction To Microcontroller Arduino Tutorial
Vlad−Mihai PL𝐀𝐂𝐈𝐍𝐓𝐀𝟏,𝟐
1. Horia Hulubei National Institute for R&D in Physics and Nuclear Engineering
2. University POLITEHNICA of Bucharest
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html |
Introduction to Microcontrollers: Arduino Tutorial
OUTLINE
➢ Introduction
➢ Microcontrollers Architecture
➢ Arduino environment
➢ Arduino boards
➢ Sensors interface
➢ Application control
➢ Arduino UNO board
➢ Coding example
➢ Applications
➢ Bibliography
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 1
Introduction to Microcontrollers: Arduino Tutorial
Introduction
What is a microcontroller?
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 2
Introduction to Microcontrollers: Arduino Tutorial
Introduction
What are they used for?
❖ Data control;
❖ Data Acquisition Systems;
❖ Power control and monitoring;
❖ Motor control applications;
❖ Smartphones;
❖ Automotive industry;
❖ Nuclear instrumentation; https://atmelcorporation.wordpress.com/tag/avr-
❖ Space applications. microcontrollers/
o In general are used in applications where high
processing resources are not required, hence a general
purpose microcontroller is considered suitable due the
low power consumption and without any peripheral and
external memories;
o Also, the cost may be an important factor.
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 3
Introduction to Microcontrollers: Arduino Tutorial
Introduction
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 4
Introduction to Microcontrollers: Arduino Tutorial
Microcontrollers Architecture
Simplified Architecture
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 5
Introduction to Microcontrollers: Arduino Tutorial
Arduino environment
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 6
Introduction to Microcontrollers: Arduino Tutorial
Arduino Boards
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 7
Introduction to Microcontrollers: Arduino Tutorial
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 8
Introduction to Microcontrollers: Arduino Tutorial
Sensor interface
Analog or digital?
➢ Sensor: an analog/digital device which converts the physical quantity in to an
electrical signal;
➢ All related physical quantities are related to ANALOG interface, where the
quantity can take any value between the hardware minimum and maximum
values;
➢ DIGITAL interface is used to describe the quantity which has only 2 levels, 1 or 0
max logic.
Sine waves are analog,
because the amplitude can
vary between minimum and a
min maximum value
1
Square waves are digital,
because the amplitude can
vary only between 2 values, 0 0
or 1 logic
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 9
Introduction to Microcontrollers: Arduino Tutorial
Sensor interface
Classification
AIR QUALITY LIGHT TEMPERATURE
SENSORS SENSORS SENSORS
PROXIMITY BAROMETRIC
SENSORS SENSORS
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 10
Introduction to Microcontrollers: Arduino Tutorial
Application control
COMPLEX DAQ RELAYS
SYSTEMS ROBOTS
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 11
Introduction to Microcontrollers: Arduino Tutorial
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 12
Introduction to Microcontrollers: Arduino Tutorial
ATMEGA328P
Architecture
Full datasheet
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 13
Introduction to Microcontrollers: Arduino Tutorial
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 14
Introduction to Microcontrollers: Arduino Tutorial
Timers / Counters
➢ Specific internal registers that increment data
and be triggered by:
❖ A clock source : Timer;
❖ An external event : Counter.
Utilities:
❖ Time domain measurements;
❖ Create PWM waveforms.
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 15
Introduction to Microcontrollers: Arduino Tutorial
Interrupts
Main loop {}
➢ Are used to break a routine of an program or
entire program flow in order to handle a instruction 1
specific event. instruction 2
Trigger Interrupt
instruction 3 ISR {}
➢ Are triggered by:
❖ Input pin state change (rise/fall/toggle); instruction 4 instruction
❖ Serial communication (USART, SPI, I2C); instruction 5
❖ ADC state registers;
instruction 6
❖ Analog comparator;
❖ Timers or Counters.
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 16
Introduction to Microcontrollers: Arduino Tutorial
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 18
Introduction to Microcontrollers: Arduino Tutorial
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 20
Introduction to Microcontrollers: Arduino Tutorial
Communication interfaces
~USART~
➢ Stands for Universal Synchronous/Asynchronous
Receiver/Transmitter;(one to one communication)
➢ Most common is used UART => Universal
Asynchronous Receiver/Transmitter; UART2
UART1
➢ The data transfer speed is defined as baud rate (bit
rate);
➢ Normally is defines as: TX RX
❖ One start bit;
❖ 8 data bits; RX TX
❖ 1 stop bit.
More at:
http://www.circuitbasics.com/basics-uart-communication/
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 21
Introduction to Microcontrollers: Arduino Tutorial
Communication interfaces
~SPI~
MASTER SLAVE1
➢ Stands for Serial Peripheral Interface, and its
SCLK SCLK describes a serial communication used in
embedded systems;
MOSI MOSI
➢ Support multiple slaves communications, but
MISO MISO only one at time;
➢ Can perform full duplex;
SS1 SS1
➢ One to many communication.
SS2 SLAVE2
SCLK SCLK => Serial Clock;
MOSI => Master Output Slave Input;
MOSI MISO => Master Input Slave Output;
MISO SS => Select Slave.
SS2
Read more about SPI
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 22
Introduction to Microcontrollers: Arduino Tutorial
Communication interfaces
~I2C~
➢ Stands for Inter-Integrated Circuit, also know as Two Wire Interface (TWI);
➢ Serial protocol which allows multiples masters and slaves on the same bus, up to
128; (many to many communication)
➢ Normally each device has an unique 7-bit or 10-bit address in the I2C bus;
➢ Being used in variety of digital sensors, can reach speeds up to 400 kbps. (Arduino
UNO)
SCL
SDA
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 23
Introduction to Microcontrollers: Arduino Tutorial
Coding example
~blinking a led~
➢ First of all, the latest version of
Arduino compiler must be installed
from: https://www.arduino.cc/ ;
➢ Run the compiler and go to
File=>Examples=>Basics=>Blink ;
➢ A new windows with the related
software should appear on your
screen;
➢ Compile the code and upload it on the
board; (The board new to be
connected to the PC already)
➢ Change the delay value, and observe
what happen.
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 24
Introduction to Microcontrollers: Arduino Tutorial
Coding example
~blinking a led~
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 25
Introduction to Microcontrollers: Arduino Tutorial
Coding example
~blinking a led~
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 26
Introduction to Microcontrollers: Arduino Tutorial
Applications
❖ Readout will be made with the Arduino UNO board and data will be send via
UART or Bluetooth to an LabVIEW GUI (Graphical User Interface).
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 27
Introduction to Microcontrollers: Arduino Tutorial
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 28
Introduction to Microcontrollers: Arduino Tutorial
Ultrasonic Radar
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 29
Introduction to Microcontrollers: Arduino Tutorial
Leds Control
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 30
Introduction to Microcontrollers: Arduino Tutorial
Datasheet
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 31
Introduction to Microcontrollers: Arduino Tutorial
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 32
Introduction to Microcontrollers: Arduino Tutorial
Bibliography
1. https://www.arduino.cc/
2. https://forum.arduino.cc/
3. http://www.ladyada.net/learn/arduino/
4. https://learn.sparkfun.com/tutorials/tags/arduino?page=all
5. http://forefront.io/a/beginners-guide-to-arduino/
6. https://programmingelectronics.com/arduino-tutorials-all/
7. http://littlebits.cc/tips-tricks/introduction-to-arduino-programming-1-the-basics
8. https://www.tutorialspoint.com/arduino/arduino_overview.htm
| vlad-mihai.placinta@cern.ch | www.nipne.ro/dpp/Collab/LHCb/upgrade.html | 33