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

Tools → Serial Monitor

Tools → Serial Plotter

pins: RX←0, TX→1

Start(0) - Bit 0 - Bit 1 - Bit 2 - Bit 3 - Bit 4 - Bit 5 - Bit 6 - Bit 7 - Stop (1)

    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

pins: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13

    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

pins: A0, A1, A2, A3, A4, A5
multichannel, 10-bit ADC
map input voltages between 0 and 5V into integer values between 0 and 1023
Resolution: 5V/1024 bit= 0.0048828125 V/bit ≅ 4.9 mV

GND + LDR + Analog PIN + 10 KΩ + 5V

POTENTIOMETER (GND +Outside LEAD + Middle TERMINAL + Analog PIN +Outside TERMINAL + 5V)

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

PWM output

pins: ∼3, ∼5, ∼6, ∼9

PWM (Pulse Width Modulation)
analogWrite(255) = 100% duty cycle = 5 V
analogWrite(127) = 50% duty cycle
analogWrite(0) = 0% duty cycle = 0 V

  • 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
    }
    


Processing code

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

    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-
    +5V Resistor(220Ω) A(LED)K GND
    +5V Resistor(10-47kΩ) c(photoTransistor)e GND DIGITAL
    Analog input(A0) c(photoTransistor)e
    A  e
    K  c   Marking area
    Applications: linefollower bot,  
    proximity sensor with sensing presence
    */
    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
    Applications: automatic contrast and brightness in TV
    Automatic street light control 
    light failure alarm
    light meter
    */
    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);
    }