Post on 16-Feb-2019
Universidade Federal do ParanaDepartamento de Informática
Oficina Arduino Robótica
Prof. Eduardo Todt2018
Introdução
● Arduino– Plataforma hw+sw
– Open source
– Microcontrolador e/s digital e analogica
– C e C++, objetos
História
● Dissertação mestrado colombiano Hernando Barragán ● Interaction Design Institute Ivrea, Italia, 2004● Supervisores: Massimo Banzi e Casey Reas (Processing, MIT
2001)● Resultado dissertação:
– Wiring● Open source sw+hw● IDE baseada na IDE Processing.org● Programas “sketches”● Cadeia completa de prototipação transparente ao usuário● Bootloader
pinMode()
digitalRead()
digitalWrite()
analogRead()
analogWrite()
delay()
Millis()
...
Protótipos Wiring
FTDI232BM for serial to USB
MAVRIC board, ATmega128
Atmel AT91R40008
https://arduinohistory.github.io/
Nasce o Arduino
● IDII monta 100 placas Wiring (2004)– Sucesso em trabalhos páticos
– 2005, Barragán monta 200 placas
– 2005, Banzi, Mellis (aluno) e Cuartilles
● ATmega8● Fork do Wiring para Arduino ● Zambetti (colega de Mellis), Martino (SERP), Igoe (NYU) se
unem ao Arduino Team
https://arduinohistory.github.io/
Conflitos
● Falta de reconhecimento autoria original– Wiring, Barragán
● Fundadores plataforma Arduino– Arduino LCC
● arduino.cc● Marca Genoino fora dos EUA
● Produtores placas– Arduino S.r.l.
● arduino.org
Energizando a placa
● Via USB● Via Adaptador AC/DC, 7V a 12V (embora até
funciona com 6 a 20, ou não fornece 5V nos pinos de saída ou sobreaquece)
● Pinos de 5V e 3.3V (max. 50mA) são para alimentar outras coisas conectadas, não é para ligar fonte
Conectando coisas
● LEDs, pequenos circuitos até 20mA @ 5V pode ligar direto nos pinos de I/O, considerando que não há isolamento elétrico.O que significa isto? Como se consegue isto se for necessário?
● Consumo ou tensão maior que isto necessita transistor ou relé
● Motores DC o modo mais simples de controlar velocidade é PWM e ponte H, ex. L298
LDR
/*** Nightlight LDR test program** Created 06 Feb 2010**** This example code is in the public domain.** www.hobbytronics.co.uk*/int sensorPin = A0; // select the input pin for the ldrunsigned int sensorValue = 0; // variable to store the value coming from the ldrvoid setup(){ pinMode(13, OUTPUT); //Start Serial port Serial.begin(9600); // start serial for output - for testing}void loop(){ // read the value from the ldr: sensorValue = analogRead(sensorPin); if(sensorValue<400) digitalWrite(13, HIGH); // set the LED on else digitalWrite(13, LOW); // set the LED on // For DEBUGGING - Print out our data, uncomment the lines below //Serial.print(sensorValue, DEC); // print the value (0 to 1024) //Serial.println(""); // print carriage return //delay(500); }
http://www.hobbytronics.co.uk/arduino-tutorial8-nightlight
Ponte H
http://www.st.com/content/st_com/en/products/motor-drivers/brushed-dc-motor-drivers/l298.html
Módulo com L298
1 DC motor 1 "+" or stepper motor A+
2 DC motor 1 "-" or stepper motor A-
3 12V jumper - remove this if using a supply voltage greater than 12V DC. This enables power to the onboard 5V regulator4 Connect your motor supply voltage here, maximum of 35V DC. Remove 12V jumper if >12V DC
5 GND
6 5V output if 12V jumper in place, ideal for powering your Arduino (etc)
7 DC motor 1 enable jumper. Leave this in place when using a stepper motor. Connect to PWM output for DC motor speed control.
8 IN1 set with IN2 negated to define Motor A movement direction.
9 IN2
10 IN3 set with IN4 negated to define Motor B movement direction.
11 IN4
12 DC motor 2 enable jumper. Leave this in place when using a stepper motor. Connect to PWM output for DC motor speed control.
13 DC motor 2 "+" or stepper motor B+
14 DC motor 2 "-" or stepper motor B-
IDE
● A ideia diferencial do Arduino é usar o IDE
● baixar de https://www.arduino.cc (2.1.0.5 em dez 2018) ou sudo apt install arduino
– Descompactar
– ignore install.sh
– Mais simples usar USB
– precisa acesso privilegiado● sudo ./arduino
– Conectar placa, com lsusb aparece com o IDdo CI USB (2341:0043)
#define LEDg 11#define LEDy 12#define LEDr 13
void setup() { // initialize digital pins pinMode(LEDg, OUTPUT); pinMode(LEDy, OUTPUT); pinMode(LEDr, OUTPUT);
digitalWrite(LEDg, HIGH); digitalWrite(LEDy, HIGH); digitalWrite(LEDr, HIGH); }
void loop() { digitalWrite(LEDr, LOW); delay(8000); digitalWrite(LEDr, HIGH); digitalWrite(LEDg, LOW); delay(3000); digitalWrite(LEDg, HIGH); digitalWrite(LEDy, LOW); delay(1000); digitalWrite(LEDy, HIGH); }
Sonar#define TRIGGER1 9#define ECHO1 8
void setup() { Serial.begin(9600); pinMode(TRIGGER1,OUTPUT); pinMode(ECHO1, INPUT); digitalWrite(TRIGGER1, LOW);}
unsigned long ping() { unsigned int retVal; digitalWrite(TRIGGER1, HIGH); delayMicroseconds(10); // Wait for 10 microseconds digitalWrite(TRIGGER1, LOW); retVal = pulseIn(ECHO1, HIGH,58000); // dist= ret[us]/58 [cm], timeout=10m, retorna 0 se timeout retVal = retVal /58;
return retVal;}
void loop() { int x = 0; x = ping(); Serial.println(x); delay(500); //delay 1/2 seconds.}
https://www.arduino.cc/en/Reference/Board
#define enA 9#define in1 6#define in2 7
int rotDirection = 0;char pwmOutput = 0;
void setup() { pinMode(enA, OUTPUT); pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); digitalWrite(in1, LOW); digitalWrite(in2, HIGH); pwmOutput = 40;}
void loop() {
analogWrite(enA, pwmOutput);
}
Encodersvoid setup(){ pinMode(E_M_PWM,OUTPUT); pinMode(E_M_EN, OUTPUT); pinMode(D_M_PWM,OUTPUT); pinMode(D_M_EN, OUTPUT);
pinMode(EncRa, INPUT); pinMode(EncRb, INPUT); pinMode(EncLa, INPUT); pinMode(EncLb, INPUT); attachInterrupt(0,encoderR,RISING); attachInterrupt(1,encoderL,RISING); Serial.begin(115200); Serial.println("Basic Encoder Test:"); E_velocidade = 150; D_velocidade = 150; //motores(); }
void encoderR(){ if (digitalRead(EncRa) == digitalRead(EncRb)){ positionR++; } else { positionR--; } }
void encoderL(){ if (digitalRead(EncLa) == digitalRead(EncLb)){ positionL++; } else { positionL--; } }