ESP8266 and BMI160 sensor example

The BMI160 is a small, low power, low noise 16-bit inertial measurement unit designed for use in mobile applications like augmented reality or indoor navigation which require highly accurate, real-time sensor data.

In full operation mode, with both the accelerometer and gyroscope enabled, the current consumption is typically 950 μA, enabling always-on applications in battery driven devices. It is available in a compact 14-pin 2.5 x 3.0 x 0.8 mm³ LGA package.

Features

Parameter Technical data
Digital resolution Accelerometer (A): 16 bit
Gyroscope (G): 16bit
Measurement ranges
(programmable)
(A): ± 2 g, ± 4 g, ± 8 g, ± 16 g
(G): ± 125°/s, ± 250°/s, ± 500°/s, ± 1000°/s, ± 2000°/s
Sensitivity (calibrated) (A): ±2g: 16384LSB/g
±4g: 8192LSB/g
±8g: 4096LSB/g
±16g: 2048LSB/g
(G): ±125°/s: 262.4 LSB/°/s
±250°/s: 131.2 LSB/°/s
±500°/s: 65.6 LSB/°/s
±1000°/s: 32.8 LSB/°/s
±2000°/s: 16.4 LSB/°/s
Zero-g offset (typ., over life-time) (A): ±40mg (G): ± 10°/s
Noise density (typ.) (A): 180 μg/√Hz
(G): 0.008 °/s/√Hz
Bandwidths (programmable) 1600 Hz … 25/32 Hz
Digital inputs/outputs SPI, I²C, 4x digital
interrupts
Supply voltage (VDD) 1.71 … 3.6 V
I/0 supply voltage (VDDIO) 1.2 … 3.6 V
Temperature range -40 … +85°C
Current consumption
– full operation
– low-power mode
950 μA
3 μA
FIFO data buffer 1024 byte
LGA package 2.5 × 3.0 × 0.8 mm³
Shock resistance 10,000 g x 200 μs

Connection

 

Wemos pin Module Pin
3v3 3v3
Gnd Gnd
SDA/D2 SDA
SCL/D1 SCL

Code

This example used the following library – https://github.com/hanyazou/BMI160-Arduino

#include <BMI160Gen.h>
 
const int select_pin = 10;
const int i2c_addr = 0x69;
 
void setup() {
  Serial.begin(9600); // initialize Serial communication
  while (!Serial);    // wait for the serial port to open
 
  // initialize device
  //BMI160.begin(BMI160GenClass::SPI_MODE, select_pin);
  BMI160.begin(BMI160GenClass::I2C_MODE, i2c_addr);
}
 
void loop() {
  int gx, gy, gz;         // raw gyro values
 
  // read raw gyro measurements from device
  BMI160.readGyro(gx, gy, gz);
 
  // display tab-separated gyro x/y/z values
  Serial.print("g:\t");
  Serial.print(gx);
  Serial.print("\t");
  Serial.print(gy);
  Serial.print("\t");
  Serial.print(gz);
  Serial.println();
 
  delay(500);
}

Output

Open the serial monitor

g: 90 86 9
g: 69 69 40
g: 35 97 -9
g: -7370 3961 -1786
g: -31829 -2652 32767
g: -3221 25109 32767
g: 26020 31878 -26125
g: -20332 -21698 -15712
g: -7297 3463 -1723
g: -1137 1521 420
g: -203 305 96
g: 144 -102 54
g: 77 116 35

 

Links

https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMI160-DS000-07.pdf
CJMCU-160I BMI160 latest inertial measurement sensor attitude module 6DOF

ESP8266 and TCS34725 Color Sensor

The TCS3472 device provides a digital return of red, green, blue (RGB), and clear light sensing values. An IR blocking filter, integrated on-chip and localized to the color sensing photodiodes, minimizes the IR spectral component of the incoming light and allows color measurements to be made accurately. The high sensitivity, wide dynamic range, and IR blocking filter make the TCS3472 an ideal color sensor solution for use under varying lighting conditions and through attenuating materials. This data is transferred via an I2C to the host.

tcs47325 module

tcs47325 module

Connection and Layout

This example is for a Wemos Mini connected to the module

 

wemos and tcs34725

wemos and tcs34725

 

Code

We will use the adafruit library – https://github.com/adafruit/Adafruit_TCS34725

This is one of the default example

 

 

#include <Wire.h>
#include "Adafruit_TCS34725.h"
 
/* Example code for the Adafruit TCS34725 breakout library */
 
/* Connect SCL to analog 5
Connect SDA to analog 4
Connect VDD to 3.3V DC
Connect GROUND to common ground */
 
/* Initialise with default values (int time = 2.4ms, gain = 1x) */
// Adafruit_TCS34725 tcs = Adafruit_TCS34725();
 
/* Initialise with specific int time and gain values */
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
 
void setup(void) {
Serial.begin(9600);
 
if (tcs.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1);
}
 
// Now we're ready to get readings!
}
 
void loop(void) {
uint16_t r, g, b, c, colorTemp, lux;
 
tcs.getRawData(&r, &g, &b, &c);
colorTemp = tcs.calculateColorTemperature(r, g, b);
lux = tcs.calculateLux(r, g, b);
 
Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - ");
Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - ");
Serial.print("R: "); Serial.print(r, DEC); Serial.print(" ");
Serial.print("G: "); Serial.print(g, DEC); Serial.print(" ");
Serial.print("B: "); Serial.print(b, DEC); Serial.print(" ");
Serial.print("C: "); Serial.print(c, DEC); Serial.print(" ");
Serial.println(" ");
}

 

 

 

Output

Open the serial monitor, this is what you should see

Color Temp: 4554 K – Lux: 379 – R: 1122 G: 831 B: 776 C: 1429
Color Temp: 3173 K – Lux: 181 – R: 475 G: 339 B: 272 C: 707
Color Temp: 3425 K – Lux: 224 – R: 604 G: 435 B: 364 C: 868
Color Temp: 2833 K – Lux: 1497 – R: 2983 G: 2240 B: 1461 C: 5723
Color Temp: 5847 K – Lux: 109 – R: 4109 G: 1327 B: 890 C: 5814
Color Temp: 2767 K – Lux: 460 – R: 4468 G: 1703 B: 1062 C: 6734
Color Temp: 4381 K – Lux: 463 – R: 1379 G: 1012 B: 938 C: 1789
Color Temp: 4276 K – Lux: 588 – R: 1464 G: 1136 B: 997 C: 2153
Color Temp: 3952 K – Lux: 646 – R: 1424 G: 1135 B: 933 C: 2350
Color Temp: 3528 K – Lux: 835 – R: 1713 G: 1362 B: 1036 C: 3101

 

 

Links

TCS34725 RGB Light Color Sensor Recognition Module

ESP8266 and MLX90393 magnetic field sensor example

The MLX90393 magnetic field sensor can be reprogrammed to different modes and with different settings at run-time. The sensor offers a 16-bit output proportional to the magnetic flux density sensed along the XYZ axes using the Melexis proprietary Triaxis® technology and also offers a temperature output signal. These digital values are available via I2C and SPI, where the MLX90393 is a slave on the bus.

mlx90393 module

mlx90393 module

By selecting which axes are to be measured, the raw data can be used as input for further post-processing, such as for joystick applications, rotary knobs, and more complex 3D position sensing applications. Unparallelled performance is achieved with this sensor, which is primarily targeting industrial and consumer applications.

Connection

Module Wemos Mini
VDD 5v
Gnd Gnd
SDA SDA – A2
SCL SCL – A1

Code

 

// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// MLX90393
// This code is designed to work with the MLX90393_I2CS I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/products
 
#include<Wire.h>
 
// MLX90393 I2C Address is 0x0C(12)
#define Addr 0x0C
 
void setup() 
{
// Initialise I2C communication as MASTER 
Wire.begin();
// Initialise serial communication, set baud rate = 9600
Serial.begin(9600);
 
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Select Write register command
Wire.write(0x60);
// Set AH = 0x00, BIST disabled
Wire.write(0x00);
// Set AL = 0x5C, Hall plate spinning rate = DEFAULT, GAIN_SEL = 5 
Wire.write(0x5C);
// Select address register, (0x00 << 2)
Wire.write(0x00);
// Stop I2C Transmission
Wire.endTransmission();
 
// Request 1 byte of data
Wire.requestFrom(Addr, 1);
 
// Read status byte
if(Wire.available() == 1) 
{
unsigned int c = Wire.read();
}
 
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Select Write register command
Wire.write(0x60);
// Set AH = 0x02
Wire.write(0x02);
// Set AL = 0xB4, RES for magnetic measurement = 0
Wire.write(0xB4);
// Select address register, (0x02 << 2)
Wire.write(0x08);
// Stop I2C Transmission
Wire.endTransmission();
 
// Request 1 byte of data
Wire.requestFrom(Addr, 1);
 
// Read status byte
if(Wire.available() == 1) 
{
unsigned int c = Wire.read();
}
delay(300);
}
 
void loop() 
{
unsigned int data[7];
 
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Start single meaurement mode, ZYX enabled
Wire.write(0x3E);
// Stop I2C Transmission
Wire.endTransmission();
 
// Request 1 byte of data
Wire.requestFrom(Addr, 1);
 
// Read status byte
if(Wire.available() == 1) 
{
unsigned int c = Wire.read();
}
delay(100);
 
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Send read measurement command, ZYX enabled
Wire.write(0x4E);
// Stop I2C Transmission
Wire.endTransmission();
 
// Request 7 bytes of data
Wire.requestFrom(Addr, 7);
 
// Read 7 bytes of data
// status, xMag msb, xMag lsb, yMag msb, yMag lsb, zMag msb, zMag lsb
if(Wire.available() == 7);
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read();
data[4] = Wire.read();
data[5] = Wire.read();
data[6] = Wire.read();
}
 
// Convert the data
int xMag = data[1] * 256 + data[2];
int yMag = data[3] * 256 + data[4];
int zMag = data[5] * 256 + data[6];
 
// Output data to serial monitor
Serial.print("Magnetic Field in X-Axis : ");
Serial.println(xMag);
Serial.print("Magnetic Field in Y-Axis : ");
Serial.println(yMag);
Serial.print("Magnetic Field in Z-Axis : ");
Serial.println(zMag);
delay(500);
}

 

Output

Open the serial monitor and you should see something like this

Magnetic Field in X-Axis : 66
Magnetic Field in Y-Axis : 65458
Magnetic Field in Z-Axis : 8
Magnetic Field in X-Axis : 83
Magnetic Field in Y-Axis : 65477
Magnetic Field in Z-Axis : 65525
Magnetic Field in X-Axis : 76
Magnetic Field in Y-Axis : 65452
Magnetic Field in Z-Axis : 65506
Magnetic Field in X-Axis : 25
Magnetic Field in Y-Axis : 65374
Magnetic Field in Z-Axis : 65512
Magnetic Field in X-Axis : 80

 

Links

https://www.melexis.com/-/media/files/documents/datasheets/mlx90393-datasheet-melexis.pdf
CJMCU-90393, MLX90393 digital 3D Holzer sensor, displacement, angle, rotation, 3D position

ESP8266 and DS1624 sensor example

The DS1624 consists of two separate functional units: a 256-byte nonvolatile E2 memory and a direct-to-digital temperature sensor.

The nonvolatile memory is made up of 256 bytes of E2 memory. This memory can be used to store any type of information the user wishes. These memory locations are accessed through the 2-wire serial bus.

The direct-to-digital temperature sensor allows the DS1624 to measure the ambient temperature and report the temperature in a 12-bit word with 0.0625°C resolution. The temperature sensor and its related registers are accessed through the 2-wire serial interface. Figure 1 in the full data sheet shows a block diagram of the DS1624.

Features

Reduces Component Count with Integrated Temperature Sensor and Nonvolatile E2 Memory
Measures Temperatures from -55°C to +125°C in 0.0625°C Increments
±0.5°C Accuracy from 0°C to 70°C
256 Bytes of E2 Memory for Storing Information Such as Frequency Compensation Coefficients
No External Components
Easy-to-Use 2-Wire Serial Interface
Temperature is Read as a 12-Bit Value (2-Byte Transfer)
Available in 8-Pin SO and DIP Packages

 

Connection

Module Wemos Mini
VDD 3v3
Gnd Gnd
SDA SDA – D2
SCL SCL – D1

Code

I downloaded and imported the following library – https://github.com/bluemurder/DS1624

This is the example so some of the hard graft has already been done for you

#include <DS1624.h>
 
// Sensor presents all address pins connected to ground
DS1624 ds1624(0x00);
 
void setup()
{ 
// Begin serial connection at 9600 baud
Serial.begin(9600);
}
 
void loop()
{
float temperature;
bool valid;
 
// Get current temperature
ds1624.GetTemperature(temperature, valid);
 
// Print it
Serial.println(temperature);
 
// Wait a while
delay(1000);
}

 

Testing

Open the serial monitor and you should see the following

24.31
24.31
24.87
25.94
26.44
27.06
27.37
27.81
27.81
27.69

 

Link

https://datasheets.maximintegrated.com/en/ds/DS1624.pdf

CJMCU-1624 DS1624 temperature sensor, high precision digital thermometer with memory function