I'm being driven mad by my custom PCB with a ESP32 C3 WROOM module, I'm connecting direct to the USB of the module and have been flashing it without any issues and receiving data back into the serial monitor on Arduino IDE 2.3.3.
I have an accelerometer SC7A20 connected via I2C and using serial.print() to view the data, yesterday I tried to edit the code to include an OLED display on the I2C without success (in another post), I then removed all the OLED code and went back to just the Accelerometer code but I cannot get any serial output any more.
Here are my settings
I have USBCDC on boot enabled but I get nothing whe I use the following code, whereas I have previously.
I have tried some other code with serial output which seems to work, maybe I've messed something up from my original working code and caan't see it.
Any suggetions?
#include <Wire.h>
#include "SparkFun_LIS2DH12.h" //Click here to get the library: http://librarymanager/All#SparkFun_LIS2DH12
#define LIS2DH12_ID = 0x11; //Device ID of SC7a20 LIS2DH12 is 0x33, THIS IS NOT THE I2C ID (19)
//#define LIS2DH12_I2C_ADD_L = 0x19;
SPARKFUN_LIS2DH12 accel; //Create instance
const int numReadings = 10; //Number of reading to average over
const int sampleDelay = 100; //Number of miliseconds delay betweem samples
float xreadings[numReadings]; // the readings from the analog input
int xreadIndex = 0; // the index of the current reading
int xtotal = 0; // the running total
int xaverage = 0; // the average
float yreadings[numReadings]; // the readings from the analog input
int yreadIndex = 0; // the index of the current reading
int ytotal = 0; // the running total
int yaverage = 0; // the average
float zreadings[numReadings]; // the readings from the analog input
int zreadIndex = 0; // the index of the current reading
int ztotal = 0; // the running total
int zaverage = 0; // the average
void setup() {
Wire.begin(4, 5); //set the I2C SDA and SCL Pins
// initialize serial communication with computer:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB
}
Serial.println("SparkFun Accel Example");
if (accel.begin() == false) {
Serial.println("Accelerometer not detected. Are you sure you did a Wire1.begin()? Freezing...");
while (1)
;
}
// initialize all the readings to 0:
for (int thisxReading = 0; thisxReading < numReadings; thisxReading++) {
xreadings[thisxReading] = 0;
}
for (int thisyReading = 0; thisyReading < numReadings; thisyReading++) {
yreadings[thisyReading] = 0;
}
for (int thiszReading = 0; thiszReading < numReadings; thiszReading++) {
zreadings[thiszReading] = 0;
}
}
void loop() {
// subtract the last reading:
xtotal = xtotal - xreadings[xreadIndex];
ytotal = ytotal - yreadings[yreadIndex];
ztotal = ztotal - zreadings[zreadIndex];
// read from the sensor:
xreadings[xreadIndex] = accel.getX();
yreadings[yreadIndex] = accel.getY();
zreadings[zreadIndex] = accel.getZ();
// add the reading to the total:
xtotal = xtotal + xreadings[xreadIndex];
ytotal = ytotal + yreadings[yreadIndex];
ztotal = ztotal + zreadings[zreadIndex];
// advance to the next position in the array:
xreadIndex = xreadIndex + 1;
yreadIndex = yreadIndex + 1;
zreadIndex = zreadIndex + 1;
// if we're at the end of the array...
if (xreadIndex >= numReadings) {
// ...wrap around to the beginning:
xreadIndex = 0;
}
if (yreadIndex >= numReadings) {
// ...wrap around to the beginning:
yreadIndex = 0;
}
if (zreadIndex >= numReadings) {
// ...wrap around to the beginning:
zreadIndex = 0;
}
//Calc Averages
xaverage = xtotal / numReadings;
yaverage = ytotal / numReadings;
zaverage = ztotal / numReadings;
Serial.print("Acc [mg]: ");
Serial.print(xaverage);
Serial.print(" x, ");
Serial.print(yaverage);
Serial.print(" y, ");
Serial.print(zaverage);
Serial.print(" z, ");
Serial.println();
delay(sampleDelay);
}