IC2 Returns False Values

farmergregor

New member
I'm using a Teensy 4.1 to read acceleration data from a Adafruit ADXL345 accelerometer board over IC2. I've been able to properly read x,y,z acceleration values for the past couple of days. However, when I let the board run over night, and when I checked this morning, I read "garbage" acceleration values (x = 1.96, y = 2.04, z = 2.12... repeating over and over). The board is also not detected when I run "sensor test" from the from the adafruit library.

I hooked up a Teensy 3.2 using the same ADXL345 + code and am getting proper values. This points to the Teensy 4.1 being the issue.

What could be the issue here? Is it possible damage occurred to the IC2 bus overnight? Does something need to be reset? I'm an amateur as far of microcontrollers go, so any guidance would be greatly appreciated.

Thank you!


EDIT: Examples -> Wire -> Scanner also does not find the ADXL345 when using the Teensy 4.1. It does find the board when using the Teensy 3.2. The Teensy 4.1 had no issues finding the board until this morning.


Code. I am using the Adafruit provided sensor library
Code:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>

Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);

void setup(){
  //BEGIN SERIAL COMMUNICATION
  Serial.begin(115200);

  //SET PARAMETERS FOR ACCELEROMETER
  accel.begin();
  accel.setRange(ADXL345_RANGE_2_G);
  accel.setDataRate(ADXL345_DATARATE_100_HZ);
}

void loop() {
  sensors_event_t event; 
  accel.getEvent(&event);
  Serial.println("Accel Data");
  Serial.println(event.acceleration.x); 
  Serial.println(event.acceleration.y); 
  Serial.println(event.acceleration.z);
  Serial.println("");
  delay(1000);
}


Adafruit's Sensor Test:
Code:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>

/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);

void displaySensorDetails(void)
{
  sensor_t sensor;
  accel.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" m/s^2");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" m/s^2");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" m/s^2");  
  Serial.println("------------------------------------");
  Serial.println("");
  delay(500);
}

void displayDataRate(void)
{
  Serial.print  ("Data Rate:    "); 
  
  switch(accel.getDataRate())
  {
    case ADXL345_DATARATE_3200_HZ:
      Serial.print  ("3200 "); 
      break;
    case ADXL345_DATARATE_1600_HZ:
      Serial.print  ("1600 "); 
      break;
    case ADXL345_DATARATE_800_HZ:
      Serial.print  ("800 "); 
      break;
    case ADXL345_DATARATE_400_HZ:
      Serial.print  ("400 "); 
      break;
    case ADXL345_DATARATE_200_HZ:
      Serial.print  ("200 "); 
      break;
    case ADXL345_DATARATE_100_HZ:
      Serial.print  ("100 "); 
      break;
    case ADXL345_DATARATE_50_HZ:
      Serial.print  ("50 "); 
      break;
    case ADXL345_DATARATE_25_HZ:
      Serial.print  ("25 "); 
      break;
    case ADXL345_DATARATE_12_5_HZ:
      Serial.print  ("12.5 "); 
      break;
    case ADXL345_DATARATE_6_25HZ:
      Serial.print  ("6.25 "); 
      break;
    case ADXL345_DATARATE_3_13_HZ:
      Serial.print  ("3.13 "); 
      break;
    case ADXL345_DATARATE_1_56_HZ:
      Serial.print  ("1.56 "); 
      break;
    case ADXL345_DATARATE_0_78_HZ:
      Serial.print  ("0.78 "); 
      break;
    case ADXL345_DATARATE_0_39_HZ:
      Serial.print  ("0.39 "); 
      break;
    case ADXL345_DATARATE_0_20_HZ:
      Serial.print  ("0.20 "); 
      break;
    case ADXL345_DATARATE_0_10_HZ:
      Serial.print  ("0.10 "); 
      break;
    default:
      Serial.print  ("???? "); 
      break;
  }  
  Serial.println(" Hz");  
}

void displayRange(void)
{
  Serial.print  ("Range:         +/- "); 
  
  switch(accel.getRange())
  {
    case ADXL345_RANGE_16_G:
      Serial.print  ("16 "); 
      break;
    case ADXL345_RANGE_8_G:
      Serial.print  ("8 "); 
      break;
    case ADXL345_RANGE_4_G:
      Serial.print  ("4 "); 
      break;
    case ADXL345_RANGE_2_G:
      Serial.print  ("2 "); 
      break;
    default:
      Serial.print  ("?? "); 
      break;
  }  
  Serial.println(" g");  
}

void setup(void) 
{
#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif
  Serial.begin(9600);
  Serial.println("Accelerometer Test"); Serial.println("");
  
  /* Initialise the sensor */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
    while(1);
  }

  /* Set the range to whatever is appropriate for your project */
  accel.setRange(ADXL345_RANGE_16_G);
  // accel.setRange(ADXL345_RANGE_8_G);
  // accel.setRange(ADXL345_RANGE_4_G);
  // accel.setRange(ADXL345_RANGE_2_G);
  
  /* Display some basic information on this sensor */
  displaySensorDetails();
  
  /* Display additional settings (outside the scope of sensor_t) */
  displayDataRate();
  displayRange();
  Serial.println("");
}

void loop(void) 
{
  /* Get a new sensor event */ 
  sensors_event_t event; 
  accel.getEvent(&event);
 
  /* Display the results (acceleration is measured in m/s^2) */
  Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print("  ");
  Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print("  ");
  Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print("  ");Serial.println("m/s^2 ");
  delay(500);
}
 
Last edited:
I'm using a Teensy 4.1 to read acceleration data from a Adafruit ADXL345 accelerometer board over IC2. I've been able to properly read x,y,z acceleration values for the past couple of days. However, when I let the board run over night, and when I checked this morning, I read "garbage" acceleration values (x = 1.96, y = 2.04, z = 2.12... repeating over and over). The board is also not detected when I run "sensor test" from the from the adafruit library.


Can you show how you've wired this up? The T4.x is not 5V tolerant for instance and so you have to be careful how you apply voltages to the level converters in the Adafruit breakout.

[ I2C = IIC = inter-integrated-circuit bus. Another typo there :) ]
 
Can you show how you've wired this up? The T4.x is not 5V tolerant for instance and so you have to be careful how you apply voltages to the level converters in the Adafruit breakout.

[ I2C = IIC = inter-integrated-circuit bus. Another typo there :) ]

Image attached.

The ADXL345 has the following silk screened on the board "VIN: 3.3-5.0V" and "Logic: 3-5V safe". Hopefully there is not a voltage compatibility issue.

I believe the Adafruit ADXL345 has a built in resistor so an external 4.7K pull up resistor is not needed. Otherwise I am relying on the Teensy 4.1 build in pullup resistor. I've also tested with an Adafruit ADXL343 which definitely states it has an internal pullup resistor for SCL and SDA. Neither ADXL boards currently work with the Teensy 4.1 (but did prior to this morning). Both still work with the Teensy 3.2 I have.

I also have an IR LED + Receiver hooked up in the mix for motion detection for the project I am working on.

For the Teensy 4.1 I'm using SCL = Pin 19 and SDA = Pin 18. I've triple checked the wiring, but nothing on the hardware side should have changed between last night and this morning. It was left powered on overnight, but I do not see any physical damage to the board, and I've made sure all interconnects have continuity.

Circuit.PNG
 

Attachments

  • Circuit.PNG
    Circuit.PNG
    15.8 KB · Views: 24
From the Adafruit site:

VIN - This is the input to the 3.3V voltage regulator, which makes it possible to use the 3.3V sensor on 5V systems. It also determines the logic level of the SCL and SDA pins. Connect this to 3.3V on the MCU for 3.3V boards (Adafruit Feathers), or 5.0V for 5V Arduinos (Arduino Uno, etc.).

If you have it powered with 5 volts, you may have damaged the Teensy 4.1
 
Back
Top