Commit a4d8559504eaa39119953665083ac7b921725f49

Authored by aknockae
1 parent 4253d3b7

Ajout de serialArduino, code permettant à l'arduino de communiquer en série. Uti…

…lisé avec le programme regroupant websockets et communication série
code_arduino/Test IMA3 P2/bme280test/bme280test.ino 0 → 100644
... ... @@ -0,0 +1,83 @@
  1 +/***************************************************************************
  2 + This is a library for the BME280 humidity, temperature & pressure sensor
  3 +
  4 + Designed specifically to work with the Adafruit BME280 Breakout
  5 + ----> http://www.adafruit.com/products/2650
  6 +
  7 + These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  8 + to interface. The device's I2C address is either 0x76 or 0x77.
  9 +
  10 + Adafruit invests time and resources providing this open source code,
  11 + please support Adafruit andopen-source hardware by purchasing products
  12 + from Adafruit!
  13 +
  14 + Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  15 + BSD license, all text above must be included in any redistribution
  16 + ***************************************************************************/
  17 +
  18 +#include <Wire.h>
  19 +#include <SPI.h>
  20 +#include <Adafruit_Sensor.h>
  21 +#include <Adafruit_BME280.h>
  22 +
  23 +#define BME_SCK 13
  24 +#define BME_MISO 12
  25 +#define BME_MOSI 11
  26 +#define BME_CS 10
  27 +
  28 +#define SEALEVELPRESSURE_HPA (1013.25)
  29 +
  30 +//Adafruit_BME280 bme; // I2C
  31 +//Adafruit_BME280 bme(BME_CS); // hardware SPI
  32 +Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
  33 +
  34 +unsigned long delayTime;
  35 +
  36 +void setup() {
  37 + Serial.begin(9600);
  38 + Serial.println(F("BME280 test"));
  39 +
  40 + bool status;
  41 +
  42 + // default settings
  43 + status = bme.begin();
  44 + if (!status) {
  45 + Serial.println("Could not find a valid BME280 sensor, check wiring!");
  46 + while (1);
  47 + }
  48 +
  49 + Serial.println("-- Default Test --");
  50 + delayTime = 1000;
  51 +
  52 + Serial.println();
  53 +
  54 + delay(100); // let sensor boot up
  55 +}
  56 +
  57 +
  58 +void loop() {
  59 + printValues();
  60 + delay(delayTime);
  61 +}
  62 +
  63 +
  64 +void printValues() {
  65 + Serial.print("Temperature = ");
  66 + Serial.print(bme.readTemperature());
  67 + Serial.println(" *C");
  68 +
  69 + Serial.print("Pressure = ");
  70 +
  71 + Serial.print(bme.readPressure() / 100.0F);
  72 + Serial.println(" hPa");
  73 +
  74 + Serial.print("Approx. Altitude = ");
  75 + Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  76 + Serial.println(" m");
  77 +
  78 + Serial.print("Humidity = ");
  79 + Serial.print(bme.readHumidity());
  80 + Serial.println(" %");
  81 +
  82 + Serial.println();
  83 +}
... ...
code_arduino/Test IMA3 P2/test/test.ino 0 → 100644
... ... @@ -0,0 +1,36 @@
  1 +/* Utilisation du capteur Ultrason HC-SR04 */
  2 +
  3 +// définition des broches utilisées
  4 +int trig1 = 7;
  5 +int echo1 = 6;
  6 +
  7 +int trig2 = 8;
  8 +int echo2 = 5;
  9 +long lecture_echo;
  10 +long cm;
  11 +
  12 +void setup()
  13 +{
  14 + pinMode(trig1, OUTPUT);
  15 + digitalWrite(trig1, LOW);
  16 + pinMode(echo1, INPUT);
  17 +
  18 + pinMode(trig2, OUTPUT);
  19 + digitalWrite(trig2, LOW);
  20 + pinMode(echo2, INPUT);
  21 + Serial.begin(9600);
  22 +}
  23 +
  24 +void loop()
  25 +{
  26 + digitalWrite(trig1, HIGH);
  27 + digitalWrite(trig2, HIGH);
  28 + delayMicroseconds(10);
  29 + digitalWrite(trig1, LOW);
  30 + digitalWrite(trig2, LOW);
  31 + lecture_echo = pulseIn(echo2, HIGH);
  32 + cm = lecture_echo / 58;
  33 + Serial.print("Distancem : ");
  34 + Serial.println(cm);
  35 + delay(500);
  36 +}
... ...
code_arduino/Test IMA3 P2/testCapteur/testCapteur.ino 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 + #include "Adafruit_BME280.h"
  2 + #include "Adafruit_Sensor.h"
  3 + //Library allows either I2C or SPI, so include both.
  4 + #include "Wire.h"
  5 + #include "SPI.h"
  6 +
  7 + BME280 capteur;
  8 +
  9 + void setup() {
  10 +
  11 + Serial.begin(9600);
  12 + while (!Serial) {
  13 + // Attente de l'ouverture du port série pour Arduino LEONARDO
  14 + }
  15 + //configuration du capteur
  16 + capteur.settings.commInterface = I2C_MODE;
  17 + capteur.settings.I2CAddress = 0x76;
  18 + capteur.settings.runMode = 3;
  19 + capteur.settings.tStandby = 0;
  20 + capteur.settings.filter = 0;
  21 + capteur.settings.tempOverSample = 1 ;
  22 + capteur.settings.pressOverSample = 1;
  23 + capteur.settings.humidOverSample = 1;
  24 +
  25 + Serial.println("Starting BME280... ");
  26 + delay(10); // attente de la mise en route du capteur. 2 ms minimum
  27 + // chargement de la configuration du capteur
  28 + capteur.begin();
  29 + }
  30 +
  31 + void loop() {
  32 + Serial.print("Température: ");
  33 + Serial.print(capteur.readTempC(), 2);
  34 + Serial.print(" °C");
  35 + Serial.print("\t Pression: ");
  36 + Serial.print(capteur.readFloatPressure(), 2);
  37 + Serial.print(" Pa");
  38 + Serial.print("\t humidité relative : ");
  39 + Serial.print(capteur.readFloatHumidity(), 2);
  40 + Serial.println(" %");
  41 + delay(1000);
  42 + }
... ...
code_arduino/com_Xbee/code_emetteur/sketch_may02a.ino 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +/* Input-side (button) Arduino code */
  2 +#include <SoftwareSerial.h>
  3 +// RX: Arduino pin 2, XBee pin DOUT. TX: Arduino pin 3, XBee pin DIN
  4 +SoftwareSerial xBee(2, 3);
  5 +
  6 +void setup()
  7 +{
  8 + // Baud rate MUST match XBee settings (as set in XCTU)
  9 + xBee.begin(9600);
  10 +}
  11 +
  12 +void loop()
  13 +{
  14 +
  15 + xBee.write('H');
  16 + xBee.println("test");
  17 + delay(500);
  18 + xBee.write('L');
  19 +}
  20 +
... ...
code_arduino/com_Xbee/code_receveur/receveurXbee.ino 0 → 100644
... ... @@ -0,0 +1,33 @@
  1 +/* Output-side (LED) Arduino code */
  2 +#include "SoftwareSerial.h"
  3 +// RX: Arduino pin 2, XBee pin DOUT. TX: Arduino pin 3, XBee pin DIN
  4 +SoftwareSerial XBee(0, 1);
  5 +int LED = 13;
  6 +
  7 +void setup()
  8 +{
  9 + // Baud rate MUST match XBee settings (as set in XCTU)
  10 + XBee.begin(9600);
  11 + pinMode(LED, OUTPUT);
  12 +}
  13 +
  14 +void loop()
  15 +{
  16 + if (XBee.available())
  17 + {
  18 + char c = XBee.read();
  19 + if (c == 'H')
  20 + {
  21 + digitalWrite(LED, HIGH);
  22 + delay(50);
  23 + }
  24 + else
  25 + {
  26 + digitalWrite(LED, LOW);
  27 + }
  28 + }
  29 + else
  30 + {
  31 + digitalWrite(LED, LOW);
  32 + }
  33 +}
... ...
code_arduino/com_Xbee/progC_initialisation_Xbee/Makefile 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +#
  2 +# Makefile de l'utilitaire XBee
  3 +#
  4 +
  5 +OBJS = xbee.o xbeeATCmd.o
  6 +
  7 +#
  8 +# Cible generale
  9 +#
  10 +
  11 +all: xbee
  12 +
  13 +#
  14 +# La cible de nettoyage
  15 +#
  16 +
  17 +clean:
  18 + rm -f core *.o xbee
  19 +
  20 +#
  21 +# Les cibles pour l'executable
  22 +#
  23 +
  24 +xbee: $(OBJS)
  25 + $(CC) $(CFLAGS) -o xbee $(OBJS)
  26 +
  27 +xbeeATCmd.o: xbeeATCmd.c xbeeATCmd.h
... ...
code_arduino/com_Xbee/progC_initialisation_Xbee/xbee 0 → 100644
No preview for this file type
code_arduino/com_Xbee/progC_initialisation_Xbee/xbee.c 0 → 100644
... ... @@ -0,0 +1,96 @@
  1 +/** fichier xbee.c **/
  2 +
  3 +/*****************************************************************/
  4 +/** Utilitaire pour configurer les modules XBee. **/
  5 +/*****************************************************************/
  6 +
  7 +/** Fichiers d'inclusion **/
  8 +
  9 +#include <stdio.h>
  10 +#include <stdlib.h>
  11 +#include <string.h>
  12 +#include <unistd.h>
  13 +#include <termios.h>
  14 +#include <netdb.h>
  15 +#include <netinet/in.h>
  16 +#include <sys/types.h>
  17 +#include <sys/stat.h>
  18 +#include <fcntl.h>
  19 +
  20 +#include "xbeeATCmd.h"
  21 +
  22 +/** Constantes **/
  23 +
  24 +#define SERIALDEV "/dev/ttyUSB0"
  25 +#define BAUDRATE B9600
  26 +
  27 +/**** Variables globales *****/
  28 +
  29 +static struct termios sauvegarde;
  30 +
  31 +/** Ouverture d'un port serie **/
  32 +
  33 +int ouvertureSerie(char *periph,int vitesse)
  34 +{
  35 +struct termios nouveau;
  36 +int df=open(periph,O_RDWR|O_NOCTTY);
  37 +if(df<0) return -1;
  38 +
  39 +tcgetattr(df,&sauvegarde); /* save current port settings */
  40 +bzero(&nouveau,sizeof(nouveau));
  41 +nouveau.c_cflag=CLOCAL|CREAD|vitesse|CS8;
  42 +nouveau.c_iflag=0;
  43 +nouveau.c_oflag=0;
  44 +nouveau.c_lflag=0;
  45 +nouveau.c_cc[VTIME]=0;
  46 +nouveau.c_cc[VMIN]=1;
  47 +tcflush(df, TCIFLUSH);
  48 +tcsetattr(df,TCSANOW,&nouveau);
  49 +
  50 +return df;
  51 +}
  52 +
  53 +/** Fermeture d'un port serie **/
  54 +
  55 +void fermetureSerie(int df)
  56 +{
  57 +tcsetattr(df,TCSANOW,&sauvegarde);
  58 +close(df);
  59 +}
  60 +
  61 +/** Programme principal **/
  62 +
  63 +int main(int argc, char *argv[])
  64 +{
  65 +
  66 +int ds;
  67 +ds=ouvertureSerie(SERIALDEV,BAUDRATE);
  68 +if(ds<0){
  69 + fprintf(stderr,"Erreur sur la connexion série.\n");
  70 + exit(-1);
  71 + }
  72 +
  73 +fprintf(stdout,"Configuration actuelle :\n");
  74 +fprintf(stdout,"----------------------\n");
  75 +xbeeModeCommande(ds);
  76 +xbeeRecupereVitesse(ds);
  77 +xbeeRecupereCanal(ds);
  78 +
  79 +fprintf(stdout,"\nConfiguration par défaut :\n");
  80 +fprintf(stdout,"------------------------\n");
  81 +xbeeDefaut(ds);
  82 +xbeeRecupereVitesse(ds);
  83 +xbeeRecupereCanal(ds);
  84 +
  85 +fprintf(stdout,"\nConfiguration spécifique :\n");
  86 +fprintf(stdout,"------------------------\n");
  87 +xbeeConfigureVitesse(ds,XBEE_VITESSE_9600);
  88 +xbeeConfigureCanal(ds,0x0B);
  89 +xbeeRecupereVitesse(ds);
  90 +xbeeRecupereCanal(ds);
  91 +xbeeSauver(ds);
  92 +xbeeSortir(ds);
  93 +
  94 +fermetureSerie(ds);
  95 +return EXIT_SUCCESS;
  96 +}
... ...
code_arduino/com_Xbee/progC_initialisation_Xbee/xbee.o 0 → 100644
No preview for this file type
code_arduino/com_Xbee/progC_initialisation_Xbee/xbeeATCmd.c 0 → 100644
... ... @@ -0,0 +1,132 @@
  1 +/** fichier xbeeATCmd.c **/
  2 +
  3 +/*****************************************************************/
  4 +/** Commandes pour configurer les modules XBee. **/
  5 +/*****************************************************************/
  6 +
  7 +/** Fichiers d'inclusion **/
  8 +
  9 +#include <stdio.h>
  10 +#include <stdlib.h>
  11 +#include <string.h>
  12 +#include <unistd.h>
  13 +
  14 +/** Constantes **/
  15 +
  16 +#define TAILLE_TAMPON 128
  17 +
  18 +/** Fonctions **/
  19 +
  20 +void xbeeReponse(int ds)
  21 +{
  22 +register int i;
  23 +char d[TAILLE_TAMPON];
  24 +sync();
  25 +for(i=0;i<TAILLE_TAMPON;i++){
  26 + if(read(ds,d+i,1)!=1){ perror("xbeeReponse.read"); exit(-1); }
  27 + if(d[i]==0x0d) break;
  28 + }
  29 +int size=i;
  30 +for(i=0;i<size;i++)
  31 + if(d[i]!=0x0d) fprintf(stdout,"%c",d[i]);
  32 +if(size>0) fprintf(stdout," (");
  33 +for(i=0;i<size;i++){
  34 + fprintf(stdout,"%.2x",d[i]);
  35 + if(i<size-1) fprintf(stdout," ");
  36 + }
  37 +if(size>0) fprintf(stdout,")\n");
  38 +}
  39 +
  40 +void xbeeDefaut(int ds)
  41 +{
  42 +#ifdef DEBUG
  43 +printf("{xbeeDefaut}\n");
  44 +#endif
  45 +char* d="ATRE\r";
  46 +write(ds,d,strlen(d));
  47 +xbeeReponse(ds);
  48 +}
  49 +
  50 +void xbeeSauver(int ds)
  51 +{
  52 +#ifdef DEBUG
  53 +printf("{xbeeSauver}\n");
  54 +#endif
  55 +char* d="ATWR\r";
  56 +write(ds,d,strlen(d));
  57 +xbeeReponse(ds);
  58 +}
  59 +
  60 +void xbeeSortir(int ds)
  61 +{
  62 +#ifdef DEBUG
  63 +printf("{xbeeSortir}\n");
  64 +#endif
  65 +char *cmd="ATCN\r";
  66 +write(ds,cmd,strlen(cmd));
  67 +xbeeReponse(ds);
  68 +}
  69 +
  70 +void xbeeConfigureVitesse(int ds,unsigned char vitesse)
  71 +{
  72 +#ifdef DEBUG
  73 +printf("{xbeeConfigureVitesse %d}\n",vitesse);
  74 +#endif
  75 +if(vitesse<0 || vitesse>7) return;
  76 +char cmd[TAILLE_TAMPON];
  77 +sprintf(cmd,"ATBD %x\r",vitesse);
  78 +write(ds,cmd,strlen(cmd));
  79 +xbeeReponse(ds);
  80 +}
  81 +
  82 +void xbeeRecupereVitesse(int ds)
  83 +{
  84 +#ifdef DEBUG
  85 +printf("{xbeeRecupereVitesse}\n");
  86 +#endif
  87 +char *cmd="ATBD\r";
  88 +write(ds,cmd,strlen(cmd));
  89 +xbeeReponse(ds);
  90 +}
  91 +
  92 +/* Parametre canal entre 0x0B et 0x1A */
  93 +void xbeeConfigureCanal(int ds,char canal)
  94 +{
  95 +#ifdef DEBUG
  96 +printf("{xbeeConfigureCanal %02x} : debut\n",canal);
  97 +#endif
  98 +char cmd[TAILLE_TAMPON];
  99 +sprintf(cmd,"ATCH %x\r",canal);
  100 +sync();
  101 +write(ds,cmd,strlen(cmd));
  102 +xbeeReponse(ds);
  103 +#ifdef DEBUG
  104 +printf("{xbeeConfigureCanal} : fin\n");
  105 +#endif
  106 +}
  107 +
  108 +void xbeeRecupereCanal(int ds)
  109 +{
  110 +#ifdef DEBUG
  111 +printf("{xbeeRecupereCanal} : debut\n");
  112 +#endif
  113 +char *cmd="ATCH\r";
  114 +sync();
  115 +write(ds,cmd,strlen(cmd));
  116 +xbeeReponse(ds);
  117 +#ifdef DEBUG
  118 +printf("{xbeeRecupereCanal} : fin\n");
  119 +#endif
  120 +}
  121 +
  122 +void xbeeModeCommande(int ds)
  123 +{
  124 +#ifdef DEBUG
  125 +printf("{xbeeModeCommande}\n");
  126 +#endif
  127 +char *cmd="+++";
  128 +sleep(1);
  129 +sync();
  130 +write(ds,cmd,strlen(cmd));
  131 +xbeeReponse(ds);
  132 +}
... ...
code_arduino/com_Xbee/progC_initialisation_Xbee/xbeeATCmd.h 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +/** fichier xbeeATCmd.h **/
  2 +
  3 +/*****************************************************************/
  4 +/** Declarations publiques pour configurer les modules XBee. **/
  5 +/*****************************************************************/
  6 +
  7 +/** Constantes **/
  8 +
  9 +#define XBEE_VITESSE_1200 0
  10 +#define XBEE_VITESSE_2400 1
  11 +#define XBEE_VITESSE_4800 2
  12 +#define XBEE_VITESSE_9600 3
  13 +#define XBEE_VITESSE_19200 4
  14 +#define XBEE_VITESSE_38400 5
  15 +#define XBEE_VITESSE_57600 6
  16 +#define XBEE_VITESSE_115200 7
  17 +
  18 +/** Prototypes **/
  19 +
  20 +void xbeeReponse(int ds);
  21 +void xbeeDefaut(int ds);
  22 +void xbeeSauver(int ds);
  23 +void xbeeSortir(int ds);
  24 +void xbeeConfigureVitesse(int ds,unsigned char vitesse);
  25 +void xbeeRecupereVitesse(int ds);
  26 +void xbeeConfigureCanal(int ds,char canal);
  27 +void xbeeRecupereCanal(int ds);
  28 +void xbeeModeCommande(int ds);
... ...
code_arduino/com_Xbee/progC_initialisation_Xbee/xbeeATCmd.o 0 → 100644
No preview for this file type
code_arduino/librairie/adafruit/Adafruit_BME280_Library-master.zip 0 → 100644
No preview for this file type
code_arduino/librairie/adafruit/Adafruit_Sensor-master.zip 0 → 100644
No preview for this file type
code_arduino/serialArduino/serialArduino.ino 0 → 100644
... ... @@ -0,0 +1,128 @@
  1 +/***************************************************************************
  2 + This is a library for the BME280 humidity, temperature & pressure sensor
  3 +
  4 + Designed specifically to work with the Adafruit BME280 Breakout
  5 + ----> http://www.adafruit.com/products/2650
  6 +
  7 + These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  8 + to interface. The device's I2C address is either 0x76 or 0x77.
  9 +
  10 + Adafruit invests time and resources providing this open source code,
  11 + please support Adafruit andopen-source hardware by purchasing products
  12 + from Adafruit!
  13 +
  14 + Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  15 + BSD license, all text above must be included in any redistribution
  16 + ***************************************************************************/
  17 +
  18 +byte requestBytes[3]; // for incoming serial data
  19 +byte answerBytes[3];
  20 +
  21 +
  22 +#include <Wire.h>
  23 +#include <SPI.h>
  24 +#include <Adafruit_Sensor.h>
  25 +#include <Adafruit_BME280.h>
  26 +
  27 +#define BME_SCK 13
  28 +#define BME_MISO 12
  29 +#define BME_MOSI 11
  30 +#define BME_CS 10
  31 +
  32 +//Adafruit_BME280 bme; // I2C
  33 +//Adafruit_BME280 bme(BME_CS); // hardware SPI
  34 +Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
  35 +
  36 +unsigned long delayTime;
  37 +
  38 +void setup() {
  39 + Serial.begin(9600);
  40 + bme.begin();
  41 +}
  42 +
  43 +
  44 +void loop() {
  45 +
  46 +
  47 + if (Serial.available() <= 3 && Serial.available() >= 1 ) {
  48 + Serial.readBytes(requestBytes,3);
  49 + if(requestBytes[0] == 'G' && requestBytes[1] == 'E' && requestBytes[2] == 'T') //Si 3 octets correspondant à G,E et T sont envoyé on envoie les données météo
  50 + {
  51 + //on charge les donnée dans la chaîne de bytes d'envoi (modélisé par un tableau)
  52 + answerBytes[0] = pressureToByte(bme.readPressure());
  53 + answerBytes[1] = tempToByte(bme.readTemperature());
  54 + answerBytes[2] = humidityToByte(bme.readHumidity());
  55 +
  56 + Serial.write(answerBytes,3);
  57 + /*Serial.println(answerBytes[0]+845,DEC);
  58 + Serial.println(answerBytes[1],DEC);
  59 + Serial.println(answerBytes[2],DEC);*/
  60 +
  61 + }
  62 + }
  63 + // printValues();
  64 +}
  65 +
  66 +
  67 +void printValues() {
  68 + Serial.print("Temperature = ");
  69 + Serial.print(bme.readTemperature());
  70 + Serial.println(" *C");
  71 +
  72 + Serial.print("Pressure = ");
  73 +
  74 + Serial.print(bme.readPressure() / 100.0F);
  75 + Serial.println(" hPa");
  76 +
  77 + Serial.print("Approx. Altitude = ");
  78 + // Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  79 + Serial.println(" m");
  80 +
  81 + Serial.print("Humidity = ");
  82 + Serial.print(bme.readHumidity());
  83 + Serial.println(" %");
  84 +
  85 + Serial.println(pressureToByte(bme.readPressure())+845);
  86 + Serial.println(tempToByte(bme.readTemperature()));
  87 + Serial.println(humidityToByte(bme.readHumidity()));
  88 +
  89 + // Serial.println(sizeof(bme.readPressure()));
  90 + // Serial.println(sizeof(int));
  91 + //sizeof(bme.readTemperature());
  92 + //Serial.println(500.9);
  93 + //Serial.println(arrondiSuperieur(500.9));
  94 + delay(1000);
  95 +
  96 +
  97 +
  98 + Serial.println("*******************************************");
  99 +}
  100 +
  101 +int arrondiSuperieur(float val)
  102 +{
  103 + int newVal = 0;
  104 + //arrondi supérieur
  105 + if(val-(int)val >= 0.5)
  106 + newVal = (int)val+1;
  107 + else
  108 + newVal = (int)val;
  109 +
  110 + return newVal;
  111 +}
  112 +
  113 +int pressureToByte(float pressure)
  114 +{
  115 + return (int)(arrondiSuperieur(pressure/100.0)-845);
  116 +}
  117 +
  118 +byte tempToByte(float temp)
  119 +{
  120 + return (byte)arrondiSuperieur(temp);
  121 +}
  122 +
  123 +byte humidityToByte(float humidity)
  124 +{
  125 + return (byte)arrondiSuperieur(humidity);
  126 +}
  127 +
  128 +
... ...
code_arduino/test.ino 0 → 100644
... ... @@ -0,0 +1,63 @@
  1 +/* Utilisation du capteur Ultrason HC-SR04 */
  2 +
  3 +// définition des broches utilisées
  4 +int trigA = 7;
  5 +int echoA = 6;
  6 +
  7 +int trigB = 7;
  8 +int echoB = 5;
  9 +long timeAB;
  10 +long timeBA;
  11 +long C;
  12 +long V;
  13 +long speedofsoundmps = 340;
  14 +
  15 +void setup()
  16 +{
  17 + pinMode(trigA, OUTPUT);
  18 + digitalWrite(trigA, LOW);
  19 + pinMode(echoA, INPUT);
  20 +
  21 + pinMode(trigB, OUTPUT);
  22 + digitalWrite(trigB, LOW);
  23 + pinMode(echoB, INPUT);
  24 + Serial.begin(9600);
  25 +}
  26 +
  27 +void loop()
  28 +{
  29 + digitalWrite(trigA, LOW);
  30 + delayMicroseconds(2);
  31 + digitalWrite(trigA, HIGH);
  32 + delayMicroseconds(10);
  33 + digitalWrite(trigA, LOW);
  34 + timeAB = pulseIn(echoB, HIGH);
  35 + //timeAB = timeAB-40;
  36 + //Serial.println("Temps AB : ");
  37 + //Serial.println(timeAB);
  38 +
  39 + delay(100);
  40 +
  41 + digitalWrite(trigB, LOW);
  42 + delayMicroseconds(2);
  43 + digitalWrite(trigB, HIGH);
  44 + delayMicroseconds(10);
  45 + digitalWrite(trigB, LOW);
  46 + timeBA = pulseIn(echoA, HIGH);
  47 + //timeBA = timeBA-40;
  48 + //Serial.println("Temps BA : ");
  49 + //Serial.println(timeBA);
  50 +
  51 +
  52 + C = (0.45/2)*((1e6/timeAB)+(1e6/timeBA));
  53 + V = (0.45/2)*((1e6/timeAB)-(1e6/timeBA));
  54 + //Serial.println("Vitesse c : ");
  55 + //Serial.println(C);
  56 + //Serial.println() ;
  57 + Serial.println("Vitesse du vent V : ");
  58 + Serial.println(V);
  59 + Serial.println();
  60 + //Serial.println();
  61 + //Serial.println();
  62 + delay(1000);
  63 +}
... ...
code_arduino/testSerial/testSerial.ino 0 → 100644
... ... @@ -0,0 +1,43 @@
  1 +/*
  2 + DigitalReadSerial
  3 + Reads a digital input on pin 2, prints the result to the serial monitor
  4 +
  5 + This example code is in the public domain.
  6 + */
  7 +byte incomingBytes[3]; // for incoming serial data
  8 +
  9 +// the setup routine runs once when you press reset:
  10 +void setup() {
  11 + // initialize serial communication at 9600 bits per second:
  12 + Serial.begin(9600);
  13 +}
  14 +
  15 +// the loop routine runs over and over again forever:
  16 +void loop() {
  17 + // read the input pin:
  18 + // print out the state of the button:
  19 + /*Serial.write('H');
  20 + delay(1); // delay in between reads for stability*/
  21 + if (Serial.available() <= 3 && Serial.available() >= 1 ) {
  22 + // read the incoming byte:
  23 + Serial.readBytes(incomingBytes,3);
  24 +
  25 + // say what you got:
  26 + /*Serial.print("I received: ");
  27 + Serial.print(incomingBytes[0]);
  28 + Serial.print(incomingBytes[1]);
  29 + Serial.print(incomingBytes[2]);
  30 +
  31 + Serial.write(incomingBytes[0]);
  32 + Serial.write(incomingBytes[1]);
  33 + Serial.write(incomingBytes[2]);*/
  34 + //Serial.print(incomingBytes,3);
  35 + Serial.write(incomingBytes,3);
  36 + }/*else{
  37 + while(Serial.available()){Serial.read();}
  38 + }*/
  39 + //while(Serial.available()){Serial.read();} //censé vider le buffer série
  40 +}
  41 +
  42 +
  43 +
... ...