Outils pour utilisateurs

Outils du site


wiki:flossmanuals:un-capteur-une-application:accueil

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
wiki:flossmanuals:un-capteur-une-application:accueil [2021/05/04 04:50]
damien.muti créée
wiki:flossmanuals:un-capteur-une-application:accueil [2021/05/04 05:29] (Version actuelle)
damien.muti
Ligne 20: Ligne 20:
 Le schéma suivant résume la situation : Le schéma suivant résume la situation :
  
-{{ :wiki:flossmanuals:un-capteur-une-application:un_capteur_une_application.png?600 |}}+{{ :wiki:flossmanuals:un-capteur-une-application:un_capteur_une_application.png?800 |}}
  
 +Nous proposons ici de mesurer une distance à l'aide d'un capteur de distance ultrason et de faire varier la couleur d'une forme sous Processing. 
  
 +===== Programme Arduino - Potentiomètre =====
  
-===== Plans et schémas de fonctionnement =====+On utilise un [[wiki:tutoriels:arduino-capteurs:arduino-capteurs#potentiometre|potentiomètre de 10kΩ]].  
 +Le schéma de câblage est le suivant : 
  
  
-===== Programmes ===== +{{ :wiki:flossmanuals:un-capteur-une-application:potentiometre_a0_bb.png?400 |}}
-==== Références Contrôle d’accès par badge RFID avec Arduino ==== +
-Le programme permettant de détecter l'identifiant unique du tag est le suivant [[https://www.electronique-mixte.fr/microcontrolleurs/rfid-controle-dacces-par-badge-avec-arduino/|RFID : Contrôle d’accès par badge avec Arduino]] +
  
 +Le programme Arduino est le suivant : {{ :wiki:flossmanuals:un-capteur-une-application:un_potentiometre_une_application_arduino.zip |}}
  
-===== Réalisation de la maquette ===== +<code> 
-vidéosphotos du making of...+int firstSensor 0;    // first analog sensor 
 +int inByte 0;         // incoming serial byte 
 + 
 +void setup() { 
 +  // start serial port at 9600 bps: 
 +  Serial.begin(9600); 
 +  while (!Serial) { 
 +    ; // wait for serial port to connect. Needed for native USB port only 
 +  } 
 +  establishContact();  // send a byte to establish contact until receiver responds 
 +
 + 
 +void loop() { 
 +  // if we get a valid byte, read analog ins: 
 +  if (Serial.available() > 0) { 
 +    // get incoming byte: 
 +    inByte Serial.read(); 
 + 
 +    // lecture de la valeur du potentiometre branché sur A0  
 +    //et conversion de la valeur en un octet 
 +    firstSensor analogRead(A0)/4; 
 +     
 +    // send sensor values: 
 +    Serial.write(firstSensor); 
 +    
 +  } 
 +
 + 
 +void establishContact() { 
 +  while (Serial.available() <0) { 
 +    Serial.print('A');   // send a capital A 
 +    delay(300); 
 +  } 
 +
 + 
 + 
 + 
 +</code> 
 + 
 +===== Programme Arduino - Ultrasonic ===== 
 + 
 +On utilise un [[wiki:tutoriels:arduino-capteurs:arduino-capteurs#capteur_de_distance_ultrason_grove|capteur de distance Ultrason Ultrasonic en Grove]].  
 +Le schéma de câblage est le suivant :  
 +{{ :wiki:tutoriels:arduino-capteurs:capteur_dist_ultrason_arduino_connection_grove.jpg?400 |}} 
 + 
 +Le capteur Ultrason est branché sur le "slot" D7. 
 + 
 +Le programme Arduino est le suivant : {{ :wiki:flossmanuals:un-capteur-une-application:un_capteur_une_application_arduino.zip |}} 
 + 
 +<code> 
 +#include "Ultrasonic.h" 
 +Ultrasonic ultrasonic(7); 
 +long distance=0; // variable qui stoke la valeur de la distance 
 +int firstSensor 0;    // first analog sensor 
 +int inByte 0;         // incoming serial byte 
 + 
 +void setup() { 
 +  // start serial port at 9600 bps: 
 +  Serial.begin(9600); 
 +  while (!Serial) { 
 +    ; // wait for serial port to connect. Needed for native USB port only 
 +  } 
 +  establishContact();  // send a byte to establish contact until receiver responds 
 +
 + 
 +void loop() { 
 +  // if we get a valid byte, read analog ins: 
 +  if (Serial.available() > 0) { 
 +    // get incoming byte: 
 +    inByte Serial.read(); 
 + 
 +    // lecture de la distance 
 +    distance ultrasonic.MeasureInCentimeters(); 
 +    // conversion de la valeur en un octet 
 +    firstSensor map(distance,0,400,0,255); 
 +     
 +    // send sensor values: 
 +    Serial.write(firstSensor); 
 +    
 +  } 
 +
 + 
 +void establishContact() { 
 +  while (Serial.available() <= 0) { 
 +    Serial.print('A');   // send a capital A 
 +    delay(300); 
 +  } 
 +
 + 
 + 
 +</code> 
 + 
 + 
 + 
 +===== Programme Processing ===== 
 + 
 +**Quel que soit le capteur utilisé**le programme Processing est le suivant : {{ :wiki:flossmanuals:un-capteur-une-application:un_capteur_une_application_processing.zip |}}. On modifie la couleur d'un cercle positionné au centre de la fenêtre d'affichage. 
 + 
 +<code> 
 +import processing.serial.*; 
 + 
 +int bgcolor;      // Background color 
 +int fgcolor;      // Fill color 
 +Serial myPort;                       // The serial port 
 +int serialInArray;    // Where we'll put what we receive 
 +int serialCount = 0;                 // A count of how many bytes we receive 
 +int xpos, ypos;              // Starting position of the ball 
 +boolean firstContact = false;        // Whether we've heard from the microcontroller 
 + 
 +void setup() { 
 +  size(256, 256);  // Stage size 
 +  noStroke();      // No border on the next thing drawn 
 + 
 +  // Set the starting position of the ball (middle of the stage) 
 +  xpos = width/2; 
 +  ypos = height/2; 
 + 
 +  // Print a list of the serial ports, for debugging purposes: 
 +  printArray(Serial.list()); 
 + 
 +  // I know that the first port in the serial list on my mac 
 +  // is always my  FTDI adaptor, so I open Serial.list()[0]. 
 +  // On Windows machines, this generally opens COM1. 
 +  // Open whatever port is the one you're using. 
 +  String portName = Serial.list()[0]; 
 +  myPort = new Serial(this, portName, 9600); 
 +   
 +  // espace HSB des couleurs 
 +  colorMode(HSB); 
 +
 + 
 +void draw() { 
 +  background(bgcolor); 
 +  fill(fgcolor,255,255); 
 +  // Draw the shape 
 +  circle(xpos, ypos, 50); 
 +
 + 
 +void serialEvent(Serial myPort) { 
 +  // read a byte from the serial port: 
 +  int inByte = myPort.read(); 
 +  // if this is the first byte received, and it's an A, 
 +  // clear the serial buffer and note that you've 
 +  // had first contact from the microcontroller.  
 +  // Otherwise, add the incoming byte to the array: 
 +  if (firstContact == false) { 
 +    if (inByte == 'A') {  
 +      myPort.clear();          // clear the serial port buffer 
 +      firstContact = true;     // you've had first contact from the microcontroller 
 +      myPort.write('A');       // ask for more 
 +    } 
 +  } else { 
 +    // Add the latest byte from the serial port to array: 
 +    fgcolor = inByte; // remplir la donnée "utile" 
 +    // print the values (for debugging purposes only): 
 +    println("valeur lue sur le port Série = " +  fgcolor); 
 + 
 +    // Send a capital A to request new sensor readings: 
 +    myPort.write('A'); 
 +    // Reset serialCount: 
 +  } 
 +
 +</code>
  
wiki/flossmanuals/un-capteur-une-application/accueil.1620096630.txt.gz · Dernière modification: 2021/05/04 04:50 de damien.muti