Go Down

Topic: Firmware problem (Read 1 time) previous topic - next topic

filippocarastro

I don't understand why after 4 cycle of loop the Arduino is block.

Code: [Select]
#include <ArduinoLowPower.h>
#include <SigFox.h>
#include <Wire.h>
#include <Adafruit_INA219.h>
#include "BMP280.h"
#define P0 1013.25


Adafruit_INA219 ina219(0x40);
BMP280 bmp;

int debug = true;
int PinY = 1;
int PinG = 0;

float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;

char result;
double T,P;

void setup() {
 
  pinMode(PinY,OUTPUT);
  pinMode(PinG,OUTPUT);
 
  Serial.begin(9600);
 
  if (!SigFox.begin()) {
    //something is really wrong, try rebooting
    reboot();
  }
 
  SigFox.end();
 
  if (debug == true) {
    // Enable debug prints and LED indication if we are testing
    SigFox.debug();
  }
 
  uint32_t currentFrequency;
  ina219.begin();
  ina219.setCalibration_16V_400mA();
  Serial.println("Measuring voltage and current with INA219 ...");

  if(!bmp.begin()){
    Serial.println("BMP init failed!");
    while(1);
  }
  else {
    Serial.println("BMP init success!");
  }
 
  bmp.setOversampling(4);
 
  LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, ledOn, CHANGE);
 
}

void loop() {

  current_mA = ina219.getCurrent_mA();
  result = bmp.startMeasurment();
 
  if(result!=0){
    delay(result);
    result = bmp.getTemperatureAndPressure(T,P);
  }
  else {
    Serial.println("Error.");
  }
  delay(100);
 
  SigFox.begin();
  delay(100);
  String to_be_sent = String(current_mA) + "mA " + String(T) + "C";
  SigFox.beginPacket();
  SigFox.print(to_be_sent);
  int ret = SigFox.endPacket();
  SigFox.end();
 
  if (debug == true) {
    if (ret == 0) {
      Serial1.println("Transmission ok");
      digitalWrite(PinY,LOW);
      digitalWrite(PinG,HIGH);
    } else {
      Serial1.println("No transmission");
      digitalWrite(PinY,HIGH);
      digitalWrite(PinG,LOW);
     }
  }
  delay(1000);
  LowPower.sleep(1800000);  //1 misura ogni mezz'ora
}

void reboot() {
  NVIC_SystemReset();
  while (1);
}

void ledOn() {
  digitalWrite(PinG,LOW);
  digitalWrite(PinY,LOW);
}

Go Up