Harold Duarte RojasRAKwireless
Published © GPL3+

Getting Started with the Arduino IDE (Debugging)

Debugging of WisBlock with the Arduino IDE and WisBlock

BeginnerProtip3 hours363
Getting Started with the Arduino IDE (Debugging)

Things used in this project

Story

Read more

Code

Tracking_1

Arduino
#define TRACKING() \
Serial.print(__FILE__); \
Serial.print(':'); \
Serial.print(__LINE__); \
Serial.print(": "); \
Serial.println(__PRETTY_FUNCTION__); \
Serial.flush();
#include<bluefruit.h>

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  TRACKING();
  Serial.println("LED TURN ON");
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  TRACKING();
  delay(1000);                       // wait for a second
  Serial.println("LED TURN OFF");
}

Tracking_RAK1906

Arduino
/**
   @file RAK1906_Environment_BEM680.ino
   @author rakwireless.com
   @brief Setup and read values from bme680 sensor
   @version 0.1
   @date 2020-12-28
   @copyright Copyright (c) 2020
**/

#define TRACKING() \
Serial.print(__FILE__); \
Serial.print(':'); \
Serial.print(__LINE__); \
Serial.print(": "); \
Serial.println(__PRETTY_FUNCTION__); \
Serial.flush();

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME680.h> // Click to install library: http://librarymanager/All#Adafruit_BME680

Adafruit_BME680 bme;
// Might need adjustments
#define SEALEVELPRESSURE_HPA (1010.0)

void bme680_init()
{
  Wire.begin();
TRACKING();
  if (!bme.begin(0x76)) {
    Serial.println("Could not find a valid BME680 sensor, check wiring!");
    return;
  }

  // Set up oversampling and filter initialization
  bme.setTemperatureOversampling(BME680_OS_8X);
  bme.setHumidityOversampling(BME680_OS_2X);
  bme.setPressureOversampling(BME680_OS_4X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
  bme.setGasHeater(320, 150); // 320*C for 150 ms
}

void bme680_get()
{
  TRACKING();
  Serial.print("Temperature = ");
  Serial.print(bme.temperature);
  Serial.println(" *C");

  Serial.print("Pressure = ");
  Serial.print(bme.pressure / 100.0);
  Serial.println(" hPa");

  Serial.print("Humidity = ");
  Serial.print(bme.humidity);
  Serial.println(" %");

  Serial.print("Gas = ");
  Serial.print(bme.gas_resistance / 1000.0);
  Serial.println(" KOhms");

  Serial.println();
}

void setup()
{TRACKING();
  // Initialize the built in LED
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);

  // Initialize Serial for debug output
  Serial.begin(115200);

  time_t serial_timeout = millis();
  // On nRF52840 the USB serial is not available immediately
  while (!Serial)
  {
    if ((millis() - serial_timeout) < 5000)
    {
      delay(100);
      digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    }
    else
    {
      break;
    }
  }

  bme680_init();
}

void loop()
{TRACKING();
  if (! bme.performReading()) {
    Serial.println("Failed to perform reading :(");
    return;
  }
  bme680_get();
  delay(5000);
}

Credits

Harold Duarte Rojas

Harold Duarte Rojas

9 projects • 10 followers
Electronics engineer, Content creator at RAKwireless.
RAKwireless

RAKwireless

27 projects • 53 followers
A pioneer in providing innovated and diverse LPWA connectivity solutions for IoT edge devices.

Comments