diff --git a/code arduino/bme280test.ino b/code arduino/bme280test.ino new file mode 100644 index 0000000..8c13ff7 --- /dev/null +++ b/code arduino/bme280test.ino @@ -0,0 +1,83 @@ +/*************************************************************************** + This is a library for the BME280 humidity, temperature & pressure sensor + + Designed specifically to work with the Adafruit BME280 Breakout + ----> http://www.adafruit.com/products/2650 + + These sensors use I2C or SPI to communicate, 2 or 4 pins are required + to interface. The device's I2C address is either 0x76 or 0x77. + + Adafruit invests time and resources providing this open source code, + please support Adafruit andopen-source hardware by purchasing products + from Adafruit! + + Written by Limor Fried & Kevin Townsend for Adafruit Industries. + BSD license, all text above must be included in any redistribution + ***************************************************************************/ + +#include +#include +#include +#include + +#define BME_SCK 13 +#define BME_MISO 12 +#define BME_MOSI 11 +#define BME_CS 10 + +#define SEALEVELPRESSURE_HPA (1013.25) + +//Adafruit_BME280 bme; // I2C +//Adafruit_BME280 bme(BME_CS); // hardware SPI +Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI + +unsigned long delayTime; + +void setup() { + Serial.begin(9600); + Serial.println(F("BME280 test")); + + bool status; + + // default settings + status = bme.begin(); + if (!status) { + Serial.println("Could not find a valid BME280 sensor, check wiring!"); + while (1); + } + + Serial.println("-- Default Test --"); + delayTime = 1000; + + Serial.println(); + + delay(100); // let sensor boot up +} + + +void loop() { + printValues(); + delay(delayTime); +} + + +void printValues() { + Serial.print("Temperature = "); + Serial.print(bme.readTemperature()); + Serial.println(" *C"); + + Serial.print("Pressure = "); + + Serial.print(bme.readPressure() / 100.0F); + Serial.println(" hPa"); + + Serial.print("Approx. Altitude = "); + Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); + Serial.println(" m"); + + Serial.print("Humidity = "); + Serial.print(bme.readHumidity()); + Serial.println(" %"); + + Serial.println(); +} diff --git a/code arduino/com_Xbee/code_emetteur/sketch_may02a.ino b/code arduino/com_Xbee/code_emetteur/sketch_may02a.ino new file mode 100644 index 0000000..9443ab4 --- /dev/null +++ b/code arduino/com_Xbee/code_emetteur/sketch_may02a.ino @@ -0,0 +1,20 @@ +/* Input-side (button) Arduino code */ +#include +// RX: Arduino pin 2, XBee pin DOUT. TX: Arduino pin 3, XBee pin DIN +SoftwareSerial xBee(2, 3); + +void setup() +{ + // Baud rate MUST match XBee settings (as set in XCTU) + xBee.begin(9600); +} + +void loop() +{ + + xBee.write('H'); + xBee.println("test"); + delay(500); + xBee.write('L'); +} + diff --git a/code arduino/com_Xbee/code_receveur/receveurXbee.ino b/code arduino/com_Xbee/code_receveur/receveurXbee.ino new file mode 100644 index 0000000..621a1dc --- /dev/null +++ b/code arduino/com_Xbee/code_receveur/receveurXbee.ino @@ -0,0 +1,33 @@ +/* Output-side (LED) Arduino code */ +#include "SoftwareSerial.h" +// RX: Arduino pin 2, XBee pin DOUT. TX: Arduino pin 3, XBee pin DIN +SoftwareSerial XBee(0, 1); +int LED = 13; + +void setup() +{ + // Baud rate MUST match XBee settings (as set in XCTU) + XBee.begin(9600); + pinMode(LED, OUTPUT); +} + +void loop() +{ + if (XBee.available()) + { + char c = XBee.read(); + if (c == 'H') + { + digitalWrite(LED, HIGH); + delay(50); + } + else + { + digitalWrite(LED, LOW); + } + } + else + { + digitalWrite(LED, LOW); + } +} diff --git a/code arduino/com_Xbee/progC_initialisation_Xbee/Makefile b/code arduino/com_Xbee/progC_initialisation_Xbee/Makefile new file mode 100644 index 0000000..f009cd8 --- /dev/null +++ b/code arduino/com_Xbee/progC_initialisation_Xbee/Makefile @@ -0,0 +1,27 @@ +# +# Makefile de l'utilitaire XBee +# + +OBJS = xbee.o xbeeATCmd.o + +# +# Cible generale +# + +all: xbee + +# +# La cible de nettoyage +# + +clean: + rm -f core *.o xbee + +# +# Les cibles pour l'executable +# + +xbee: $(OBJS) + $(CC) $(CFLAGS) -o xbee $(OBJS) + +xbeeATCmd.o: xbeeATCmd.c xbeeATCmd.h diff --git a/code arduino/com_Xbee/progC_initialisation_Xbee/xbee b/code arduino/com_Xbee/progC_initialisation_Xbee/xbee new file mode 100644 index 0000000..c6a3abe Binary files /dev/null and b/code arduino/com_Xbee/progC_initialisation_Xbee/xbee differ diff --git a/code arduino/com_Xbee/progC_initialisation_Xbee/xbee.c b/code arduino/com_Xbee/progC_initialisation_Xbee/xbee.c new file mode 100644 index 0000000..ff91496 --- /dev/null +++ b/code arduino/com_Xbee/progC_initialisation_Xbee/xbee.c @@ -0,0 +1,96 @@ +/** fichier xbee.c **/ + +/*****************************************************************/ +/** Utilitaire pour configurer les modules XBee. **/ +/*****************************************************************/ + +/** Fichiers d'inclusion **/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "xbeeATCmd.h" + +/** Constantes **/ + +#define SERIALDEV "/dev/ttyUSB0" +#define BAUDRATE B9600 + +/**** Variables globales *****/ + +static struct termios sauvegarde; + +/** Ouverture d'un port serie **/ + +int ouvertureSerie(char *periph,int vitesse) +{ +struct termios nouveau; +int df=open(periph,O_RDWR|O_NOCTTY); +if(df<0) return -1; + +tcgetattr(df,&sauvegarde); /* save current port settings */ +bzero(&nouveau,sizeof(nouveau)); +nouveau.c_cflag=CLOCAL|CREAD|vitesse|CS8; +nouveau.c_iflag=0; +nouveau.c_oflag=0; +nouveau.c_lflag=0; +nouveau.c_cc[VTIME]=0; +nouveau.c_cc[VMIN]=1; +tcflush(df, TCIFLUSH); +tcsetattr(df,TCSANOW,&nouveau); + +return df; +} + +/** Fermeture d'un port serie **/ + +void fermetureSerie(int df) +{ +tcsetattr(df,TCSANOW,&sauvegarde); +close(df); +} + +/** Programme principal **/ + +int main(int argc, char *argv[]) +{ + +int ds; +ds=ouvertureSerie(SERIALDEV,BAUDRATE); +if(ds<0){ + fprintf(stderr,"Erreur sur la connexion série.\n"); + exit(-1); + } + +fprintf(stdout,"Configuration actuelle :\n"); +fprintf(stdout,"----------------------\n"); +xbeeModeCommande(ds); +xbeeRecupereVitesse(ds); +xbeeRecupereCanal(ds); + +fprintf(stdout,"\nConfiguration par défaut :\n"); +fprintf(stdout,"------------------------\n"); +xbeeDefaut(ds); +xbeeRecupereVitesse(ds); +xbeeRecupereCanal(ds); + +fprintf(stdout,"\nConfiguration spécifique :\n"); +fprintf(stdout,"------------------------\n"); +xbeeConfigureVitesse(ds,XBEE_VITESSE_9600); +xbeeConfigureCanal(ds,0x0B); +xbeeRecupereVitesse(ds); +xbeeRecupereCanal(ds); +xbeeSauver(ds); +xbeeSortir(ds); + +fermetureSerie(ds); +return EXIT_SUCCESS; +} diff --git a/code arduino/com_Xbee/progC_initialisation_Xbee/xbee.o b/code arduino/com_Xbee/progC_initialisation_Xbee/xbee.o new file mode 100644 index 0000000..34ad773 Binary files /dev/null and b/code arduino/com_Xbee/progC_initialisation_Xbee/xbee.o differ diff --git a/code arduino/com_Xbee/progC_initialisation_Xbee/xbeeATCmd.c b/code arduino/com_Xbee/progC_initialisation_Xbee/xbeeATCmd.c new file mode 100644 index 0000000..c93f837 --- /dev/null +++ b/code arduino/com_Xbee/progC_initialisation_Xbee/xbeeATCmd.c @@ -0,0 +1,132 @@ +/** fichier xbeeATCmd.c **/ + +/*****************************************************************/ +/** Commandes pour configurer les modules XBee. **/ +/*****************************************************************/ + +/** Fichiers d'inclusion **/ + +#include +#include +#include +#include + +/** Constantes **/ + +#define TAILLE_TAMPON 128 + +/** Fonctions **/ + +void xbeeReponse(int ds) +{ +register int i; +char d[TAILLE_TAMPON]; +sync(); +for(i=0;i0) fprintf(stdout," ("); +for(i=0;i0) fprintf(stdout,")\n"); +} + +void xbeeDefaut(int ds) +{ +#ifdef DEBUG +printf("{xbeeDefaut}\n"); +#endif +char* d="ATRE\r"; +write(ds,d,strlen(d)); +xbeeReponse(ds); +} + +void xbeeSauver(int ds) +{ +#ifdef DEBUG +printf("{xbeeSauver}\n"); +#endif +char* d="ATWR\r"; +write(ds,d,strlen(d)); +xbeeReponse(ds); +} + +void xbeeSortir(int ds) +{ +#ifdef DEBUG +printf("{xbeeSortir}\n"); +#endif +char *cmd="ATCN\r"; +write(ds,cmd,strlen(cmd)); +xbeeReponse(ds); +} + +void xbeeConfigureVitesse(int ds,unsigned char vitesse) +{ +#ifdef DEBUG +printf("{xbeeConfigureVitesse %d}\n",vitesse); +#endif +if(vitesse<0 || vitesse>7) return; +char cmd[TAILLE_TAMPON]; +sprintf(cmd,"ATBD %x\r",vitesse); +write(ds,cmd,strlen(cmd)); +xbeeReponse(ds); +} + +void xbeeRecupereVitesse(int ds) +{ +#ifdef DEBUG +printf("{xbeeRecupereVitesse}\n"); +#endif +char *cmd="ATBD\r"; +write(ds,cmd,strlen(cmd)); +xbeeReponse(ds); +} + +/* Parametre canal entre 0x0B et 0x1A */ +void xbeeConfigureCanal(int ds,char canal) +{ +#ifdef DEBUG +printf("{xbeeConfigureCanal %02x} : debut\n",canal); +#endif +char cmd[TAILLE_TAMPON]; +sprintf(cmd,"ATCH %x\r",canal); +sync(); +write(ds,cmd,strlen(cmd)); +xbeeReponse(ds); +#ifdef DEBUG +printf("{xbeeConfigureCanal} : fin\n"); +#endif +} + +void xbeeRecupereCanal(int ds) +{ +#ifdef DEBUG +printf("{xbeeRecupereCanal} : debut\n"); +#endif +char *cmd="ATCH\r"; +sync(); +write(ds,cmd,strlen(cmd)); +xbeeReponse(ds); +#ifdef DEBUG +printf("{xbeeRecupereCanal} : fin\n"); +#endif +} + +void xbeeModeCommande(int ds) +{ +#ifdef DEBUG +printf("{xbeeModeCommande}\n"); +#endif +char *cmd="+++"; +sleep(1); +sync(); +write(ds,cmd,strlen(cmd)); +xbeeReponse(ds); +} diff --git a/code arduino/com_Xbee/progC_initialisation_Xbee/xbeeATCmd.h b/code arduino/com_Xbee/progC_initialisation_Xbee/xbeeATCmd.h new file mode 100644 index 0000000..5f48df3 --- /dev/null +++ b/code arduino/com_Xbee/progC_initialisation_Xbee/xbeeATCmd.h @@ -0,0 +1,28 @@ +/** fichier xbeeATCmd.h **/ + +/*****************************************************************/ +/** Declarations publiques pour configurer les modules XBee. **/ +/*****************************************************************/ + +/** Constantes **/ + +#define XBEE_VITESSE_1200 0 +#define XBEE_VITESSE_2400 1 +#define XBEE_VITESSE_4800 2 +#define XBEE_VITESSE_9600 3 +#define XBEE_VITESSE_19200 4 +#define XBEE_VITESSE_38400 5 +#define XBEE_VITESSE_57600 6 +#define XBEE_VITESSE_115200 7 + +/** Prototypes **/ + +void xbeeReponse(int ds); +void xbeeDefaut(int ds); +void xbeeSauver(int ds); +void xbeeSortir(int ds); +void xbeeConfigureVitesse(int ds,unsigned char vitesse); +void xbeeRecupereVitesse(int ds); +void xbeeConfigureCanal(int ds,char canal); +void xbeeRecupereCanal(int ds); +void xbeeModeCommande(int ds); diff --git a/code arduino/com_Xbee/progC_initialisation_Xbee/xbeeATCmd.o b/code arduino/com_Xbee/progC_initialisation_Xbee/xbeeATCmd.o new file mode 100644 index 0000000..9456ffa Binary files /dev/null and b/code arduino/com_Xbee/progC_initialisation_Xbee/xbeeATCmd.o differ diff --git a/code arduino/test.ino b/code arduino/test.ino new file mode 100644 index 0000000..d9567d1 --- /dev/null +++ b/code arduino/test.ino @@ -0,0 +1,63 @@ +/* Utilisation du capteur Ultrason HC-SR04 */ + +// définition des broches utilisées +int trigA = 7; +int echoA = 6; + +int trigB = 7; +int echoB = 5; +long timeAB; +long timeBA; +long C; +long V; +long speedofsoundmps = 340; + +void setup() +{ + pinMode(trigA, OUTPUT); + digitalWrite(trigA, LOW); + pinMode(echoA, INPUT); + + pinMode(trigB, OUTPUT); + digitalWrite(trigB, LOW); + pinMode(echoB, INPUT); + Serial.begin(9600); +} + +void loop() +{ + digitalWrite(trigA, LOW); + delayMicroseconds(2); + digitalWrite(trigA, HIGH); + delayMicroseconds(10); + digitalWrite(trigA, LOW); + timeAB = pulseIn(echoB, HIGH); + //timeAB = timeAB-40; + //Serial.println("Temps AB : "); + //Serial.println(timeAB); + + delay(100); + + digitalWrite(trigB, LOW); + delayMicroseconds(2); + digitalWrite(trigB, HIGH); + delayMicroseconds(10); + digitalWrite(trigB, LOW); + timeBA = pulseIn(echoA, HIGH); + //timeBA = timeBA-40; + //Serial.println("Temps BA : "); + //Serial.println(timeBA); + + + C = (0.45/2)*((1e6/timeAB)+(1e6/timeBA)); + V = (0.45/2)*((1e6/timeAB)-(1e6/timeBA)); + //Serial.println("Vitesse c : "); + //Serial.println(C); + //Serial.println() ; + Serial.println("Vitesse du vent V : "); + Serial.println(V); + Serial.println(); + //Serial.println(); + //Serial.println(); + delay(1000); +} diff --git a/code arduino/test_arduino.zip b/code arduino/test_arduino.zip new file mode 100644 index 0000000..fa65957 Binary files /dev/null and b/code arduino/test_arduino.zip differ -- libgit2 0.21.2