microbotsio / CodeCell

A penny-sized board that can help you miniaturize DIY Robots, Wearables & other IoT projects!! It includes an Arduino friendly ESP32-C3 Wifi & BLE module, USBC LiPo Battery Charger with onboard Battery Connector, Light Sensor, and an optional Motion Sensor
Apache License 2.0
21 stars 4 forks source link

Sensor init issue #1

Open quinm0 opened 1 day ago

quinm0 commented 1 day ago

Hi, I plan on looking into this more myself but I just want to document the first issue I got

I was using the example from the library

#include <CodeCell.h>

CodeCell myCodeCell;

/*
 * Overview:
 * This code shows you how easy it is to set up and run the CodeCell. You just needs to specify which sensors to enable by 
 * passing the appropriate macros to the `Init()` function and use the `Run()` function to handle the power and battery management.
 *
 **** Initialization (`Init` function):
 * 
 * To initialize the CodeCell, use the `myCodeCell.Init()` function with one or more of the predefined macros. Each macro
 * corresponds to a specific sensing function. Here are the available macros:
 * 
 * - `LIGHT`                          // Enables Light Sensing
 * - `MOTION_ACCELEROMETER`           // Enables Accelerometer Sensing
 * - `MOTION_GYRO`                    // Enables Gyroscope Sensing
 * - `MOTION_MAGNETOMETER`            // Enables Magnetometer Sensing
 * - `MOTION_LINEAR_ACC`              // Enables Linear Acceleration Sensing
 * - `MOTION_GRAVITY`                 // Enables Gravity Sensing
 * - `MOTION_ROTATION`                // Enables Rotation Sensing
 * - `MOTION_ROTATION_NO_MAG`         // Enables Rotation Sensing without Magnetometer
 * - `MOTION_STEP_COUNTER`            // Enables Walking Step Counter
 * - `MOTION_STATE`                   // Enables Motion State Detection
 * - `MOTION_TAP_DETECTOR`            // Enables Tap Detector
 * - `MOTION_ACTIVITY`                // Enables Motion Activity Recognition
 * 
 * Example Usage:
 * - `myCodeCell.Init(LIGHT);`                                      // Initializes Light Sensing
 * - `myCodeCell.Init(LIGHT + MOTION_ROTATION);`                    // Initializes Light Sensing and Angular Rotation Sensing
 * - `myCodeCell.Init(LIGHT + MOTION_ROTATION + MOTION_STATE);`     // Initializes Light Sensing, Angular Rotation Sensing, and State Detection
 * 
 * Note: You can combine multiple macros using the `+` operator to initialize multiple sensors.
 * 
 **** Running the Code (`Run` function):
 * 
 * Call the `myCodeCell.Run()` function in the `loop()` to manage battery and power. This function returns true every 100ms and
 * also handles the onboard LED to indicate power status. When the battery voltage falls below 3.3V, the LED will blink red 10 times 
 * and then go into Sleep Mode until the USB cable is connected for charging. While charging, the CodeCell will shut down the application, 
 * light the LED blue, and wait until the battery is fully charged. Once fully charged, it will start a breathing-light animation with a speed
 * corresponding to the proximity distance. The LED will shine green when powered by the battery and blue when powered via USB.
 * 
 **** Reading Sensor Data:
 * 
 * After initializing the sensors, you can use the following functions to read data from them:
 * 
 * Sensor Read Functions:
 * 
 * - `Light_ProximityRead()`                                            // Reads the proximity value from the light sensor
 * - `Light_WhiteRead()`                                                // Reads the white light intensity from the light sensor
 * - `Light_AmbientRead()`                                              // Reads the ambient light intensity from the light sensor
 * - `Motion_TapRead()`                                                  // Reads the number of taps detected (tap = 1, no tap = 0)
 * - `Motion_StateRead()`                                               // Reads the current state (On Table = 1, Stationary = 2, Stable = 3, Motion = 4)
 * - `Motion_ActivityRead()`                                            // Reads the current activity (Driving = 1, Cycling = 2, Walking = 3/6, Still = 4, Tilting = 5, Running = 7, Climbing Stairs = 8)
 * - `Motion_AccelerometerRead(float &x, float &y, float &z)`           // Reads acceleration data along the x, y, and z axes
 * - `Motion_GyroRead(float &x, float &y, float &z)`                    // Reads rotational velocity data along the x, y, and z axes
 * - `Motion_MagnetometerRead(float &x, float &y, float &z)`            // Reads magnetic field strength data along the x, y, and z axes
 * - `Motion_GravityRead(float &x, float &y, float &z)`                 // Reads gravity vector data along the x, y, and z axes
 * - `Motion_LinearAccRead(float &x, float &y, float &z)`               // Reads linear acceleration data along the x, y, and z axes
 * - `Motion_StepCounterRead(uint16_t &x)`                              // Reads the number of steps counted
 * - `Motion_RotationRead(float &roll, float &pitch, float &yaw)`       // Reads angular rotational data (roll, pitch, yaw)
 * - `Motion_RotationNoMagRead(float &roll, float &pitch, float &yaw)`  // Reads angular rotational data without magnetometer
 *
 * Example Usage:
 * - `uint16_t proximity = myCodeCell.Light_ProximityRead();`
 * - `myCodeCell.Motion_AccelerometerRead(myX, myY, myZ);`
 * - `myCodeCell.Motion_RotationRead(myRoll, myPitch, myYaw);`
 * 
 * Note: You can use `myCodeCell.PrintSensors()`to prints the values of all enabled sensors on the Serial Monitor.
 * 
 */

void setup() {
  Serial.begin(115200); /* Set Serial baud rate to 115200. Ensure Tools/USB_CDC_On_Boot is enabled if using Serial. */

  myCodeCell.Init(LIGHT); /*Initializes Light Sensing*/
}

void loop() {
  if (myCodeCell.Run()) {
    /*Runs  every 100ms - Put your code here*/
    myCodeCell.PrintSensors(); /*Print Sensors data every 100ms*/
  }
}

And following

 * Example Usage:
 * - `myCodeCell.Init(LIGHT);`                                      // Initializes Light Sensing
 * - `myCodeCell.Init(LIGHT + MOTION_ROTATION);`                    // Initializes Light Sensing and Angular Rotation Sensing
 * - `myCodeCell.Init(LIGHT + MOTION_ROTATION + MOTION_STATE);`     // Initializes Light Sensing, Angular Rotation Sensing, and State Detection

I added + MOTION_ACCELEROMETER to the example init call.

And I get the following. Note, the default example works just fine, just adding the + MOTION_ACCELEROMETER causes the issue

ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x3 (RTC_SW_SYS_RST),boot:0xe (SPI_FAST_FLASH_BOOT)
Saved PC:0x40048b82
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5820,len:0x1058
load:0x403cc710,len:0x8a8
load:0x403ce710,len:0x2fac
entry 0x403cc710

Hello World! I am your CodeCell
Please wait while I setup my sensors.. Light Sensing Enabled + Guru Meditation Error: Core  0 panic'ed (Load access fault). Exception was unhandled.

Core  0 register dump:
MEPC    : 0x4200199c  RA      : 0x4200093c  SP      : 0x3fc990d0  GP      : 0x3fc8ea00  
TP      : 0x3fc89bf4  T0      : 0x00000000  T1      : 0x403887e8  T2      : 0x61656c50  
S0/FP   : 0x3fc8f720  S1      : 0x3fc90000  A0      : 0x00000000  A1      : 0x00000000  
A2      : 0x3fc990df  A3      : 0x00000001  A4      : 0x600c0000  A5      : 0x3fc8f768  
A6      : 0x3fc9901c  A7      : 0x3fc99020  S2      : 0x00000065  S3      : 0x3fc90000  
S4      : 0x00000000  S5      : 0x00000000  S6      : 0x00000000  S7      : 0x00000000  
S8      : 0x00000000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000  
T3      : 0x00000094  T4      : 0x00000800  T5      : 0x00000006  T6      : 0x00000000  
MSTATUS : 0x00001881  MTVEC   : 0x40380001  MCAUSE  : 0x00000005  MTVAL   : 0x00000014  
MHARTID : 0x00000000  

Stack memory:
3fc990d0: 0x00000000 0x00000000 0x00000000 0x01000000 0x00000094 0x00000800 0x00000006 0x42001d9c
3fc990f0: 0x00000033 0x3fc90000 0x3fc8f720 0x420036c8 0x00000000 0x00000000 0x00000000 0x00000000
3fc99110: 0x00000033 0x3fc90000 0x3fc8f720 0x420037ca 0x00000000 0x00000000 0x00000000 0x420074de
3fc99130: 0x00000000 0x00000000 0x00000000 0x40389ac8 0x00000000 0x00000000 0x00000000 0x00000000
3fc99150: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
3fc99170: 0xa5a5a5a5 0xa5a5a5a5 0xbaad5678 0x00000160 0xabba1234 0x00000154 0x3fc99070 0x00000523
3fc99190: 0x3fc90970 0x3fc90970 0x3fc99188 0x3fc90968 0x00000018 0x3fc94908 0x3fc94908 0x3fc99188
3fc991b0: 0x00000000 0x00000001 0x3fc97178 0x706f6f6c 0x6b736154 0x3fc99400 0x00c99658 0x00000000
3fc991d0: 0x3fc99170 0x00000001 0x00000000 0x00000000 0x00000000 0x00000000 0x3fc92780 0x3fc927e8
3fc991f0: 0x3fc92850 0x00000000 0x00000000 0x00000001 0x00000000 0x00000000 0x00000000 0x42024f16
3fc99210: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc99230: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc99250: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc99270: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc99290: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc992b0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fc992d0: 0x00000000 0x00000000 0xb2000000 0xbaad5678 0x00000060 0xabba1234 0x00000054 0x00000000
3fc992f0: 0x3fc992ec 0x00000000 0x00000000 0x00000000 0x3fc99304 0xffffffff 0x3fc99304 0x3fc99304
3fc99310: 0x00000000 0x3fc99318 0xffffffff 0x3fc99318 0x3fc99318 0x00000001 0x00000001 0x00000000
3fc99330: 0xab00ffff 0x00000000 0xb33fffff 0x00000000 0xbaad5678 0x00000160 0xabba1234 0x00000154
3fc99350: 0x3fc993a4 0x3fc993a4 0x3fc994a4 0x3fc994a3 0x00000000 0x3fc99368 0xffffffff 0x3fc99368
3fc99370: 0x3fc99368 0x00000000 0x3fc9937c 0xffffffff 0x3fc9937c 0x3fc9937c 0x00000000 0x00000100
3fc99390: 0x00000001 0x3f00ffff 0x00000000 0xb33fffff 0x00000000 0x6d207075 0x65732079 0x726f736e
3fc993b0: 0x202e2e73 0x776f6e69 0x2e2e7265 0x72500a0a 0x6d69786f 0xad427469 0x20c93ae3 0x35e6014e
3fc993d0: 0xfde87a79 0x768916f2 0x7ded35f9 0x6364ab25 0x0188fd72 0x1c710fc8 0xc320b46d 0x1b200100
3fc993f0: 0xf0eafe6b 0xefafb3b7 0xbf2bbeff 0xd3fd75f9 0x687c063f 0x74fc789e 0xc4084012 0xed19a836
3fc99410: 0x6d33cb13 0x5abbf116 0xdfca3dfe 0x81094d4e 0x3fcb1b03 0x965e8a10 0xd59d8973 0x822f7e6d
3fc99430: 0xbdffa339 0x6fdff7f1 0x7bf7f32f 0x667fafad 0x24330707 0x48470868 0xa2b53d35 0x44a9c44c
3fc99450: 0x9f7ffff5 0xf9dbaf16 0x37d7d311 0xff4ff312 0x2d2e7563 0x750209c5 0x31803043 0x5a433f00
3fc99470: 0xf71d97b0 0xfc3a6e2e 0xbffde733 0xa3b10b7e 0x25a08220 0x2bc80a72 0x4b08094c 0xa24010ba
3fc99490: 0xf6b7ec90 0x9f71bfc0 0x512e72fe 0xd1771fa7 0x832628d0 0xbaad5678 0x0000007c 0xabba1234
3fc994b0: 0x00000070 0x00000100 0x00000100 0x00000002 0x40385b0c 0x4038618c 0x40385a42 0x403866d4

ELF file SHA256: 1135b25dfb9d017e

Rebooting...
ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x3 (RTC_SW_SYS_RST),boot:0xe (SPI_FAST_FLASH_BOOT)
Saved PC:0x40048b82
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5820,len:0x1058
load:0x403cc710,len:0x8a8
load:0x403ce710,len:0x2fac
entry 0x403cc710
microbotsio commented 1 day ago

Hi Quin

Are you using the CodeCell Light or CodeCell light+motion?

This means that the CodeCell is not finding the motion sensor when you added "+ MOTION_ACCELEROMETER", as it is not present on the board -so it keeps resetting indicating the error

Let me know if you have further questions.