https://community.bosch-sensortec.com/mems-sensors-forum-jrmujtaw/post/bma400-fall-detection-
mRv3lE7Pv1DrE91
with the given code link, I was trying to compile using the Arduino IDE, I keep getting following error:
Compilation error: 'Write' was not declared in this scope
In the following code lines...wherever we have write action, I see it pops up above error.....
Any suggestions on, do I include define the write related on the top of the instantiation section ?
code loaded into arduino IDE is :
#include <Wire.h>
#include <iostream>
#include "SparkFun_BMA400_Arduino_Library.h"
// Create a new sensor object
BMA400 accelerometer;
// I2C address selection
uint8_t i2cAddress = BMA400_I2C_ADDRESS_DEFAULT; // 0x14
//uint8_t i2cAddress = BMA400_I2C_ADDRESS_SECONDARY; // 0x15
// Pin used for interrupt detection
int interruptPin = 1;
// Flag to know when interrupts occur
volatile bool interruptOccurred = false;
void setup()
{
// Start serial
Serial.begin(115200);
Serial.println("BMA400 Example 3 - Interrupts");
// Initialize the I2C library
Wire.begin();
// Check if sensor is connected and initialize
// Address is optional (defaults to 0x14)
while(accelerometer.beginI2C(i2cAddress) != BMA400_OK)
{
// Not connected, inform user
Serial.println("Error: BMA400 not connected, check wiring and I2C address!");
// Wait a bit to see if connection is established
delay(1000);
}
Serial.println("BMA400 connected!");
// The default ODR (output data rate) is 200Hz, which is too fast to read
// reasonably. Here we reduce the ODR to the minimum of 12.5Hz
accelerometer.setODR(BMA400_ODR_12_5HZ);
// The BMA400 has 2 interrupt pins. All interrupt conditions can be mapped
// to either pin, so we'll just choose the first one for this example
accelerometer.setDRDYInterruptChannel(BMA400_INT_CHANNEL_1);
// Here we configure the INT1 pin to push/pull mode, active high
accelerometer.setInterruptPinMode(BMA400_INT_CHANNEL_1,
BMA400_INT_PUSH_PULL_ACTIVE_1);
// Enable DRDY interrupt condition
accelerometer.enableInterrupt(BMA400_DRDY_INT_EN, false);
// Setup interrupt handler
attachInterrupt(digitalPinToInterrupt(interruptPin), bma400InterruptHandler, RISING);
}
void init_BMA400(void)
{
// configure common control registers
Write 0x02 to register 0x19; // bring BMA400 to normal mode form sleep mode
Write 0x49 to register 0x1A; // set BMA400 to 200Hz ODR, +/-4g full scale range and 0 over sampling
rate (OSR) meaning one single measurement without averaging. The current consumption is
about 3.5uA
Write 0x00 to register 0x1B; // select acc_filt1 200Hz as source for data registers
// configure generic interrupt 1 parameters
Write 0xF0 to register 0x3F; // enable X/Y/Z axis for interrupt evaluation. Gen1 interrupt engine data
source is acc_filt2 which is fixed 100Hz ODR or 10ms time interval. Manual update and
hysteresis 0mg
Write 0x01 to register 0x40; // select inactivity detection which means the interrupt will be generated
within the positive and negative threshold zone. Select AND logic meaning that when all enabled
axes enter the threshold zone simultaneously an interrupt will be generated
Write 0x3F to register 0x41; // set inactivity threshold to 0x3F = 63LSBs = 63LSBs * 8mg/LSB = 504mg
(can be fine-tuned). So the threshold zone is +/-504mg
Write 0x00 to register 0x42; // set MSB of Gen1 interrupt duration to 0x00
Write 0x0C to register 0x43; // set LSB of Gen1 interrupt duration to 0x0C = 12LSBs = 12 * 10ms =120ms
(can be fine-tuned). This corresponds to about 7cm height freefall. H = 0.5 * g * t^2 = 0.5 *
9.81m/s^2 * (0.12s)^2
Write 0x00 to register 0x44;
Write 0x00 to register 0x45; // set X axis reference to 0mg
Write 0x00 to register 0x46;
Write 0x00 to register 0x47; // set Y axis reference to 0mg
Write 0x00 to register 0x48;
Write 0x00 to register 0x49; // set Z axis reference to 0mg. Because the manual update is selected for
Gen1, every 10ms BMA400 Gen1 will compare the X/Y/Z measurement data against the X/Y/Z
references respectively to check if the differences are all within the threshold or not. If yes, then the
duration timer will start counting. If not, then the duration timer will be reset to 0.
// configure interrupt registers
Write 0x04 to register 0x1F; // enable generic interrupt 1 (Gen1)
Write 0x04 to register 0x21; // route Gen1 interrupt signal to INT1 pin
Write 0x22 to register 0x24; // set INT1 pin and INT2 pin both to push-pull and active-high
}
void loop()
{
// Wait for interrupt to occur
// if(interruptOccurred)
{
// Reset flag for next interrupt
interruptOccurred = false;
Serial.print("Interrupt occurred!");
Serial.print("\t");
accelerometer.getSensorData();
// Print acceleration data
Serial.print("Acceleration in g's");
Serial.print("\t");
Serial.print("X: ");
Serial.print(accelerometer.data.accelX, 3);
Serial.print("\t");
Serial.print("Y: ");
Serial.print(accelerometer.data.accelY, 3);
Serial.print("\t");
Serial.print("Z: ");
Serial.println(accelerometer.data.accelZ, 3);
// Get the interrupt status to know which condition triggered
uint16_t interruptStatus = 2;
accelerometer.getInterruptStatus(&interruptStatus);
// Check if this is the "data ready" interrupt condition
if(interruptStatus & BMA400_ASSERTED_DRDY_INT)
{
// Get measurements from the sensor. This must be called before
// accessing the acceleration data, otherwise it will never update
accelerometer.getSensorData();
// Print acceleration data
Serial.print("Acceleration in g's");
Serial.print("\t");
Serial.print("X: ");
Serial.print(accelerometer.data.accelX, 3);
Serial.print("\t");
Serial.print("Y: ");
Serial.print(accelerometer.data.accelY, 3);
Serial.print("\t");
Serial.print("Z: ");
Serial.println(accelerometer.data.accelZ, 3);
}
else
{
Serial.println("Wrong interrupt condition!");
}
}
}
void bma400InterruptHandler()
{
interruptOccurred = false;
}
Remove this part (if it's part of your code) or make it a comment:
https://community.bosch-sensortec.com/mems-sensors-forum-jrmujtaw/post/bma400-fall-detection-
mRv3lE7Pv1DrE91
with the given code link, I was trying to compile using the Arduino IDE, I keep getting following error:
Compilation error: 'Write' was not declared in this scope
In the following code lines...wherever we have write action, I see it pops up above error.....
Any suggestions on, do I include define the write related on the top of the instantiation section ?
code loaded into arduino IDE is :
If you mean that the Arduino forum did add that I have serious doubts. Things like Write 0x02 to register 0x19; in init_BMA400() are not added during a copy/paste to the forum. And there are inconsistencies in the way HTML tags are used; this would have been consistent.
I've fixed your code; note that init_BMA400 does not do anything anymore.
#include <Wire.h>
#include <iostream>
#include "SparkFun_BMA400_Arduino_Library.h"
// Create a new sensor object
BMA400 accelerometer;
// I2C address selection
uint8_t i2cAddress = BMA400_I2C_ADDRESS_DEFAULT; // 0x14
//uint8_t i2cAddress = BMA400_I2C_ADDRESS_SECONDARY; // 0x15
// Pin used for interrupt detection
int interruptPin = 1;
// Flag to know when interrupts occur
volatile bool interruptOccurred = false;
void setup()
{
// Start serial
Serial.begin(115200);
Serial.println("BMA400 Example 3 - Interrupts ");
// Initialize the I2C library
Wire.begin();
// Check if sensor is connected and initialize
// Address is optional (defaults to 0x14)
while (accelerometer.beginI2C(i2cAddress) != BMA400_OK)
{
// Not connected, inform user
Serial.println("Error: BMA400 not connected, check wiring and I2C address !");
// Wait a bit to see if connection is established
delay(1000);
}
Serial.println("BMA400 connected !");
// The default ODR (output data rate) is 200Hz, which is too fast to read
// reasonably. Here we reduce the ODR to the minimum of 12.5Hz
accelerometer.setODR(BMA400_ODR_12_5HZ);
// The BMA400 has 2 interrupt pins. All interrupt conditions can be mapped
// to either pin, so we'll just choose the first one for this example
accelerometer.setDRDYInterruptChannel(BMA400_INT_CHANNEL_1);
// Here we configure the INT1 pin to push/pull mode, active high
accelerometer.setInterruptPinMode(BMA400_INT_CHANNEL_1,
BMA400_INT_PUSH_PULL_ACTIVE_1);
// Enable DRDY interrupt condition
accelerometer.enableInterrupt(BMA400_DRDY_INT_EN, false);
// Setup interrupt handler
attachInterrupt(digitalPinToInterrupt(interruptPin), bma400InterruptHandler, RISING);
}
void init_BMA400(void)
{
/*
// configure common control registers
Write 0x02 to register 0x19; // bring BMA400 to normal mode form sleep mode
Write 0x49 to register 0x1A; // set BMA400 to 200Hz ODR, +/-4g full scale range and 0 over sampling
rate(OSR) meaning one single measurement without averaging.The current consumption is
about 3.5uA
Write 0x00 to register 0x1B; // select acc_filt1 200Hz as source for data registers
// configure generic interrupt 1 parameters
Write 0xF0 to register 0x3F; // enable X/Y/Z axis for interrupt evaluation. Gen1 interrupt engine data
source is acc_filt2 which is fixed 100Hz ODR or 10ms time interval.Manual update and hysteresis 0mg
Write 0x01 to register 0x40; // select inactivity detection which means the interrupt will be generated
within the positive and negative threshold zone.Select AND logic meaning that when all enabled
axes enter the threshold zone simultaneously an interrupt will be generated
Write 0x3F to register 0x41; // set inactivity threshold to 0x3F = 63LSBs = 63LSBs * 8mg/LSB = 504mg
(can be fine - tuned).So the threshold zone is + / -504mg Write 0x00 to register 0x42; // set MSB of Gen1 interrupt duration to 0x00
Write 0x0C to register 0x43; // set LSB of Gen1 interrupt duration to 0x0C = 12LSBs = 12 * 10ms =120ms
(can be fine - tuned).This corresponds to about 7cm height freefall.H = 0.5 *g *t ^ 2 = 0.5 * 9.81m / s ^ 2 * (0.12s) ^ 2 Write 0x00 to register 0x44;
Write 0x00 to register 0x45; // set X axis reference to 0mg
Write 0x00 to register 0x46;
Write 0x00 to register 0x47; // set Y axis reference to 0mg
Write 0x00 to register 0x48;
Write 0x00 to register 0x49; // set Z axis reference to 0mg. Because the manual update is selected for
Gen1, every 10ms BMA400 Gen1 will compare the X / Y / Z measurement data against the X / Y / Z references respectively to check if the differences are all within the threshold or not .If yes, then the duration timer will start counting.If not, then the duration timer will be reset to 0.
// configure interrupt registers
Write 0x04 to register 0x1F; // enable generic interrupt 1 (Gen1)
Write 0x04 to register 0x21; // route Gen1 interrupt signal to INT1 pin
Write 0x22 to register 0x24; // set INT1 pin and INT2 pin both to push-pull and active-high
*/
}
void loop()
{
// Wait for interrupt to occur
// if(interruptOccurred)
{
// Reset flag for next interrupt
interruptOccurred = false;
Serial.print("Interrupt occurred !");
Serial.print("\t ");
accelerometer.getSensorData();
// Print acceleration data
Serial.print("Acceleration in g & #39; s ");
Serial.print("\t ");
Serial.print("X: ");
Serial.print(accelerometer.data.accelX, 3);
Serial.print("\t ");
Serial.print("Y: ");
Serial.print(accelerometer.data.accelY, 3);
Serial.print("\t ");
Serial.print("Z: ");
Serial.println(accelerometer.data.accelZ, 3);
// Get the interrupt status to know which condition triggered
uint16_t interruptStatus = 2;
accelerometer.getInterruptStatus(&interruptStatus);
// Check if this is the "data ready"interrupt condition
if (interruptStatus & BMA400_ASSERTED_DRDY_INT)
{
// Get measurements from the sensor. This must be called before
// accessing the acceleration data, otherwise it will never update
accelerometer.getSensorData();
// Print acceleration data
Serial.print("Acceleration in g & #39; s ");
Serial.print("\t ");
Serial.print("X: ");
Serial.print(accelerometer.data.accelX, 3);
Serial.print("\t ");
Serial.print("Y: ");
Serial.print(accelerometer.data.accelY, 3);
Serial.print("\t ");
Serial.print("Z: ");
Serial.println(accelerometer.data.accelZ, 3);
}
else
{
Serial.println("Wrong interrupt condition !");
}
}
}
void bma400InterruptHandler()
{
interruptOccurred = false;
}
I suggest that you study the examples that come with the BMA400 examples and next write your own code based on that.
Thank you for the response. I did try the shared code, only difference I see is write function into registers is not considered. But still appreciate your help in checking my request.
Any tips about how to implement write option into the register?
Following is the response I got from Arduino team :
The error you are encountering, indicates that the compiler cannot find the definition for the Write function. This is because Write is not a standard Arduino or C++ function.
It looks like you're trying to do low level control of the device by writing directly to it's control registers. If that's what you really want, then you don't need the library. Instead, implement your own driver code to communicate with the device via I2C or SPI.