Wisblock bme 680 I2C code

hi everyone i have wisblock 4631 board and bme680 card. I connected to wisblock I2c and I can get the values. How can I add Lorawan, can you share the ready code?

BME680_Class BME680; ///< Create an instance of the BME680 class

///< Forward function declaration with default value for sea level

float altitude(const int32_t press, const float seaLevel = 1013.25);

float altitude(const int32_t press, const float seaLevel) {

/*!

@brief This converts a pressure measurement into a height in meters

@details The corrected sea-level pressure can be passed into the function if it is known,

         otherwise the standard atmospheric pressure of 1013.25hPa is used (see

         https://en.wikipedia.org/wiki/Atmospheric_pressure) for details.

@param[in] press Pressure reading from BME680

@param[in] seaLevel Sea-Level pressure in millibars

@return floating point altitude in meters.

*/

static float Altitude;

Altitude =

  44330.0 * (1.0 - pow(((float)press / 100.0) / seaLevel, 0.1903));  // Convert into meters

return (Altitude);

} // of method altitude()

void setup() {

/*!

@brief Arduino method called once at startup to initialize the system

@details This is an Arduino IDE method which is called first upon boot or restart. It is only

        called one time and then control goes to the main "loop()" method, from which

        control never returns

@return void

*/

Serial.begin(SERIAL_SPEED); // Start serial port at Baud rate

#ifdef AVR_ATmega32U4 // If this is a 32U4 processor, then wait 3 seconds to init USB port

delay(3000);

#endif

Serial.print(F(“Starting I2CDemo example program for BME680\n”));

Serial.print(F("- Initializing BME680 sensor\n"));

while (!BME680.begin(I2C_STANDARD_MODE)) { // Start BME680 using I2C, use first device found

Serial.print(F("-  Unable to find BME680. Trying again in 5 seconds.\n"));

delay(5000);

} // of loop until device is located

Serial.print(F("- Setting 16x oversampling for all sensors\n"));

BME680.setOversampling(TemperatureSensor, Oversample16); // Use enumerated type values

BME680.setOversampling(HumiditySensor, Oversample16); // Use enumerated type values

BME680.setOversampling(PressureSensor, Oversample16); // Use enumerated type values

Serial.print(F("- Setting IIR filter to a value of 4 samples\n"));

BME680.setIIRFilter(IIR4); // Use enumerated type values

Serial.print(F("- Setting gas measurement to 320\xC2\xB0\x43 for 150ms\n")); // “�C” symbols

BME680.setGas(320, 150); // 320�c for 150 milliseconds

} // of method setup()

void loop() {

/*!

@brief Arduino method for the main program loop

@details This is the main program for the Arduino IDE, it is an infinite loop and keeps on

        repeating. The "sprintf()" function is to pretty-print the values, since floating

        point is not supported on the Arduino, split the values into those before and those

        after the decimal point.

@return void

*/

static int32_t temp, humidity, pressure, gas; // BME readings

static char buf[16]; // sprintf text buffer

static float alt; // Temporary variable

static uint16_t loopCounter = 0; // Display iterations

if (loopCounter % 25 == 0) { // Show header @25 loops

Serial.print(F("\nLoop Temp\xC2\xB0\x43 Humid% Press hPa   Alt m Air m"));

Serial.print(F("\xE2\x84\xA6\n==== ====== ====== ========= ======= ======\n"));  // "�C" symbol

} // if-then time to show headers

BME680.getSensorData(temp, humidity, pressure, gas); // Get readings

if (loopCounter++ != 0) { // Ignore first reading, might be incorrect

sprintf(buf, "%4d %3d.%02d", (loopCounter - 1) % 9999,  // Clamp to 9999,

        (int8_t)(temp / 100), (uint8_t)(temp % 100));   // Temp in decidegrees

Serial.print(buf);

sprintf(buf, "%3d.%03d", (int8_t)(humidity / 1000),

        (uint16_t)(humidity % 1000));  // Humidity milli-pct

Serial.print(buf);

sprintf(buf, "%7d.%02d", (int16_t)(pressure / 100),

        (uint8_t)(pressure % 100));  // Pressure Pascals

Serial.print(buf);

alt = altitude(pressure);                                                // temp altitude

sprintf(buf, "%5d.%02d", (int16_t)(alt), ((uint8_t)(alt * 100) % 100));  // Altitude meters

Serial.print(buf);

sprintf(buf, "%4d.%02d\n", (int16_t)(gas / 100), (uint8_t)(gas % 100));  // Resistance milliohms

Serial.print(buf);

delay(10000);  // Wait 10s

} // of ignore first reading

} // of method loop()

Hi @mryavash ,

BME680 is used on WisBlock Kit 4.

I can share four tutorials that you can check which is a complete tutorial from end-to-end.

  1. RAK Developer Kit 4 (Air Quality Kit) Guide | RAKwireless Documentation Center
  2. WisBlock Kit 4 and RAK Edge Gateway Complete LoRaWAN Guide with TTN V3 and TagoIO | RAKwireless Documentation Center
  3. WisBlock Kit 4 + RAK Built-in Network Server + Datacake | RAKwireless Documentation Center
  4. WisBlock Kit 4 and RAK Edge Gateway Complete LoRaWAN Guide with TTN V3 and Qubitro | RAKwireless Documentation Center

GitHub - beegee-tokyo/RAK4631-Kit-4-RAK1906: Example code for WisBlock Environment Sensor with RAK1906 environment sensor ok i installed it but i am running the bme680 sensor as i2c can you help me. Which code should I change? device works as spi.

Hello, I don’t want to use oled here, instead I want to connect it as seen in the picture and read the data directly from google sheet.

Hi @mryavash ,

You can use Beegee’s code above and it has AT commands functionality which can be handy on making the device work immediately via AT commands. However, it has larger code to handle AT functionality and works with platformio natively.

If you need basic code for your sensor, you can use this example - https://github.com/RAKWireless/WisBlock/tree/master/examples/RAK4630/solutions/Environment_Monitoring

Then you can connect your LNS to google sheet. If you are using TTS, you can try to use this - GitHub - Uspizig/Ttn-gooogle-script: Http integration of google script fir the things network (I haven’t tried it myself though).

Btw, your sensor is connected via I2C and it should be fine.