Skip to content

Commit

Permalink
Initial upload
Browse files Browse the repository at this point in the history
master branch creation
  • Loading branch information
N0ury authored Jan 15, 2019
1 parent 5e8cfd8 commit e3d7c52
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 0 deletions.
38 changes: 38 additions & 0 deletions direction.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
void getAngle(int iter) {
res = mlx_1.readAngle();
res=0;
/* if res = -1 then no SPI signal
* if res = -2 then signal too strong
* if res = -3 then signal too weak
*/
if (debug) {
mySerial.print("direction:res lu #"); mySerial.print(iter); mySerial.print("/10: ");
mySerial.print(res);
}
if (res > 1800) angle = -3600+res; else angle = res;

if (res >= 0) {
if (debug) {
mySerial.print(", Angle retenu (en 1/10 degres C): ");
mySerial.println(angle);
}
sum_angle+=angle;
nb_angle++;
} else {
angle = 0; // Pour avoir une instruction en mode non debug
if (debug) mySerial.println(", Angle du capteur non retenu, on retient 0");
}
}

void calcAngle() {
if (nb_angle != 0)
direction = sum_angle / nb_angle;
else
direction = 0;
if (direction < 0) direction = 3600 + direction;
if (debug) {
mySerial.print("direction:Direction vent (en 1/10 degres C): ");
mySerial.println(direction);
}
}

34 changes: 34 additions & 0 deletions divers.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
void blink(uint8_t pin, uint8_t times) {
for (int i = 0; i < times; i++) {
digitalWrite(pin, HIGH);
delay(100);
digitalWrite(pin, LOW);
delay(1000);
}
}

void twi_disable(void)
{
// disable twi module, acks, and twi interrupt
TWCR &= ~(_BV(TWEN) | _BV(TWIE) | _BV(TWEA));

// deactivate internal pullups for twi.
digitalWrite(SDA, 0);
digitalWrite(SCL, 0);
}

/*
PrintHex routines for Arduino: to print byte or word data in hex with
leading zeroes.
Copyright (C) 2010 Kairama Inc
*/
void PrintHex8(uint8_t *data, uint8_t length) // prints 8-bit data in hex with leading zeroes
{
mySerial.print("0x");
for (int i=0; i<length; i++) {
if (data[i]<0x10) {mySerial.print("0");}
mySerial.print(data[i],HEX);
mySerial.print(" ");
}
}

37 changes: 37 additions & 0 deletions get_temp_pressure.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
void getTempPress(){

digitalWrite (BMP_POWER, HIGH); // On met le BMP280 sous tension
pinMode (BMP_POWER, OUTPUT);
delay(400); // On attend un peu que le BMP280 soit sous tension

if (!bmp.begin()) {
// Si le bmp280 ne démarre pas, on fait clignoter la led indéfiniment (1 fois par sec)
while (1) {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
}

temperature = bmp.readTemperature()*100;
pression = (bmp.readPressure());
delay(40);
// Workaround: must read twice, otherwice results are wrong
temperature = bmp.readTemperature()*100;
pression = (bmp.readPressure());
pinMode (BMP_POWER, INPUT);
digitalWrite (BMP_POWER, LOW); // On remet hors tension le BMP280

// Arrêt I2C (à conserver)
TWCR &= ~(bit(TWEN) | bit(TWIE) | bit(TWEA));
twi_disable();

if (debug) {
mySerial.print("temperature:");
mySerial.println(temperature);
mySerial.print("pression:");
mySerial.println(pression);
}
}

33 changes: 33 additions & 0 deletions loop.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
void loop () {
if (debug) mySerial.println("======================= begin loop ======================");
sum_angle = 0;
nb_angle = 0;
angle = 0;
int j = 0;
int iter = 0;
// On se met en sleep pour 8*SLEEP_10MINS secondes
for (int i = 0; i < SLEEP_10MINS; i++) {
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
j++;
if (j >= SLEEP_1MINS) {
// Chaque minute, on vérifie si le mode debug a été activé/désactivé
// Et on récupère la direction du vent à cet instant là
uint8_t debugNew = !digitalRead(debugPin);
if (debugNew != debug) {
debug = debugNew;
if (debug) mySerial.begin(9600); else mySerial.end();
}
j = 0; iter++;
getAngle(iter);
}
}
calcAngle(); // On calcule une moyenne de direction du vent
getTempPress();
processResults();

// On attend que les I/O en TX soient terminées (obligatoire)
loop_until_bit_is_set(UCSR0A, TXC0); /* Wait until transmission ready. */

if (debug) mySerial.println("======================== end loop =======================");
}

73 changes: 73 additions & 0 deletions process_results.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
void processResults(){

temp_union.value2 = temperature;
pression_union.value2 = pression;
direction_union.value2 = direction;
data[0] = temp_union.value1[1];
data[1] = temp_union.value1[0];
data[2] = pression_union.value1[2];
data[3] = pression_union.value1[1];
data[4] = pression_union.value1[0];
data[5] = direction_union.value1[1];
data[6] = direction_union.value1[0];
size = 7;

if (debug) {
mySerial.print ("sigfox:Contenu de data: ");
PrintHex8(data,7);
mySerial.println ("");
}

error = 1;
error = Sigfox.ON(SOCKET0); // UART0
if( error != 0 ) {
//"Sigfox ON ERROR"
if (debug) mySerial.println ("sigfox:erreur sur le ON");
digitalWrite(6, HIGH);
exit(0);
}
blink(6, 1);
if (debug) {
mySerial.print ("sigfox:valeur de la variable error apres le ON depuis le .ino: ");
mySerial.print (error);
mySerial.println (" =>0=OK, autre=KO");
}
// Send data to Sigfox
error = 1;
// error = Sigfox.sendACK(data,size);
error = Sigfox.send(data,size);
if( error != 0 ) {
//"Sigfox packet sent ERROR"
if (debug) mySerial.println ("sigfox:erreur sur le send");
digitalWrite(7, HIGH);
exit(0);
}
blink(7, 1);
if (debug) {
mySerial.print ("sigfox:valeur de la variable error apres le send depuis le .ino: ");
mySerial.print (error);
mySerial.println (" =>0=OK, autre=KO");
}

error = 1;
error = Sigfox.OFF(SOCKET0); // UART0
if( error != 0 ) {
//"Sigfox OFF ERROR"
if (debug) mySerial.println ("sigfox:erreur sur le OFF");
digitalWrite(8, HIGH);
exit(0);
}
// blink(8, 2);
if (debug) {
mySerial.print ("sigfox:valeur de la variable error apres le OFF depuis le .ino: ");
mySerial.print (error);
mySerial.println (" =>0=OK, autre=KO");
// char state_c = reinterpret_cast<const char*>(Sigfox._ackData);
// int state_i = (int)strtol(state_c, NULL, 16);
// mySerial.print("resultat int:");
// mySerial.println(state);
// mySerial.print("resultat char:");
// mySerial.println(reinterpret_cast<const char*>(Sigfox._ackData));
}
}

25 changes: 25 additions & 0 deletions setup.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
void setup () {
pinMode(debugPin, INPUT_PULLUP);
debug = !digitalRead(debugPin); // Par défaut l'état est à HIGH:debug=off à cause de la résistance de pull-up interne
if (debug) {
mySerial.begin(9600);
mySerial.println("======================= begin setup ======================");
}

// Arrêt I2C
// TWCR &= ~(bit(TWEN) | bit(TWIE) | bit(TWEA));

//Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high.
mlx_1.attach(10, 13, 11 ); // pin_SS=10, pinSCLK=13, pinMOSI=11
res = mlx_1.readAngle();

blink(13, 5);

pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
if (debug) mySerial.println("======================== end setup =======================");
}
52 changes: 52 additions & 0 deletions station_girouette.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "LowPower.h"
#include <arduinoUtils.h>
#include <arduinoSigfox.h>
#include <Adafruit_BMP280.h>
#include <SoftwareSerial.h>
#include "MLX90316.h"

#define BMP_POWER 5 // pin pour alimenter le module BMP280 (µc 11)
#define debugPin 9
#define SLEEP_10MINS 75 // Pour un power down de 10 minutes environ
#define SLEEP_1MINS 7 // Pour des intervalles de 1 minute (vent)

int res;
MLX90316 mlx_1 = MLX90316();

// variable qui contiendra les données à envoyer à Sigfox
uint8_t data[12]; // 12 octets max
uint8_t size; // taille utilisée

int16_t temperature=0;
uint32_t pression=0;
int16_t direction=0;

Adafruit_BMP280 bmp; // I2C

int16_t sum_angle = 0;
uint8_t nb_angle = 0;
int16_t angle = 0;

uint8_t debug = 0;

SoftwareSerial mySerial(2, 3); // RX, TX

// define error variable
uint8_t error;

union{
uint8_t value1[4];
uint32_t value2;
}pression_union;

union{
uint8_t value1[2];
uint16_t value2;
}temp_union;

union{
uint8_t value1[2];
uint16_t value2;
}direction_union;


0 comments on commit e3d7c52

Please sign in to comment.