Seeed-Studio / Seeed_Arduino_LSM6DS3

Grove sensor 6 Axis Accelerometer&Gyroscope using LSM6DS3
Other
53 stars 23 forks source link

Problem with first start lsm6ds3 #18

Closed brightproject closed 10 months ago

brightproject commented 10 months ago

This issue can be closed, because it says to minor "rework" of the source code. I haven’t learned how to do PR yet, so whoever can, please add it to the release. It is also possible that this addition is only necessary for me, because I am not sure of the authenticity of the lsm6ds3 sensors - which I bought in China. 6_osevoy-datchik-polozheniya-GY_LSM6DS3-_2v1_-akselerometr_-giroskop_

In general, the problem is the following - when the board is first started with the MCU stm32f401, the sensor shows a lack of data and the message Device error appears in the serial port. If you press reset, the data appears. I myself discovered this problem by accident - I usually use about 4-5 sensors connected via the i2c bus. I got out of the situation by performing a simple software reset of the microcontroller and doing this in a cycle of checking data from the device.

     //Call .begin() to configure the IMUs
     if (myIMU.begin() != 0) {
         Serial.println("Device error");
         digitalWrite(STATUS_LED, LOW); // stm32f411 led ON
         delay(500);
         NVIC_SystemReset();
     } else {
         Serial.println("Device OK!");
     }

For my convenience, I added the LED ignition to see how the code is executed. I also output raw data to the serial port in this way.

    //Accelerometer Raw
    Serial.print("\nAccelerometer Raw:\n");
    Serial.print(" X1 = ");
    Serial.println(myIMU.readRawAccelX());
    Serial.print(" Y1 = ");
    Serial.println(myIMU.readRawAccelY());
    Serial.print(" Z1 = ");
    Serial.println(myIMU.readRawAccelZ());

    //Gyroscope Raw
    Serial.print("\nGyroscope Raw:\n");
    Serial.print(" X1 = ");
    Serial.println(myIMU.readRawGyroX());
    Serial.print(" Y1 = ");
    Serial.println(myIMU.readRawGyroY());
    Serial.print(" Z1 = ");
    Serial.println(myIMU.readRawGyroZ());

Before changing the code, the first start of the device was like this:

Monitor port settings:
baudrate=115200
Connected to COM14! Press CTRL-C to exit.

Device error

Accelerometer Raw:
 X1 = -1
 Y1 = -1
 Z1 = -1

Gyroscope Raw:
 X1 = 0
 Y1 = 0
 Z1 = 0

After modification:

Monitor port settings:
baudrate=115200
Connected to COM14! Press CTRL-C to exit.

Device OK!

Accelerometer Raw:
 X1 = -19
 Y1 = 49
 Z1 = 2059

Gyroscope Raw:
 X1 = 3
 Y1 = -45
 Z1 = -34

I hope this helps those who encounter the same problem. P.S. I'm using an Arduino core. Function software reset NVIC_SystemReset(); available for ST microcontrollers only. If you use a different tool for compiling the firmware or a different microcontroller, then you need to look for a different reboot tool.