Skip to content

Accelerometer BMA250 Sensor Wireling Tutorial

TinyCircuits Accelerometer Wireling product photo

This Wireling features the high performance and low power Bosch BMA250 3-axis accelerometer. The BMA250 allows measurement of accelerations in three perpendicular axes and thus senses tilt, motion, shock, tap, and vibration in your projects. There is also an integrated temperature sensor built into this tiny sensor.

Technical Details Bosch BMA250 Accelerometer Specs
  • 3-axis (X, Y & Z)
  • Digital resolution: 10bit
  • Resolution: 3.9mg
  • Measurement ranges: +-2g, +-4g, +-8g, +-16g
  • Sensitivity: 2g: 256LSB/g, 4g: 128LSB/g, 8g: 64LSB/g, 16g: 32LSB/g
  • Zero-g offset (over lifetime): +-80mg
  • Bandwidths: 1000Hz… 8Hz
  • Low Power: 139uA @2kHz data rate
TinyDuino Power Requirements
  • Voltage: 3.0V - 5.5V
  • Current: 139uA (Normal Mode).  Due to the low current, this board can be run using the TinyDuino coin cell option
Pins Used
  • A5/SCL - I2C Serial Clock line
  • A4/SDA - I2C Serial Data line
  • A(x)/INT - Interrupt Pin 
    • Note: (x) corresponds to the Wireling port
Dimensions
  • 10mm x 10mm (.394 inches x .394 inches)
  • Max Height (from lower bottom of Wireling to upper top Wireling Connector): 3.63mm (0.143 inches)
  • Weight: 1 gram (.04 ounces)

Materials

To interface with any TinyCircuits Arduino board, you will need the Arduino IDE and a Micro USB Cable

There are multiple processor/adapter combinations that can be used with Wirelings. Use the following table to find the combination that works for you.

Processor Adapter
* and
*
*
N/A
* N/A
Arduino
Raspberry Pi

* These processors have a 32-pin connector and can have multiple Wireling Adapter TinyShields stacked to increase the number of Wireling ports up to a maximum of 32 total Wireling ports.

In order to interface with Wirelings, you'll need the appropriate number of Wireling Cables and the Wireling.h Library (You can download this from GitHub as linked, or from the Library Manager in the Arduino IDE).

You will also need the Accelerometer Wireling and the included example Arduino sketch.

Wireling Code
Port 0

Bonus Example: Double Tap Recognition - To trigger the double tap detection, lay the accelerometer sensor flat loosely by holding the Wireling cable, and gently tap the Wireling connector twice (This program is mutually exclusive to the Example Sketch due to different register manipulation)


Hardware Assembly

Depending on the development system you choose, you will need to put together a TinyDuino stack using the 32-pin tan connectors, or you will just need to plug in your Wireling to Port 0 using a Wireling Cable. (You can change this port in the included Arduino Sketch using the Wireling.selectPort() function)

NOTE: Be mindful when inserting Wireling Cables - the connector pins inside the 5-pin connectors on Wirelings can be bent when cables are inserted at an angle.

TinyCircuits Accelerometer Wirelng assembly with WirelingZero


Software Setup

If you have not already done so, download the Accelerometer Wireling Example Sketch and open it in the Arduino IDE. All the necessary files for the program are included in the zipped folder.

Make the correct Tools selections for your development board. If unsure, you can double check the Help page that mentions the Tools selections needed for any TinyCircuits processor.


Upload Program

In this program, the BMA250 has the four available sensor readings output to the Serial Monitor, OR the Serial Plotter, you can find these options under the Tools tab. The Serial Monitor will output the data readings of the sensor, which may not be very easy to read long term. The Serial Plotter, however, graphs the sensor data, and is nice to look at when you want to see data over time. The four variables being output are three axes of perpendicular acceleration x, y, and z, and the temperature in degrees Celsius.

Code
/*************************************************************************
 * Accelerometer BMA250 Wireling Tutorial:
 * This example program will show the basic method of printing out the 
 * accelerometer values from the BMA250 to the Serial Monitor/Serial Plotter
 * 
 * Hardware by: TinyCircuits
 * Code by: Laveréna Wienclaw for TinyCircuits
 *
 * Initiated: 11/29/2017 
 * Updated: 12/06/2019
 ************************************************************************/

#include <Wire.h>         // For I2C communication with sensor
#include <Wireling.h>     // For interfacing with Wirelings
#include "BMA250.h"       // For interfacing with the accel. sensor

// Accelerometer sensor variables for the sensor and its values
BMA250 accel_sensor;
int x, y, z, temp;

// Make Serial Monitor compatible for all TinyCircuits processors
#if defined(ARDUINO_ARCH_AVR)
  #define SerialMonitorInterface Serial
#elif defined(ARDUINO_ARCH_SAMD)
  #define SerialMonitorInterface SerialUSB
#endif

void setup() {
  SerialMonitorInterface.begin(115200);
  Wire.begin();

  // Initialize Wireling
  Wireling.begin();
  Wireling.selectPort(0); 

  // Sets up the BMA250 accelerometer
  accel_sensor.begin(BMA250_range_2g, BMA250_update_time_64ms); 
}

void loop() {
  accel_sensor.read();//This function gets new data from the accelerometer

  // Get the acceleration values from the sensor and store them into local variables
  // (Makes reading the rest of the program easier)
  x = accel_sensor.X;
  y = accel_sensor.Y;
  z = accel_sensor.Z;
  temp = ((accel_sensor.rawTemp * 0.5) + 24.0, 1);

 // If the BMA250 is not found, nor connected correctly, these values will be produced
 // by the sensor 
  if (x == -1 && y == -1 && z == -1) {
    // Print error message to Serial Monitor
    SerialMonitorInterface.print("ERROR! NO BMA250 DETECTED!");
  }
  else { // if we have correct sensor readings: 
    showSerial();                 //Print to Serial Monitor or Serial Plotter
  }

  // The BMA250 can only poll new sensor values every 64ms, so this delay
  // will ensure that we can continue to read values
  delay(250);
  // ***Without the delay, there would not be any sensor output*** 
}

// Prints the sensor values to the Serial Monitor (found under 'Tools')
void showSerial() {
  SerialMonitorInterface.print("X = ");
  SerialMonitorInterface.print(x);

  SerialMonitorInterface.print("  Y = ");
  SerialMonitorInterface.print(y);

  SerialMonitorInterface.print("  Z = ");
  SerialMonitorInterface.print(z);

  SerialMonitorInterface.print("  Temperature(C) = ");
  SerialMonitorInterface.println((accel_sensor.rawTemp * 0.5) + 24.0, 1);
}

If you have never used the Serial Plotter, now is a good time to start! This tool makes a good visualization of the range of sensor readings! Here is an example of my data when I was waving the sensor around every couple of seconds:

TinyCircuits Accelerometer Wireling Serial Plotter Arduino output
The constant, turquoise-colored value is the temperature reading.


Downloads


Contact Us

If you have any questions or feedback, feel free to email us or make a post on our forum. Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it.

Thanks for making with us!