Sensor (ADXL345 3 axis accelerometer) acting different when combined with Teensy 4.0

Status
Not open for further replies.

woutbog

New member
Hello, I'm designing a flight computer for my rocket, and I'm testing an accelerometer at the moment. So I followed an online tutorial that used a regular Arduino, but I wanted to log data so I ordered a Teensy because of it's speeds. When I connect it all the same as last time (with the nano), I now get these insane values "corresponding" to millimeters of acceleration. This can't be something good.


Here are some screenshots of results with Teensy 4.0 and the Arduino Nano, also a picture of how I have it wired up. The sensor uses the I2C protocol.

Code:
/*
    Arduino and ADXL345 Accelerometer Tutorial
     by Dejan, https://howtomechatronics.com
*/
#include <Wire.h>  // Wire library - used for I2C communication
int ADXL345 = 0x53; // The ADXL345 sensor I2C address
float X_out, Y_out, Z_out;  // Outputs
void setup() {
  Serial.begin(9600); // Initiate serial communication for printing the results on the Serial monitor
  Wire.begin(); // Initiate the Wire library
  // Set ADXL345 in measuring mode
  Wire.beginTransmission(ADXL345); // Start communicating with the device 
  Wire.write(0x2D); // Access/ talk to POWER_CTL Register - 0x2D
  // Enable measurement
  Wire.write(8); // (8dec -> 0000 1000 binary) Bit D3 High for measuring enable 
  Wire.endTransmission();
  delay(10);
}
void loop() {
  // === Read acceleromter data === //
  Wire.beginTransmission(ADXL345);
  Wire.write(0x32); // Start with register 0x32 (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(ADXL345, 6, true); // Read 6 registers total, each axis value is stored in 2 registers
  X_out = ( Wire.read()| Wire.read() << 8); // X-axis value
  X_out = X_out/256; //For a range of +-2g, we need to divide the raw values by 256, according to the datasheet
  Y_out = ( Wire.read()| Wire.read() << 8); // Y-axis value
  Y_out = Y_out/256;
  Z_out = ( Wire.read()| Wire.read() << 8); // Z-axis value
  Z_out = Z_out/256;
  Serial.print("Xa= ");
  Serial.print(X_out);
  Serial.print("   Ya= ");
  Serial.print(Y_out);
  Serial.print("   Za= ");
  Serial.println(Z_out);
  delay(100);
}

teensy.pngJPEG_20200703_210019.jpgnano.jpg

Thanks for reading this and all support is very welcome!

(Sorry about my English if it's bad, I'm not an native Englishman / American)
 
Just realised, don't mind the 100 delay at the end of the code, was testing if the speed of the Teensy was the issue, but gives same result.
 
Status
Not open for further replies.
Back
Top