Commit c4726d68ece1e1c4402511b4f036556496dc6ceb

Authored by aknockae
1 parent 1e6dee6c

ajout du code arduino

code arduino/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/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/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/test_arduino.zip 0 → 100644
No preview for this file type