I am trying to make to make an impact sensor to test the effectiveness of different cushioning materials.
Anyway…
I have the the following parts:
SparkFun Triple Axis Accelerometer Breakout - H3LIS331DL
Adafruit Metro M4 feat. Microchip ATSAMD51
I have the power mode set to normal and the data rate set to 1000hz.
xl.setPowerMode(LIS331::NORMAL);
xl.setODR(LIS331::DR_1000HZ);
I put some serial print lines before and after the sensor read line to time the sensor read.
Serial.println("Start Read");
xl.readAxes(x, y, z); // The readAxes() function transfers the
// current axis readings into the three
// parameter variables passed to it.
Serial.println("End Read");
Here are he results on the serial monitor.
11:21:10.953 → Start Read
11:21:24.424 → End Read
14 seconds to read the sensor.
Is right? I hope I am doing something wrong. I was hoping to get data every millisecond or two.
Thanks.
P.S.
I am using the I2C code and wiring set up.
Hi Christopher.
With just that tiny bit of code, it’s hard to say what’s going on. Have you tried the example code on a 3.3 volt ATmega328 based board? I’m not even sure if this code executes properly on a SAMD51 based board or if something else is going on.
I will try the SPI hook up and code to see if that is better.
I have a standard RED-Board at home that isn’t dedicated to a project. I will try that one. But I think that board is 5v logic, right? That will kill the accelerometer, right?
Here is all of the code:
#include "SparkFun_LIS331.h"
#include <Wire.h>
LIS331 xl;
void setup()
{
// put your setup code here, to run once:
pinMode(9,INPUT); // Interrupt pin input
Wire.begin();
xl.setI2CAddr(0x19); // This MUST be called BEFORE .begin() so
// .begin() can communicate with the chip
xl.begin(LIS331::USE_I2C); // Selects the bus to be used and sets
// the power up bit on the accelerometer.
// Also zeroes out all accelerometer
// registers that are user writable.
xl.setPowerMode(LIS331::NORMAL);
xl.setODR(LIS331::DR_1000HZ);
// This next section configures an interrupt. It will cause pin
// INT1 on the accelerometer to go high when the absolute value
// of the reading on the Z-axis exceeds a certain level for a
// certain number of samples.
//xl.intSrcConfig(LIS331::INT_SRC, 1); // Select the source of the
// signal which appears on pin INT1. In
// this case, we want the corresponding
// interrupt's status to appear.
//xl.setIntDuration(50, 1); // Number of samples a value must meet
// the interrupt condition before an
// interrupt signal is issued. At the
// default rate of 50Hz, this is one sec.
//xl.setIntThreshold(2, 1); // Threshold for an interrupt. This is
// not actual counts, but rather, actual
// counts divided by 16.
//xl.enableInterrupt(LIS331::Z_AXIS, LIS331::TRIG_ON_HIGH, 1, true);
// Enable the interrupt. Parameters indicate
// which axis to sample, when to trigger
// (in this case, when the absolute mag
// of the signal exceeds the threshold),
// which interrupt source we're configuring,
// and whether to enable (true) or disable
// (false) the interrupt.
pinMode(13, OUTPUT);
Serial.begin(115200);
}
void loop()
{
int16_t x, y, z;
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
while(1==1)
{
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
Serial.println("Start Read");
xl.readAxes(x, y, z); // The readAxes() function transfers the
// current axis readings into the three
// parameter variables passed to it.
Serial.println("End Read");
//Serial.println(time);
//Serial.print(",");
Serial.print(xl.convertToG(100,x)); // The convertToG() function
Serial.print(",");
Serial.print(xl.convertToG(100,y)); // accepts as parameters the
Serial.print(",");
Serial.println(xl.convertToG(100,z)); // raw value and the current
// maximum g-rating.
}
}
I’m afraid I can’t debug your code, but like I said earlier, we haven’t tested this code or sensor on a SAMD51. You may need to modify the code and library for maximum performance on that platform.
Have you tried your code on a 3.3 volt Arduino Pro?
I switched the code and wires over to the SPI mode.
14:58:38.761 → Start Read
14:58:38.761 → End Read
I’m not sure if that is a good thing.
All I get for results are zeros across the board…
I guess I need to order a 3.3v Arduino Pro.
Would the “Pro Micro - 3.3V/8MHz” ?
I found a NANO in my box electronics bits.
The code up loaded and “seems” to work.
It prints values to the serial monitor. But the values don’t change when I move the sensor around.
Hi Christopher.
The Nano is a 5 volt board and the H3LIS331DL is a 3.3 volt device. That extra 1.7 volts can damage the sensor but I can’t say for sure if it’s dead or not. If you’re lucky it may still work, but it might be a good idea to get a replacement just in case it’s fried.
You’re going to want to try a 3.3 volt board like the 3.3 volt [Arduino Pro, a 3.3 volt [Pro Mini (either with a 3.3 volt [FTDI) or a 3.3 volt [Pro Micro.
I’d recommend the Arduino Pro or Pro Mini over the Pro Micro since it’s easy to get a Pro Micro into a state where it can’t accept new code. You can get it out of that state but it takes some work and skill to figure out how.](Pro Micro - 3.3V/8MHz - DEV-12587 - SparkFun Electronics)](https://www.sparkfun.com/products/13746)](https://www.sparkfun.com/products/11114)](https://www.sparkfun.com/products/10914)