SlideShare a Scribd company logo
Grenoble | images | parole | signal | automatique | laboratoire
UMR 5216
Anton Andreev
07/05/2020
INTRODUCTION TO
ARDUINO
Contents
INTRODUCTION TO ARDUINO
1. General information
- Specification
- Drivers and Shields
- GPIO
- Compilers and IDEs
- Hardware protocols: I2C, SPI, UART
2. Examples
- DC Motor control
- Stepper motor control
- Reading analog data ADC
- What is DMA optimization?
- Equalizer in software and hardware
In a nutshell
INTRODUCTION TO ARDUINO
Arduino is:
• Board + Microcontroller unit (MCU)
• A standard (Arduino comtible/clone)
Arduino’s features:
- 8 bit 32 registers RISC processor, AVR family
- Produced by Atmel (acquired by Microchip Technology)
- In-system programmer
- Bootloader
- Analog to Digital Converter (ADC)
- 10-bit ADC with 1,024 (2^10) discrete analog levels
- 14 input/output pins
- Comes with IDE (Integrated Development Environment)
- Many libraries, examples and documentation
Specification
INTRODUCTION TO ARDUINO
- 8 bit AVR CPU
- Flash Memory is 32 KB
- SRAM is 2 KB (RAM)
- EEPROM is 1 KB
- CLK Speed is 16-20 MHz
- Some versions have DMA
- 32bit ARM CPU
- Flash Memory is 512 KB
- SRAM is 96 KB
- EEPROM is 1 KB
- CLK Speed is 74-80 MHz
- Has RTC
- Has DMA
Arduino Arduino clone STM32 Nucleo
Many clones of Arduino exist often with better hardware parameters,
Bluetooth and WIFI modules built-in
Arduino also has several versions: UNO, Leonardo, Mega, Ethernet
Drivers and Shields
INTRODUCTION TO ARDUINO
Example: the L298N first as a driver
and then a shield
Difference:
- A motor driver is a chip that drives motors. A motor shield is a circuit
board with connections on it that contains a motor driver chip that
drives motors. A shield is convenient since you can just plug it in to your
Arduino and wire the motors direct to it, but it lacks the flexibility of a
raw driver chip which you can wire up precisely as your project
demands.
Other popular shields for Arduino: ethernet, WIFI, RGB LCD
Arduino vs Raspberry Pi Short Comparison
INTRODUCTION TO ARDUINO
Pi is more powerful, like a normal computer
Raspberry Pi is:
- Multicore ARM 1.2Ghz,integrated GPU, RAM 1GB
- Has GPIO 40 pins compared to Arduino’s 20
- 8 channel 17 bit ADC
Usage:
- For higher level tasks
- Machine Learning (any ML library that compiles on
Linux OpenCV included), Image Processing
- Multimedia
- Small factor computers
- Surveillance systems
- Draws more energy than Arduino
- More expensive
- Has no storage by default
Arduino can be used as a
slave for Raspberry Pi
Compilers
INTRODUCTION TO ARDUINO
Arduino
program/sketch
Small modifications to
produce standard C code
Every manufacturer has its own software
development toolchain
Avr-g++ compiler is part of Atmel AVR GNU
Toolchain. It is based on GNU GCC and
tools created by AVR
Code for STM32 is pure C/C++ with libraries
from ST. The compiler is part of the
STM32Cube Ecosystem. The compiler is
called GNU Tools for STM32 and it based
on a patched version GNU Arm Embedded
Toolchain avr-g++
compiler
CircuitPython
INTRODUCTION TO ARDUINO
- Fork of MicroPython
- Targets: low memory and performance boards
- 32 bit ARM (such as STM32 or ESP8266)
- But not the original Arduino with 8 bit AVR CPU
- Python 3 compiler and Virtual Machine are on the board
- REPL on the USB through serial
- Controller’s flash memory is exposed as USB thumb drive
- .py files can be copied onto the board and executed
- main.py or code.py are executed automatically on restart
- Can restart automatically when .py file has changed
- Result of “print” command is visible in the Serial Monitor
- Can have only the VM and bytecode compiled program on the board
IDEs
INTRODUCTION TO ARDUINO
- Arduino IDE
- Programs are called sketches
- Easy program upload
- Easy configuration
- Serial Port
- Arduino type or clone
- Atom IDE + Platformio plugin
- Visual Studio with Arduino add-on
- Paid
- Integrated debugging
- Eclipse for Arduino
- SMT32 System Workbench (only for STM32)
- STM32CubeIDE (only for STM32)
Arduino GPIO
INTRODUCTION TO ARDUINO
General-Purpose Input Output (GPIO)
14 digital and 6 analog pins ca be used
for both input and output
pinMode (3, OUTPUT) //set as output
digitalWrite (3, HIGH) //set 3,3V value
digitalRead(pin) //read state
digitalRead(pin) // ADC 5v -> [0..1023]
Arduino PINS
INTRODUCTION TO ARDUINO
Digital Input with Pull-up
Resistor
INTRODUCTION TO ARDUINO
Problem:
Sometimes switching between one state
to another or pins configured as input with
nothing connected to them may arise
situation of High-impedance state i.e.
floating state. This state may report
random changes in pin state
Solution:
Adding pull-up (to +5V) or pull-down (to
Gnd) resistor which helps to set the input
to a known state
pinMode (3, INPUT_PULLUP)
Pull Down resistor
SPI and I2C
INTRODUCTION TO ARDUINO
When we connect a microcontroller to a
sensor, display, or other module these
device needs to communicate
Two popular hardware communication
protocols:
- SPI is used for SD cards, RFID card
readers …
- I2C is used for OLED displays,
barometric pressure sensors, or
gyroscope/accelerometer …
- Both use clocks, are serial and async
- 2 (I2C) or 4 (SPI) wires
- One or multiple masters (I2C)
- One or multiple slaves (both)
- I2C uses messages with addresses to
communicate with salves, SPI use selects
to which slave to speak
- Speed of transfer (SPI is faster)
I2C message
I2C: SDA (Serial Data) and SDL (Serial Clock)
I2C OLED example
INTRODUCTION TO ARDUINO
#include <Arduino.h>
#include <U8g2lib.h> //library for control of the OLED screen
#include <SPI.h>
#include <Wire.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
void setup(void)
{
u8g2.begin();
}
void loop(void)
{
u8g2.clearBuffer(); //clear the internal memory
u8g2.setFont(u8g2_font_logisoso28_tr);
u8g2.drawStr(8,29,“GIPSALAB"); //write something to the internal
memory
u8g2.sendBuffer();//transfer internal memory to the display
}
On the Arduino:
Pin 19 blue line is SCL
Pin 18 purple is SCA
UART
INTRODUCTION TO ARDUINO
UART is used over a computer or peripheral
device serial port (COM1,COM2…) through a
UART chip
Characteristics:
- Well documented and widely used
- Two wires
- 9 bit packet (0 or 1 parity bits)
- Serial
- No clock
- Has a parity bit to allow for error checking
- No multiple slaves, only one on one
PWM (1)
INTRODUCTION TO ARDUINO
PWM is a technique to
use digital values and
delays to emulate
analog values
DC motor control With Arduino (1)
INTRODUCTION TO ARDUINO
In red the L298N
motor driver
DC motor control With Arduino (2)
INTRODUCTION TO ARDUINO
L298N H-bridge can used for two motors and to change in which direction
the motor spins
DC motor control with Arduino (3)
INTRODUCTION TO ARDUINO
We use PWM in the
range of [0 255]. So if
want 3V out of 12V
maximum then we
need to send the
value of 255/4 on the
control pin
255 corresponds to 12 volts
DC motor control with Arduino (4)
INTRODUCTION TO ARDUINO
int rotDirection = 0;
int pressed = false;
#define button 4
void loop()
{
// Read potentiometer value
int potValue = analogRead(A0);
// Map the potentiometer value from 0 to 255
int pwmOutput = map(potValue, 0, 1023, 0 , 255);
// Send PWM signal to L298N Enable pin
analogWrite(enA, pwmOutput);
// Read button
if (digitalRead(button) == true)
{
pressed = !pressed;
}
//wait until button is released on a single push
while (digitalRead(button) == true);
delay(20);
//If button is pressed - change rotation direction
if (pressed == true & rotDirection == 0)
{
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
rotDirection = 1;
delay(20);
}
// If button is pressed - change rotation direction
if (pressed == false & rotDirection == 1)
{
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
rotDirection = 0;
delay(20);
}
} //end of loop()
Stepper motor control with Arduino (1)
INTRODUCTION TO ARDUINO
Stepper motors can be:
• unipolar -> U2004 Darlington Array
• Bipolar -> SN754410ne H-Bridge
Also the wiring is different for Darlington Array and the H-Bridge
Stepper motor control with Arduino (2)
INTRODUCTION TO ARDUINO
Code is the same for unipolar and bipolar motors.
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int stepCount = 0; // number of steps the motor has taken
void setup() { // nothing to do inside the setup}
void loop()
{ // read the sensor value: int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100); // set the motor speed:
if (motorSpeed > 0)
{
myStepper.setSpeed(motorSpeed); // how many RPMs per minute
myStepper.step(stepsPerRevolution / 100); //2 steps
}
}
Reading analog data example
INTRODUCTION TO ARDUINO
// the setup routine runs once when you press reset:
void setup()
{
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop()
{ // read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue); //data is send over UART
delay(1); // delay in between reads for stability
}
Reads an analog input on pin 0, prints the result to the Serial Monitor
DMA – Direct Memory Access
INTRODUCTION TO ARDUINO
If we need Audio processing, oscilloscope or EEG device
Arduino Zero or STM32 have built-in DMA controllers
Optimization with DMA
INTRODUCTION TO ARDUINO
Processing (ADC + data forwarding to UART) takes 9.6 μs
(microsecond) without DMA and 2 μs with DMA. That makes 4
times the difference.
Signal Processing on Arduino
INTRODUCTION TO ARDUINO
- Do we need to do it in real-time?
- Are there space and energy constraints (flying air sensor)?
- Is the ADC in Arduino good enough?
- 10 bit ADC => 1,024 (2^10) discrete analog levels
- ~1 KHz real world sampling / 9.6 KHz theoretical
- RAM limit (2KB – 96 KB)
- Is there enough libraries?
- FIR: https://www.arduinolibraries.info/libraries/fir-filter
- FFT: https://www.arduinolibraries.info/libraries/arduino-fft
- Can we augment the Arduino to do better DSP?
7 bin Equalizer (1)
INTRODUCTION TO ARDUINO
Source: https://github.com/debsahu/ESP32_FFT_Audio_LEDs
Using an Arduino clone such as: ESP32 or Lolin D32
7 bin Equalizer (2)
INTRODUCTION TO ARDUINO
Using software implemented FFT
- We can choose each bin frequency
- FFT https://github.com/kosme/arduinoFFT
- Bins to LED conversion:
https://github.com/G6EJD/ESP32-8266-Audio-Spectrum-Display
7 bin Equalizer (3)
INTRODUCTION TO ARDUINO
- Using hardware FFT IC MSGEQ7
- Predefined bins
- The Arduino microcontroller is relieved (FFT very CPU intensive)
Refernces
INTRODUCTION TO ARDUINO
NUCLEO DMA:
https://www.digikey.fr/en/maker/projects/getting-started-with-stm32-
working-with-adc-and-dma/f5009db3a3ed4370acaf545a3370c30c
https://www.youtube.com/watch?v=EsZLgqhqfO0
Arduino ZERO DMA:
https://github.com/manitou48/ZERO
DC motor control:
https://howtomechatronics.com/tutorials/arduino/arduino-dc-motor-
control-tutorial-l298n-pwm-h-bridge/
Stepper motor control:
https://www.arduino.cc/en/tutorial/stepperSpeedControl
Support for STM32 in Arduino:
https://github.com/rogerclarkmelbourne/Arduino_STM32

More Related Content

Similar to How to use an Arduino (20)

PDF
Arduino - Learning.pdf
KhalilSedki1
 
PDF
Arduino spooky projects_class3
Anil Yadav
 
PDF
Starting with Arduino
MajdyShamasneh
 
PDF
Arduino A Technical Reference A Handbook For Technicians Engineers And Makers...
ozoezenesli
 
PPT
Intro to Arduino
avikdhupar
 
PDF
Intro to Arduino Revision #2
Qtechknow
 
PPTX
ARDUINO Presentation1.pptx
SourabhSalunkhe10
 
PPTX
Arduino . .
dryazhinians
 
PPTX
Arduino intro.pptx
SanthanaMari11
 
PPTX
Micro_Controllers_lab1_Intro_to_Arduino.pptx
Gaser4
 
PDF
Mechatronics material . Mechanical engineering
sachin chaurasia
 
PPTX
arduinoedit.pptx
rajalakshmi769433
 
PPTX
BURO Arduino Workshop
Omer Kilic
 
PDF
Arduino experimenters guide ARDX
Johnny Parrales
 
PPTX
embedded_in_Arduino_with_basic_embedded.pptx
acloudinfo2023
 
PPT
13223971.ppt
SuYee13
 
PPTX
Ardui no
Amol Sakhalkar
 
PDF
arduinoworkshop-160204051621.pdf
AbdErrezakChahoub
 
PDF
Arduino experimenters guide hq
Andreis Santos
 
PPTX
Arduino tutorial A to Z
Md. Asaduzzaman Jabin
 
Arduino - Learning.pdf
KhalilSedki1
 
Arduino spooky projects_class3
Anil Yadav
 
Starting with Arduino
MajdyShamasneh
 
Arduino A Technical Reference A Handbook For Technicians Engineers And Makers...
ozoezenesli
 
Intro to Arduino
avikdhupar
 
Intro to Arduino Revision #2
Qtechknow
 
ARDUINO Presentation1.pptx
SourabhSalunkhe10
 
Arduino . .
dryazhinians
 
Arduino intro.pptx
SanthanaMari11
 
Micro_Controllers_lab1_Intro_to_Arduino.pptx
Gaser4
 
Mechatronics material . Mechanical engineering
sachin chaurasia
 
arduinoedit.pptx
rajalakshmi769433
 
BURO Arduino Workshop
Omer Kilic
 
Arduino experimenters guide ARDX
Johnny Parrales
 
embedded_in_Arduino_with_basic_embedded.pptx
acloudinfo2023
 
13223971.ppt
SuYee13
 
Ardui no
Amol Sakhalkar
 
arduinoworkshop-160204051621.pdf
AbdErrezakChahoub
 
Arduino experimenters guide hq
Andreis Santos
 
Arduino tutorial A to Z
Md. Asaduzzaman Jabin
 

Recently uploaded (20)

PPTX
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
PDF
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PDF
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PDF
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PPT
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
PPTX
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PPTX
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
PDF
NTPC PATRATU Summer internship report.pdf
hemant03701
 
PPTX
原版一样(EC Lille毕业证书)法国里尔中央理工学院毕业证补办
Taqyea
 
PDF
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
PPT
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
PDF
aAn_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PDF
REINFORCEMENT LEARNING IN DECISION MAKING SEMINAR REPORT
anushaashraf20
 
PDF
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PDF
Digital water marking system project report
Kamal Acharya
 
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
NTPC PATRATU Summer internship report.pdf
hemant03701
 
原版一样(EC Lille毕业证书)法国里尔中央理工学院毕业证补办
Taqyea
 
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
aAn_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
REINFORCEMENT LEARNING IN DECISION MAKING SEMINAR REPORT
anushaashraf20
 
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
Digital water marking system project report
Kamal Acharya
 
Ad

How to use an Arduino

  • 1. Grenoble | images | parole | signal | automatique | laboratoire UMR 5216 Anton Andreev 07/05/2020 INTRODUCTION TO ARDUINO
  • 2. Contents INTRODUCTION TO ARDUINO 1. General information - Specification - Drivers and Shields - GPIO - Compilers and IDEs - Hardware protocols: I2C, SPI, UART 2. Examples - DC Motor control - Stepper motor control - Reading analog data ADC - What is DMA optimization? - Equalizer in software and hardware
  • 3. In a nutshell INTRODUCTION TO ARDUINO Arduino is: • Board + Microcontroller unit (MCU) • A standard (Arduino comtible/clone) Arduino’s features: - 8 bit 32 registers RISC processor, AVR family - Produced by Atmel (acquired by Microchip Technology) - In-system programmer - Bootloader - Analog to Digital Converter (ADC) - 10-bit ADC with 1,024 (2^10) discrete analog levels - 14 input/output pins - Comes with IDE (Integrated Development Environment) - Many libraries, examples and documentation
  • 4. Specification INTRODUCTION TO ARDUINO - 8 bit AVR CPU - Flash Memory is 32 KB - SRAM is 2 KB (RAM) - EEPROM is 1 KB - CLK Speed is 16-20 MHz - Some versions have DMA - 32bit ARM CPU - Flash Memory is 512 KB - SRAM is 96 KB - EEPROM is 1 KB - CLK Speed is 74-80 MHz - Has RTC - Has DMA Arduino Arduino clone STM32 Nucleo Many clones of Arduino exist often with better hardware parameters, Bluetooth and WIFI modules built-in Arduino also has several versions: UNO, Leonardo, Mega, Ethernet
  • 5. Drivers and Shields INTRODUCTION TO ARDUINO Example: the L298N first as a driver and then a shield Difference: - A motor driver is a chip that drives motors. A motor shield is a circuit board with connections on it that contains a motor driver chip that drives motors. A shield is convenient since you can just plug it in to your Arduino and wire the motors direct to it, but it lacks the flexibility of a raw driver chip which you can wire up precisely as your project demands. Other popular shields for Arduino: ethernet, WIFI, RGB LCD
  • 6. Arduino vs Raspberry Pi Short Comparison INTRODUCTION TO ARDUINO Pi is more powerful, like a normal computer Raspberry Pi is: - Multicore ARM 1.2Ghz,integrated GPU, RAM 1GB - Has GPIO 40 pins compared to Arduino’s 20 - 8 channel 17 bit ADC Usage: - For higher level tasks - Machine Learning (any ML library that compiles on Linux OpenCV included), Image Processing - Multimedia - Small factor computers - Surveillance systems - Draws more energy than Arduino - More expensive - Has no storage by default Arduino can be used as a slave for Raspberry Pi
  • 7. Compilers INTRODUCTION TO ARDUINO Arduino program/sketch Small modifications to produce standard C code Every manufacturer has its own software development toolchain Avr-g++ compiler is part of Atmel AVR GNU Toolchain. It is based on GNU GCC and tools created by AVR Code for STM32 is pure C/C++ with libraries from ST. The compiler is part of the STM32Cube Ecosystem. The compiler is called GNU Tools for STM32 and it based on a patched version GNU Arm Embedded Toolchain avr-g++ compiler
  • 8. CircuitPython INTRODUCTION TO ARDUINO - Fork of MicroPython - Targets: low memory and performance boards - 32 bit ARM (such as STM32 or ESP8266) - But not the original Arduino with 8 bit AVR CPU - Python 3 compiler and Virtual Machine are on the board - REPL on the USB through serial - Controller’s flash memory is exposed as USB thumb drive - .py files can be copied onto the board and executed - main.py or code.py are executed automatically on restart - Can restart automatically when .py file has changed - Result of “print” command is visible in the Serial Monitor - Can have only the VM and bytecode compiled program on the board
  • 9. IDEs INTRODUCTION TO ARDUINO - Arduino IDE - Programs are called sketches - Easy program upload - Easy configuration - Serial Port - Arduino type or clone - Atom IDE + Platformio plugin - Visual Studio with Arduino add-on - Paid - Integrated debugging - Eclipse for Arduino - SMT32 System Workbench (only for STM32) - STM32CubeIDE (only for STM32)
  • 10. Arduino GPIO INTRODUCTION TO ARDUINO General-Purpose Input Output (GPIO) 14 digital and 6 analog pins ca be used for both input and output pinMode (3, OUTPUT) //set as output digitalWrite (3, HIGH) //set 3,3V value digitalRead(pin) //read state digitalRead(pin) // ADC 5v -> [0..1023]
  • 12. Digital Input with Pull-up Resistor INTRODUCTION TO ARDUINO Problem: Sometimes switching between one state to another or pins configured as input with nothing connected to them may arise situation of High-impedance state i.e. floating state. This state may report random changes in pin state Solution: Adding pull-up (to +5V) or pull-down (to Gnd) resistor which helps to set the input to a known state pinMode (3, INPUT_PULLUP) Pull Down resistor
  • 13. SPI and I2C INTRODUCTION TO ARDUINO When we connect a microcontroller to a sensor, display, or other module these device needs to communicate Two popular hardware communication protocols: - SPI is used for SD cards, RFID card readers … - I2C is used for OLED displays, barometric pressure sensors, or gyroscope/accelerometer … - Both use clocks, are serial and async - 2 (I2C) or 4 (SPI) wires - One or multiple masters (I2C) - One or multiple slaves (both) - I2C uses messages with addresses to communicate with salves, SPI use selects to which slave to speak - Speed of transfer (SPI is faster) I2C message I2C: SDA (Serial Data) and SDL (Serial Clock)
  • 14. I2C OLED example INTRODUCTION TO ARDUINO #include <Arduino.h> #include <U8g2lib.h> //library for control of the OLED screen #include <SPI.h> #include <Wire.h> U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0); void setup(void) { u8g2.begin(); } void loop(void) { u8g2.clearBuffer(); //clear the internal memory u8g2.setFont(u8g2_font_logisoso28_tr); u8g2.drawStr(8,29,“GIPSALAB"); //write something to the internal memory u8g2.sendBuffer();//transfer internal memory to the display } On the Arduino: Pin 19 blue line is SCL Pin 18 purple is SCA
  • 15. UART INTRODUCTION TO ARDUINO UART is used over a computer or peripheral device serial port (COM1,COM2…) through a UART chip Characteristics: - Well documented and widely used - Two wires - 9 bit packet (0 or 1 parity bits) - Serial - No clock - Has a parity bit to allow for error checking - No multiple slaves, only one on one
  • 16. PWM (1) INTRODUCTION TO ARDUINO PWM is a technique to use digital values and delays to emulate analog values
  • 17. DC motor control With Arduino (1) INTRODUCTION TO ARDUINO In red the L298N motor driver
  • 18. DC motor control With Arduino (2) INTRODUCTION TO ARDUINO L298N H-bridge can used for two motors and to change in which direction the motor spins
  • 19. DC motor control with Arduino (3) INTRODUCTION TO ARDUINO We use PWM in the range of [0 255]. So if want 3V out of 12V maximum then we need to send the value of 255/4 on the control pin 255 corresponds to 12 volts
  • 20. DC motor control with Arduino (4) INTRODUCTION TO ARDUINO int rotDirection = 0; int pressed = false; #define button 4 void loop() { // Read potentiometer value int potValue = analogRead(A0); // Map the potentiometer value from 0 to 255 int pwmOutput = map(potValue, 0, 1023, 0 , 255); // Send PWM signal to L298N Enable pin analogWrite(enA, pwmOutput); // Read button if (digitalRead(button) == true) { pressed = !pressed; } //wait until button is released on a single push while (digitalRead(button) == true); delay(20); //If button is pressed - change rotation direction if (pressed == true & rotDirection == 0) { digitalWrite(in1, HIGH); digitalWrite(in2, LOW); rotDirection = 1; delay(20); } // If button is pressed - change rotation direction if (pressed == false & rotDirection == 1) { digitalWrite(in1, LOW); digitalWrite(in2, HIGH); rotDirection = 0; delay(20); } } //end of loop()
  • 21. Stepper motor control with Arduino (1) INTRODUCTION TO ARDUINO Stepper motors can be: • unipolar -> U2004 Darlington Array • Bipolar -> SN754410ne H-Bridge Also the wiring is different for Darlington Array and the H-Bridge
  • 22. Stepper motor control with Arduino (2) INTRODUCTION TO ARDUINO Code is the same for unipolar and bipolar motors. #include <Stepper.h> const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution // for your motor // initialize the stepper library on pins 8 through 11: Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); int stepCount = 0; // number of steps the motor has taken void setup() { // nothing to do inside the setup} void loop() { // read the sensor value: int sensorReading = analogRead(A0); // map it to a range from 0 to 100: int motorSpeed = map(sensorReading, 0, 1023, 0, 100); // set the motor speed: if (motorSpeed > 0) { myStepper.setSpeed(motorSpeed); // how many RPMs per minute myStepper.step(stepsPerRevolution / 100); //2 steps } }
  • 23. Reading analog data example INTRODUCTION TO ARDUINO // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // print out the value you read: Serial.println(sensorValue); //data is send over UART delay(1); // delay in between reads for stability } Reads an analog input on pin 0, prints the result to the Serial Monitor
  • 24. DMA – Direct Memory Access INTRODUCTION TO ARDUINO If we need Audio processing, oscilloscope or EEG device Arduino Zero or STM32 have built-in DMA controllers
  • 25. Optimization with DMA INTRODUCTION TO ARDUINO Processing (ADC + data forwarding to UART) takes 9.6 μs (microsecond) without DMA and 2 μs with DMA. That makes 4 times the difference.
  • 26. Signal Processing on Arduino INTRODUCTION TO ARDUINO - Do we need to do it in real-time? - Are there space and energy constraints (flying air sensor)? - Is the ADC in Arduino good enough? - 10 bit ADC => 1,024 (2^10) discrete analog levels - ~1 KHz real world sampling / 9.6 KHz theoretical - RAM limit (2KB – 96 KB) - Is there enough libraries? - FIR: https://www.arduinolibraries.info/libraries/fir-filter - FFT: https://www.arduinolibraries.info/libraries/arduino-fft - Can we augment the Arduino to do better DSP?
  • 27. 7 bin Equalizer (1) INTRODUCTION TO ARDUINO Source: https://github.com/debsahu/ESP32_FFT_Audio_LEDs Using an Arduino clone such as: ESP32 or Lolin D32
  • 28. 7 bin Equalizer (2) INTRODUCTION TO ARDUINO Using software implemented FFT - We can choose each bin frequency - FFT https://github.com/kosme/arduinoFFT - Bins to LED conversion: https://github.com/G6EJD/ESP32-8266-Audio-Spectrum-Display
  • 29. 7 bin Equalizer (3) INTRODUCTION TO ARDUINO - Using hardware FFT IC MSGEQ7 - Predefined bins - The Arduino microcontroller is relieved (FFT very CPU intensive)
  • 30. Refernces INTRODUCTION TO ARDUINO NUCLEO DMA: https://www.digikey.fr/en/maker/projects/getting-started-with-stm32- working-with-adc-and-dma/f5009db3a3ed4370acaf545a3370c30c https://www.youtube.com/watch?v=EsZLgqhqfO0 Arduino ZERO DMA: https://github.com/manitou48/ZERO DC motor control: https://howtomechatronics.com/tutorials/arduino/arduino-dc-motor- control-tutorial-l298n-pwm-h-bridge/ Stepper motor control: https://www.arduino.cc/en/tutorial/stepperSpeedControl Support for STM32 in Arduino: https://github.com/rogerclarkmelbourne/Arduino_STM32

Editor's Notes

  • #3: A standard means that clones can be produced.
  • #4: A standard means that clones can be produced. In-system programmer = we do not need to remove MCU from the board own bootloader =  MCU what to load or do next. The bootloader also aids communication between the Arduino IDE and Arduino Board using USB.  The bootloader is responsible for writing code on the chip as it arrives from the Arduino IDE.
  • #5: Why 8 bit processor ? SRAM is RAM for program execution EEPROM is persistent memory. It can be used for storing small amounts of information e.x. configuration settings, passwords. Using the EEPROM is easy with a built-in library: https://www.arduino.cc/en/Reference/EEPROM
  • #6: Some Arduino clones require a driver for USB connectivity such as: CH340
  • #7: https://www.electronicshub.org/raspberry-pi-vs-arduino/
  • #9: MicroPython is a full Python compiler and runtime that runs on the micro-controller hardware. The user is presented with an interactive prompt (the REPL) to execute supported commands immediately. Included are a selection of core Python libraries; MicroPython includes modules which give the programmer access to low-level hardware. Circuit Python https://learn.adafruit.com/welcome-to-circuitpython/what-is-circuitpython https://www.youtube.com/watch?v=rN7kvWuAt7k
  • #10: STM32 in Arduino IDE: https://github.com/stm32duino
  • #11: https://www.electronicwings.com/arduino/digital-gpio-of-arduino Arduino pin are set as digital input (default). 
  • #12: GPIO 20 (6 analog + 16 There are only two external interrupt pins on the ATmega168/328 (ie, in the Arduino Uno/Nano/Duemilanove), INT0 and INT1, and they are mapped to Arduino pins 2 and 3. These interrupts can be set to trigger on RISING or FALLING signal edges
  • #13: https://www.electronicwings.com/arduino/digital-gpio-of-arduino Arduino pin are set as digital input (default). 
  • #14: I²C (Inter-Integrated Circuit), pronounced I-squared-C https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ https://www.circuitbasics.com/basics-of-the-spi-communication-protocol SPI, I2C, and UART are quite a bit slower than protocols like USB, ethernet, Bluetooth, and WiFi, but they’re a lot more simple and use less hardware and system resources. SPI, I2C, and UART are ideal for communication between microcontrollers and between microcontrollers and sensors where large amounts of high speed data don’t need to be transferred.
  • #15: https://www.instructables.com/id/Tutorial-to-Interface-OLED-091inch-128x32-With-Ard/
  • #18: It can be difficult to choose between servo motors and stepper motors as there are so many considerations: cost, torque, efficiency, speed, circuitry and more. Let’s take the a simple DC motor.
  • #19: The L298N main function is to change direction of current, so that we can change the direction of rotation of the motor or simply said if we are going forward or backward. It supports two motors.
  • #21: if (digitalRead(button) == true) checks if the button is pressed while (digitalRead(button) == true); waits until the button is released “Pressed” is not if the button is currently pressed, but it the requested direction. Pressed = requested direction 1 Not pressed == requested direction 0
  • #23: We need to know the number of steps per revolution. We need how many steps of the motor to perform how fast each step is performed. We always advance 2 steps. We control the speed in RPMs. Higher RPMS means that it takes less time a single step to be performed. After each two steps we check if there is a request to increase the speed per step.
  • #26: A microsecond is equal to 1000 nanoseconds or ​1⁄1,000 of a millisecond.
  • #27: For a 16 MHz Arduino the ADC clock is set to 16 MHz/128 = 125 KHz. Each conversion in AVR takes 13 ADC clocks so 125 KHz /13 = 9615 Hz. 9615 Hz is the theoretical maximum. Source: https://arduino.stackexchange.com/questions/699/how-do-i-know-the-sampling-frequency ADCs can vary greatly between microcontroller. The ADC on the Arduino is a 10-bit ADC meaning it has the ability to detect 1,024 (2^10) discrete analog levels. Some microcontrollers have 8-bit ADCs (2^8 = 256 discrete levels) and some have 16-bit ADCs (2^16 = 65,536 discrete levels). Source: https://learn.sparkfun.com/tutorials/analog-to-digital-conversion/all
  • #28: https://www.youtube.com/watch?v=8YaeUYZ_Ex8 Note on Arduino clones: Both chips have a 32-bit processor. The ESP32 is dual core 160MHz to 240MHz CPU whereas the ESP8266 is a single core processor that runs at 80MHz. The ESP32 is the ESP8266 successor. It adds an extra CPU core, faster Wi-Fi, more GPIOs, and supports Bluetooth 4.2 and Bluetooth low energy. Additionally, the ESP32 comes with touch sensitive pins that can be used to wake up the ESP32 from deep sleep, a built-in hall effect sensor and a built-in temperature sensor. Spécifications de la Wemos Lolin D32 Pro based on ESP32 requires driver CH340 for USB connectivity SoC : ESP32-WROVER @ 240MHz avec 4Mo de mémoire 4 Mo et 4Mo de PSRAM Connectivités WiFi 802.11 b/g/n Bluetooth 4.1 LE Stockage : emplacement pour carte micro SD prenant en charge le mode SPI. La capacité maximale n’est pas précisée Connecteurs 1x JST SH 1.0mm 10 broches pour écran TFT