Hi everyone, I'm feeling kind of desperate as I have a high altitude balloon launch in a week and I put off making a parachute release until this week because I thought it was going to be the easiest of the coding I would have to do. I'm using a nano and a LIS3DH Arduino | Adafruit LIS3DH Triple-Axis Accelerometer Breakout | Adafruit Learning System 3 axis accelerometer which is listed as having free fall detection but I can't find any code. I do have the example sketches working on it and googled the hell out of it but now I'm getting worried. It's seeming a bit more complicated then the level I'm at.
I know people probably don't love the "I'm stuck can you write my code" but but any advice would be greatly appreciated.
Post your code. Think about the information people might need to help. If you are waiting for the one person in a million that has used that exact functionality of that exact component then you might be waiting a while. However if you precide the information then anyone with a reasonable understanding of electronics and code might help. N1<N2!
The manufacturer's sensor data sheet and application notes are the very best source of information. Study the data sheet on interrupt conditions carefully, then write the four or five lines of code required to set it up and read the status register or output.
You might check the ST product page to see if there is an application note on free fall detection.
Fair enough! Here is the code I am using. I'm trying to read the x-y-z axis for a zero reading on each for about 500 ms because there may be a false trigger at points during the flight on the module. I will have it trigger a servo to deploy the parachute.
// Basic demo for accelerometer readings from Adafruit LIS3DH
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>
// Used for software SPI
#define LIS3DH_CLK 5
#define LIS3DH_MISO 12
#define LIS3DH_MOSI 4
// Used for hardware & software SPI
#define LIS3DH_CS 10
// software SPI
//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS, LIS3DH_MOSI, LIS3DH_MISO, LIS3DH_CLK);
// hardware SPI
//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS);
// I2C
Adafruit_LIS3DH lis = Adafruit_LIS3DH();
void setup(void) {
Serial.begin(115200);
while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("LIS3DH test!");
if (! lis.begin(0x18)) { // change this to 0x19 for alternative i2c address
Serial.println("Couldnt start");
while (1) yield();
}
Serial.println("LIS3DH found!");
// lis.setRange(LIS3DH_RANGE_4_G); // 2, 4, 8 or 16 G!
Serial.print("Range = "); Serial.print(2 << lis.getRange());
Serial.println("G");
// lis.setDataRate(LIS3DH_DATARATE_50_HZ);
Serial.print("Data rate set to: ");
switch (lis.getDataRate()) {
case LIS3DH_DATARATE_1_HZ: Serial.println("1 Hz"); break;
case LIS3DH_DATARATE_10_HZ: Serial.println("10 Hz"); break;
case LIS3DH_DATARATE_25_HZ: Serial.println("25 Hz"); break;
case LIS3DH_DATARATE_50_HZ: Serial.println("50 Hz"); break;
case LIS3DH_DATARATE_100_HZ: Serial.println("100 Hz"); break;
case LIS3DH_DATARATE_200_HZ: Serial.println("200 Hz"); break;
case LIS3DH_DATARATE_400_HZ: Serial.println("400 Hz"); break;
case LIS3DH_DATARATE_POWERDOWN: Serial.println("Powered Down"); break;
case LIS3DH_DATARATE_LOWPOWER_5KHZ: Serial.println("5 Khz Low Power"); break;
case LIS3DH_DATARATE_LOWPOWER_1K6HZ: Serial.println("16 Khz Low Power"); break;
}
}
void loop() {
lis.read(); // get X Y and Z data at once
// Then print out the raw data
Serial.print("X: "); Serial.print(lis.x);
Serial.print(" \tY: "); Serial.print(lis.y);
Serial.print(" \tZ: "); Serial.print(lis.z);
/* Or....get a new sensor event, normalized */
sensors_event_t event;
lis.getEvent(&event);
/* Display the results (acceleration is measured in m/s^2) */
Serial.print("\t\tX: "); Serial.print(event.acceleration.x);
Serial.print(" \tY: "); Serial.print(event.acceleration.y);
Serial.print(" \tZ: "); Serial.print(event.acceleration.z);
Serial.println(" m/s^2 ");
Serial.println();
delay(200);
}
Don't you want the vector sum to be zero. Root sum of squares to be zero?
Small magnitude. Zero is extremely unlikely.
The point being that it is unlikely that any one axis will be 'zero' for anything more than a moment.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.