Fermion: BLE Sensor Beacon Wiki - DFRobot

Fermion: BLE Sensor Beacon

Introduction

Fermion: BLE Sensor Beacon, a wireless beacon that broadcasts sensor data via Bluetooth, with built-in 11-bit ADC acquisition and I2C write/read functionality, can be connected to digital or analogue sensors for data acquisition and broadcasting. Sensor data broadcasted by the beacon can be accessed within the beacon's broadcast range using mobile phones, ESP32 and other devices that support BLE reception.

Fermion: BLE sensor beacons integrate low-power Bluetooth 5.3 technology with self-configurable data formats, such as iBeacon, Eddystone, user-defined, and more. The data format of the beacon broadcast, the content of the broadcast, the broadcast interval and so on can be configured through the graphical interface, without the need for any code programming to complete a Bluetooth beacon. After the configuration is completed, the device power supply is running as a Bluetooth beacon, which will automatically collect sensor data and broadcast to the outside world according to the configuration information. It is suitable for IoT sensor nodes, such as smart farms, offices, factories, warehouses and other scenarios in the data collection node.

Compared to Gravity: BLE Sensor Beacons , the Fermion version mproved:

Specification

Pinout

No Name Function
1 Serial port burning area VCC:3.3V Input
GND:Ground
IO0:RX(3.3V)
IO1:TX (3.3V)
2 I2C/Other sensors (coin cell powered) VBAT:Coin Cell Positive
IO3/IO7:Can be set to SDA/SCL or digital/analogue inputs and outputs
3 I2C/Other sensors (dynamic power control) SW0:Configurable dynamic power supply that outputs a high level to power the sensor only when broadcasting
IO4/IO5:Can be set to SDA/SCL or digital/analogue inputs and outputs
4 Digital/Analogue Sensors SW1:Configurable dynamic power supply that pulls down only when broadcasting
IO2:Can be set to SDA/SCL
IO6:Can be set to digital/analogue input, this GPIO has a built-in voltage divider, recommended for analogue sensors.
5 Pull-up Resistor Selection Pad IO3/IO7/IO4/IO5/IO2Pull-up resistor soldering point, connect the corresponding IO to the pull-up resistor, the default is not connected to the pull-up.
Fermion and Gravity series sensors have pull-up resistors on the sensor side.
6 Battery socket CR2032 button cell
Connect positive to VBAT, negative to GND
7 NOTE Beacon Information Marker to mark the key information of the burned beacons

Digital/Analog Sensors Tutorial

As an example of a custom data format, the sensor data is acquired through the mobile app and ESP32.

1. Requirements

2.Configure Sensor Beacon

*Note: The module can only be burned once, do not click "Burn/Program" directly to burn before confirming the configuration information. You can test the module by "Run inRAM", and "Run in RAM" can be used for unlimited times before burning, and the system will be reset after power failure.

The input voltage of the module's ADC interface must not exceed 1.6V. If the voltage of the accessed sensors may exceed 1.6V, the sensors need to be connected to GPIO6, which adds 2.06 times the divider resistor to support an input voltage of up to 3.3V.

3. Mobile app to get data

4. ESP32 Get Data

/*
   Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp
   Ported to Arduino ESP32 by Evandro Copercini
   Changed to a beacon scanner to report iBeacon, EddystoneURL and EddystoneTLM beacons by beegee-tokyo
*/

#include <Arduino.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
#include <BLEEddystoneURL.h>
#include <BLEEddystoneTLM.h>
#include <BLEBeacon.h>
#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00) >> 8) + (((x)&0xFF) << 8))

float Sensor_Data;
int scanTime = 5; //In seconds
BLEScan *pBLEScan;

class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks
{
    void onResult(BLEAdvertisedDevice advertisedDevice)
    {
      if (advertisedDevice.haveName())
      {
        if(String(advertisedDevice.getName().c_str()) == "Fermion:Sensor Beacon"){
          Serial.print("Device name: ");
          Serial.println(advertisedDevice.getName().c_str());
          std::string strManufacturerData = advertisedDevice.getManufacturerData();
          uint8_t cManufacturerData[100];
          strManufacturerData.copy((char *)cManufacturerData, strManufacturerData.length(), 0);
          Serial.printf("strManufacturerData: %d ", strManufacturerData.length());
            for (int i = 0; i < strManufacturerData.length(); i++)
            {
              Serial.printf("[%X]", cManufacturerData[i]);
            }
            Sensor_Data = int(cManufacturerData[2]<<8 | cManufacturerData[3]);
            Serial.println();
            Serial.print("Voltage:");Serial.print(int(Sensor_Data));Serial.println("mV");   
            Serial.print("Temp_LM35:");Serial.print(Sensor_Data/10);Serial.println("℃");      
            Serial.println("------------------");       
        }        
      }
    }
};
void setup()
{
  Serial.begin(115200);
  Serial.println("Scanning...");

  BLEDevice::init("");
  pBLEScan = BLEDevice::getScan(); //create new scan
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
  pBLEScan->setInterval(100);
  pBLEScan->setWindow(99); // less or equal setInterval value
}
void loop()
{
  // put your main code here, to run repeatedly:
  BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
  pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
  delay(2000);
}

5.Confirm the data and burn into Beacon

I2C Sensor Tutorial

The custom data format is used as an example to get I2C sensor data via mobile app and ESP32.

1. Requirements

*Note: If the module is bricked after burning due to configuration file error, the user will be responsible for it. The module can only be burned once, please don't click "Burn/Program" to burn the module before confirming the configuration information, I2C sensors don't support "Run in RAM" test and can only be burned directly, it is recommended to use the Sensor Sample Configuration File provided by DFRobot. To use I2C sensors for which no profile is provided, please consult the tutorials in the Wiki.

2. Configuration of sensor beacon

Since the I2C configuration of the Fermion: BLE Sensor Beacon can only be burned once, it is recommended to first test the I2C communication control in a controller such as an Arduino for correctness using code programming.

Use the Arduino UNO to upload I2C to read the code and confirm that the sensor is working correctly Wire diagram can refer to SHT40(SEN0428)wiki

Code is as followed:

  #include <Wire.h>

  #define SHT40_ADDRESS 0x44 // I2C address of the sensor, here 0x44 for SHT40
  int l = 5;// Read Byte Length

  void setup(){
    Serial.begin(115200);
    Wire.begin();
  }

  void loop() {

    Wire.beginTransmission(SHT40_ADDRESS);
    Wire.write(0xFD);//i2ctx:3
    Wire.endTransmission();//i2c null

    delay(10); // The programme waits 10ms for the SHT40 to get ready

    Wire.requestFrom(SHT40_ADDRESS, 6);
    if (Wire.available() >= l) {
      byte data[l];
      for (int i = 0; i < l; i++) {//Read the data output from the I2C sensor
        data[i] = Wire.read();
        Serial.print(data[i], HEX);
        Serial.print(" ");
      }
    Serial.println();
    }
    Wire.endTransmission();//i2c null
    delay(1000); 
  }

When a value appears in the serial monitor, it means that the SHT40 sensor is outputting normally and you can continue with the following configuration.

Code Explanation: In common I2C communication sensors, the communication flow tends to be:

Step 1, The master writes a read command to the I2C of the sensor ——>the master reads data to the sensor

It is the master control that writes 0xFD byte to the SHT40 sensor. Checking the datasheet shows that the 0xFD byte is an instruction for the SHT40 sensor to measure temperature and humidity.

Step 2, the master waits for some time while the sensor prepares the data delay(10); Indicates that the master waits for 10ms, check the datasheet to find out: SHT40 recommends a minimum wait time of 1ms, but here we usually set the wait time to 10ms to be on the safe side.

Step three, the master requests data from the sensor Wire.requestFrom(SHT40_ADDRESS, 6);

It is the master requesting the SHT40 to read 6 bytes, checking the datasheet shows that this frame data: The 1st and 2nd bytes are temperature data, and the 3rd bit is CRC check. The 4th and 5th bytes are humidity data, and the 6th bit is CRC checksum.

/*
   Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp
   Ported to Arduino ESP32 by Evandro Copercini
   Changed to a beacon scanner to report iBeacon, EddystoneURL and EddystoneTLM beacons by beegee-tokyo
*/

#include <Arduino.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
#include <BLEEddystoneURL.h>
#include <BLEEddystoneTLM.h>
#include <BLEBeacon.h>
#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00) >> 8) + (((x)&0xFF) << 8))

float TemperatureData,HumidityData;
float Temperature,Humidity;

//Setting up ESP32 to scan for Bluetooth devices once every 5 seconds
int scanTime = 5; //In seconds
BLEScan *pBLEScan;

class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks
{
    void onResult(BLEAdvertisedDevice advertisedDevice)
    {
      if (advertisedDevice.haveName())
      {
        if(String(advertisedDevice.getName().c_str()) == "SHT40")//Scan for a Bluetooth device named SHT40
        {
          Serial.print("Device name: ");
          Serial.println(advertisedDevice.getName().c_str());
          std::string strManufacturerData = advertisedDevice.getManufacturerData();
          uint8_t cManufacturerData[100];
          strManufacturerData.copy((char *)cManufacturerData, strManufacturerData.length(), 0);
          Serial.printf("strManufacturerData: %d ", strManufacturerData.length());

          for (int i = 0; i < strManufacturerData.length(); i++)
          {
            Serial.printf("[%X]", cManufacturerData[i]);
          }

          //Getting raw data from SHT40
          TemperatureData = int(cManufacturerData[2]<<8 | cManufacturerData[3]);
          HumidityData = int(cManufacturerData[5]<<8 | cManufacturerData[6]);

          //Convert raw data into temperature and humidity data
          Temperature = (175 * TemperatureData/65535) - 45;
          Humidity = (125 * HumidityData/65535) - 6;

          Serial.println();
          Serial.print("TemperatureData:");Serial.print(Temperature);Serial.println("℃");   
          Serial.print("HumidityData:");Serial.print(Humidity);Serial.println("%");      
          Serial.println("------------------");       
        }        
      }
    }
};
void setup()
{
  Serial.begin(115200);
  Serial.println("Scanning...");

  BLEDevice::init("");
  pBLEScan = BLEDevice::getScan(); //create new scan
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
  pBLEScan->setInterval(100);
  pBLEScan->setWindow(99); // less or equal setInterval value
}
void loop()
{
  // put your main code here, to run repeatedly:
  BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
  pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
  delay(2000);
}

Dynamic Power Control

APP pop-up alerts

Fermion:Sensor beacons support APP pop-up alerts, you can set the threshold to trigger the mobile phone alerts, please see IN100 official tutorial for details

NanoBeacon Config Tool Instructions for Use

For more information on how to use the NanoBeacon Config Tool, see the software's user guide:NanoBeacon Config Tool User Guide EN.pdf

The user guide uses the "Beacon development kit", when using the Fermion: BLE Sensor Beacon, just use the 3.3V USB-TTL tool:

FAQ

The Github repository holds sample code and configuration files for the sensors we have tested. You are also welcome to contact us if you have a need for a new sensor adaptation.

For other questions, please see our FAQ about Fermion: BLE sensor Beacon topic in Forum.

More