LSM6DS3 sample rate

hello everyone!

i am working with an arduino uno wifi r2 board, which has an integrated imu of the type LSM6DS3.
i'm using the library 'Arduino_LSM6DS3.h' and i wanted to know how is it possible to change the sample rate of the accelerometer and gyroscope from 104Hz to 1666Hz...
i was thinking of modifying the .cpp file of the library, is this idea correct?

thanks a lot everyone!

Please post a link to the library file. If the one you have does not have a function to set the data rate, perhaps there is another library for that sensor that does.

here is the link to the library. in the .cpp file there are the two functions for the sample rate of the accelerometer and the gyroscope

The Sparkfun library would be a better choice. The initialization can easily be changed to set any data rate allowed:

	//Construct with these default settings

	settings.gyroEnabled = 1;  //Can be 0 or 1
	settings.gyroRange = 2000;   //Max deg/s.  Can be: 125, 245, 500, 1000, 2000
	settings.gyroSampleRate = 416;   //Hz.  Can be: 13, 26, 52, 104, 208, 416, 833, 1666
	settings.gyroBandWidth = 400;  //Hz.  Can be: 50, 100, 200, 400;
	settings.gyroFifoEnabled = 1;  //Set to include gyro in FIFO
	settings.gyroFifoDecimation = 1;  //set 1 for on /1

	settings.accelEnabled = 1;
	settings.accelODROff = 1;
	settings.accelRange = 16;      //Max G force readable.  Can be: 2, 4, 8, 16
	settings.accelSampleRate = 416;  //Hz.  Can be: 13, 26, 52, 104, 208, 416, 833, 1666, 3332, 6664, 13330
	settings.accelBandWidth = 100;  //Hz.  Can be: 50, 100, 200, 400;
	settings.accelFifoEnabled = 1;  //Set to include accelerometer in the FIFO
	settings.accelFifoDecimation = 1;  //set 1 for on /1

ok thanks... so all I have to do is import this library and in the setup part put the commands 'settings.gyroSampleRate = 1666;' and 'settings.accelerSampleRate = 1666;' to change the sample rate
is this correct?

The beauty of Arduino is that you can try something and very quickly see if and how it works.

I tried to download the library and run examples, but I get the error 'compilation error: exit status 1'.

Post the complete error message, using code tags.

C:\Users\alber\OneDrive\Documenti\Arduino\libraries\SparkFun_LSM6DS3_Breakout\src\SparkFunLSM6DS3.cpp: In member function 'status_t LSM6DS3Core::beginCore()':
C:\Users\alber\OneDrive\Documenti\Arduino\libraries\SparkFun_LSM6DS3_Breakout\src\SparkFunLSM6DS3.cpp:78:47: error: 'MSB_FIRST' was not declared in this scope
     mySpiSettings = SPISettings(spiPortSpeed, MSB_FIRST, SPI_MODE1);
                                               ^~~~~~~~~
C:\Users\alber\OneDrive\Documenti\Arduino\libraries\SparkFun_LSM6DS3_Breakout\src\SparkFunLSM6DS3.cpp:78:47: note: suggested alternative: 'MSBFIRST'
     mySpiSettings = SPISettings(spiPortSpeed, MSB_FIRST, SPI_MODE1);
                                               ^~~~~~~~~
                                               MSBFIRST
In file included from C:\Users\alber\OneDrive\Documenti\Arduino\libraries\SparkFun_LSM6DS3_Breakout\src\SparkFunLSM6DS3.h:31:0,
                 from C:\Users\alber\OneDrive\Documenti\Arduino\libraries\SparkFun_LSM6DS3_Breakout\src\SparkFunLSM6DS3.cpp:30:
C:\Users\alber\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\libraries\Wire\src/Wire.h: In member function 'status_t LSM6DS3Core::readRegisterRegion(uint8_t*, uint8_t, uint8_t)':
C:\Users\alber\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\libraries\Wire\src/Wire.h:63:12: note: candidate 1: size_t TwoWire::requestFrom(int, int)
     size_t requestFrom(int, int);
            ^~~~~~~~~~~
C:\Users\alber\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\libraries\Wire\src/Wire.h:61:12: note: candidate 2: virtual size_t TwoWire::requestFrom(uint8_t, size_t)
     size_t requestFrom(uint8_t, size_t);
            ^~~~~~~~~~~
C:\Users\alber\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\libraries\Wire\src/Wire.h: In member function 'status_t LSM6DS3Core::readRegister(uint8_t*, uint8_t)':
C:\Users\alber\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\libraries\Wire\src/Wire.h:63:12: note: candidate 1: size_t TwoWire::requestFrom(int, int)
     size_t requestFrom(int, int);
            ^~~~~~~~~~~
C:\Users\alber\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8\libraries\Wire\src/Wire.h:61:12: note: candidate 2: virtual size_t TwoWire::requestFrom(uint8_t, size_t)
     size_t requestFrom(uint8_t, size_t);
            ^~~~~~~~~~~

exit status 1

Compilation error: exit status 1

It looks like you have conflicting libraries for Wire.

Which example are you trying to run, and how did you wire the sensor? Why is the SPI library involved?

the sensor is built into the arduino uno wifi r2 board, i did nothing on the sensor..
i tried running several 'MultiSPI.ino' 'MinimalistExample.ino' example files

However, if I wanted to use my library that I told you about at the beginning ('Arduino_LSM6DS3.h'), in your opinion, is my idea correct?

To change the data rate, you need to set certain registers to specific values, as described in the sensor data sheet.

You can do that either with a library that has a specific function to perform the setting, or by using the Wire or SPI libraries, depending on how you wired the sensor.

OK, I get it...
but I can add the library you mentioned to my code and then in the setup part I do the two sample rate commands for accelerometer and gyroscope

Both topics have evolved into the same thing: Frequency rate of serial monitor

in this topic I was asking if there was a way to set the IMU sample rate, in the other we went on to talk about the same thing following an exchange of ideas

hello!

do you have any idea why it gives me the error I showed you in the previous post?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.