technology

    Arduino:
  • Prototype platform
    • Hardware: circuit board with a microcontroller
    • Software: Arduino IDE
    Arduino / Genuino 101
  • It has the same pin configuration as the Arduino UNO
  • Intel® Curie™
    • Intel® Quark™ SE Microcontroller C1000: 32 MHz, 32-bit address bus, 8 kb 2-way L1 instruction cache
    • Sensor: ARC* EM4 DSP core with FPU + 8 kB L1 instruction cache + 8 kB data CCM
    • 2-I2C master + 2 SPI master + 19 chanel 12-bit ADC + 16 GPIOs + 2 timers
    • 1.8V/3.3V LDO
    • BLE
    • 6-Axis Accelerometer/Gyroscope
    • Pattern Matching Accelerator
    • Battery Charger (Optional)
    • Memory: 384 kB Flash + 8 kbOTP Flash + 80 kB SRAM
IDE (Integrated Development Environment)
LDO (Low-DropOut linear voltage regulator)
BLE (Bluetooth Low Energy)
FPU (Floating Point Unit)
CCM (Counter with CBC-MAC)
CBC-MAC (Cipher Block Chaining Massage Authentication Code)
DSP (Digital Signal Processor)
ADC (Analog to Digital Converter)
DAC (Digital to Analog Converter)
I2C (Inter-Integrated Circuit) bus
SPI (Serial Peripheral Interface)
GPIO (General-Purpose Input/Output)

Arduino IDE

    • Arduino IDE
    • Cross-platform application (Windows, macOS, Linux)
    • Write and upload programs to Arduino board
    • It is written in Java
    • Software library from Wiring
    • Supports the languages C and C++
      Wiring
    • Electronics prototyping platform
    • Programming language : dialect of C and C++
    • IDE written in Java
    • Single-board microcontroller
    • Wiring builds on Processing
      Processing
    • Graphical library and IDE / playground
    • It uses Java
    • built for:
      • Electronic arts
      • New media art
      • Visual design
      • Learning
      • Prototyping
      Java
    • General-purpose programming language
    • Concurrent (not sequentially), class-based, object-oriented
    • Compiled to bytecode that can run on any JVM (Java Virtual Machine)
    • Derived from C and C++
      C++
    • General-purpose programming language
    • Imperative
    • Object-oriented (data -attributes- and code -procedures, methods-)
      C
    • General-purpose programming language
    • Imperative (how achive the result: statements -commands- that change a program's state)
    • NOT a declarative (what should accomplish)
    • procedural (subroutines or functions)

Arduino/Genuino 101 offline

    Install Arduino Desktop IDE
  • Download Arduino 1.8.8 IDE 
    Choose:
                  Windows Installer
                  Windows ZIP
                  Windows app
    
                   Mac OS X 
                    
                    Linux 32 bits
                    Linux 64 bits
                    Linux ARM
    
    Install Intel Curie Core
  • Tools
    Board
              Boards Manager...
                   Arduino AVR Boards Built-In by Arduino version 1.6.23 INSTALLED
                   Intel Curie Boards by Intel version 2.0.2
    -----------------------------------------------
    Manual Instalation:
    Documents → ArduinoData → packages → Intel → hardware → arc32 → 2.0.2 → drivers
    dpinst-amd64.exe or dpinst-x86.exe
    If it doesn't work: press every second MASTER RESET
    
    Select board type + port
  • Tools
    Board
               Arduino/Genuino 101
    Port
             COM3 (Arduino/Genuino 101)  
    
    Program or open a sketch
  • File
          New
          Open...
          Open Recent 
          Sketchbook
          Examples
    
    Upload the program
  • Press the second round icon with the right arrow (→)
                         or
                  Sketch → Upload
                        or
                     Ctrl + U
    



Arduino IDE code

    Bare Minimum
  • void setup() {
     /* to run once:
         initialize variables
         pin modes
         set the serial baud rate
    */
    }
    
    void loop() {
      // to run repeatedly
      //main code
    }
    //void subroutinename() {}
    

Serial Communication

    Arduino → PC
  • void setup()
    {
      Serial.begin(9600);
    }
     
    void loop()
    {
      Serial.print(65);// Serial.print(65,DEC); 
       //Serial.println(65);// Serial.print(65,DEC)+"carriage return";  
      // Serial.println(65,HEX);
      // Serial.println(65,OCT);
      // Serial.println(65,BIN);
      // Serial.write(65);// Serial Monitor print "A" ASCII of 65
    }
    
    PC → Arduino
  • void setup()
    {
      Serial.begin(9600);
    }
     
    void loop()
    {
      if(Serial.available()>0) 
      {
        int data=Serial.read();  
        Serial.println(data); Serial Monitor print a decimal number
        // Serial.write(dato);Serial Monitor print an ASCII
      }
    }
    

Digital input/output

    Digital input
  •  // pushbutton connected to digital pin 2 + pulldown resistor 10kΩ to GND
    int inPin = 2;    
    int val = 0;   
    
    void setup()
    {
      pinMode(inPin, INPUT);  
    }
    
    void loop()
    {
      val = digitalRead(inPin);   
    }
    
    Digital Output
  • int ledPin = 13;   // LED_BUILTIN
    
    void setup()
    {
      pinMode(ledPin, OUTPUT);      
    }
    
    void loop()
    {
      digitalWrite(ledPin, HIGH);    // value: HIGH or LOW
    }
    

Analog input

    Analog input
  • int analogPin = A0;                            
    int val = 0;  
    
    void setup()
    {
      Serial.begin(9600);    
    }
    
    void loop()
    {
      val = analogRead(analogPin); 
      Serial.println(val);  
    }
    

PWM output

  • int ledPin = 13;  
    int analogPin = 3;   // potentiometer connected to analog pin 3
    int val = 0;  
    
    void setup()
    {
      pinMode(ledPin, OUTPUT);  
    }
    
    void loop()
    {
      val = analogRead(analogPin);  //from 0 to 1023
      analogWrite(ledPin, val / 4); // from 0 to 255
    }
    

Sensors

LDR

    LDR: Light-Dependent Resistor
  • /*
    +5V + PullUp Resistor(1 KΩ) + Analog INPUT(A0)+LDR+GND
    */
    int analogPin = 0;  
    int val;
    int led=13;
     
    void setup()
    {
      Serial.begin(9600);
    }
     
    void loop()
    {
      val= analogRead(analogPin);
      Serial.println(val);
    
      if (val>500){
         digitalWrite(led, HIGH);
      } else {
        digitalWrite(led, LOW);
      }
      delay(200);
    }
    

Ultrasonic Sensor: HC-SR04

    Ultrasonic Sensor: HC-SR04
  • /* 
    HC-SR04
    Vcc Trig Echo Gnd
    velocity of sound =343 m/s = 0.0343 cm / us
    humidity = 50 %
    temperature = 20 ºC
    speed of sound = distance / time;
    */
    
     
    #define trigger 9  
    #define echo 8
     
    int distance;  
    float time; 
     
    void setup()
    {
      Serial.begin(9600); 
      pinMode(trigger, OUTPUT);
      pinMode(echo, INPUT); 
    }
     
    void loop()
    {
      digitalWrite(trigger,LOW);
      delayMicroseconds(5);
      digitalWrite(trigger, HIGH); 
      delayMicroseconds(10);
      time = pulseIn(echo, HIGH);  
      distance = 0.01715*time; 
       
      Serial.print("Distance: ");
      Serial.print(distance);
      Serial.println(" cm");
      delay(2000);
    }
    

Humidity-Temperature sensor: DHT22

    Humidity-Temperature sensor: DHT22
  • /*
    DHT22
    Vcc Data NC   Gnd
    
    Vcc -10 K-Data
    pin 5-Data
    5V-Vcc
    GND -Gnd
    */
    #include "DHT.h"
    #define DHTPIN 2     
    #define DHTTYPE DHT22
    int h;
    float t,f,hi;  
     
    DHT dht(DHTPIN, DHTTYPE);
     
    void setup() { 
      Serial.begin(9600); 
      dht.begin();
     }
     
    void loop() {
      h = dht.readHumidity();
      t = dht.readTemperature();
      f = dht.readTemperature(true);
     
      if (isnan(h) || isnan(t) || isnan(f)) {
        Serial.println("Failed to read from DHT sensor!");
        return;
        }
     
      hi = dht.computeHeatIndex(f, h);
    
      Serial.print("Humidity: ");
      Serial.print(h);
      Serial.print(" Temperature: ");
      Serial.print(t);
      Serial.print(" HeatIndex: ");
      Serial.println(hi);
      delay(500);      
      }
    


Processing code

    To control an Arduino board from Processing program
    • Arduino IDE
    • file →examples → Firmadata → StandardFirmadata
    • Sketch → Upload
      Processing IDE
    • Download this library:
      • processing-arduino
    • Copy this library into Documents → Processing → libraries
    • arduino.jar must be in libraries
  • This how your document folder must be:
    • Documents
    • Processing
      libraries
      arduino
      arduino.jar

    Writing : Processing → Arduino Board
  • import processing.serial.*; 
    import cc.arduino.*;
    
    Arduino arduino;
    int led=13;
    float x = 50;
    float y = 50;
    float w = 50;
    float h = 50;
    
    void setup(){
     arduino = new Arduino(this, Arduino.list()[0], 9600);
     arduino.pinMode(led, Arduino.OUTPUT);
     size(640,480);
     background(127);
     stroke(0);
     noFill();
    }
    
    void draw(){
     background(127);
     PFont  f = createFont("Arial",16,true); 
     textFont(f, 20);
     rect(x,y,w,h);
     fill(255,0,0);
     if(mousePressed){
      if(mouseX>x && mouseX <x+w && mouseY>y && mouseY <y+h){
        arduino.digitalWrite(led,Arduino.HIGH);
        fill(0,255,0);
        text ("ON", 75, 125);
        println("The mouse is pressed and over");    
      }
     }
     if (!mousePressed) { 
        arduino.digitalWrite(led,Arduino.LOW);
        text ("OFF", 75, 125);
        println("The mouse is no pressed");
        }
    }
    
    Reading: Arduino Board → Processing
  • /*
    +5V  PullUp Resistor(1 KΩ)  Analog INPUT(A0) LDR GND
    */
    import processing.serial.*; 
    import cc.arduino.*;
    
    Arduino arduino;
    
    int analogPin = 0;  
    int val;
    
    void setup(){
     arduino = new Arduino(this, Arduino.list()[0], 9600);
     size(640,480);
     background(127);
     stroke(0);
     noFill();
    }
    
    void draw(){
     background(127);
     PFont  f = createFont("Arial",24,true);
     textFont(f);
     
     val=arduino.analogRead(analogPin);
     
     text("LDR =",100,100);
     text(val, 200, 100);
     fill(255,255,0);
     delay(100);
    }
    
    Reflective Optical Sensor with Transistor Output
  • /*
    CNY70
    A  e
    K  c   Marking area
    +5V Resistor(220Ω) A(LED)K GND
    +5V Resistor(10-47kΩ) c(photoTransistor)e GND DIGITAL
    Analog input(A0) c(photoTransistor)e
    */
    import processing.serial.*; 
    import cc.arduino.*;
    
    Arduino arduino;
    int led=13;
    int analogPin = 0;  
    int val;
    int count=0;
    color c;
    
    void setup(){
     arduino = new Arduino(this, Arduino.list()[1], 9600);
     arduino.pinMode(led, Arduino.OUTPUT);
     size(640,480);
     background(127);
     stroke(0);
     noFill();
    }
    
    void draw(){
     background(127);
     PFont  f = createFont("Arial",24,true);
     textFont(f);
     
     val=arduino.analogRead(analogPin);
     if (val<500) {
        arduino.digitalWrite(led,Arduino.HIGH);
        c=#00FF00;
     } else {
       arduino.digitalWrite(led,Arduino.LOW);
       c=#FF0000;
     }
     fill(c);
     ellipse(width/2,height/2,50,50);
     fill(255,255,0);
     text("octo =",100,100);
     text(val, 200, 100);
     delay(200);
    }
    
    LDR: Light-Dependent Resistor
  • /*
    +5V + PullUp Resistor(1 KΩ) + Analog INPUT(A0)+LDR+GND
    */
    import processing.serial.*; 
    import cc.arduino.*;
    
    Arduino arduino;
    int x=0;
    int analogPin = 0;  
    int val;
    int led=13;
    
    void setup(){
      arduino = new Arduino(this, Arduino.list()[0], 9600);
      arduino.pinMode(led, Arduino.OUTPUT);
      size(640,480);
      background(127);
      stroke(0);
      noFill();
    }
    
    void draw(){
      background(127);
      PFont  f = createFont("Arial",24,true);
      textFont(f);
     
      val=arduino.analogRead(analogPin);
      strokeWeight(4);
      text("LDR ="+val,100,100);
      println(val);
     
      fill(0,255,255);
      text("*",x,val/2);
      x++;
      if (x>500) {x=0;}
      if (val>500){
         arduino.digitalWrite(led,Arduino.HIGH);
      } else {
        arduino.digitalWrite(led,Arduino.LOW);
     }
     fill(255,255,0);
     delay(100);
    }