Teensy 4.1 and ADXL345 accelerometer not working outside of Arduino IDE

Jim123

New member
I'm using a Teensy 4.1 with the Arduino IDE to interface with an Adafruit ADXL345 using a 4 wire SPI connection. It runs just fine when I upload the code from the IDE; however, if I disconnect from the IDE and power cycle the board, I get nothing from the accelerometer. It doesn't crash. I just get 0. Other parts of the code are fine. If I upload the code again from the IDE, it works again. I've attached my code. Any ideas?
 

Attachments

  • accelerometer_code.txt
    16.4 KB · Views: 15
Do you have something like this below in your code?
while (!Serial);
If so it will wait forever if NOT connected to the IDE,
If so try putting the code below in instead.
while (!Serial && (millis() < 3000));
 
Back
Top