cippe
August 9, 2023, 7:00pm
1
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.
cippe
August 14, 2023, 3:18pm
3
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:
/******************************************************************************
SparkFunLSM6DS3.cpp
LSM6DS3 Arduino, Teensy Driver, SparkFun ESP32 and ESP8266
Marshall Taylor @ SparkFun Electronics
May 20, 2015
https://github.com/sparkfun/LSM6DS3_Breakout
https://github.com/sparkfun/SparkFun_LSM6DS3_Arduino_Library
Resources:
Uses Wire.h for i2c operation
Uses SPI.h for SPI operation
Either can be omitted if not used
Development environment specifics:
Arduino IDE 1.6.4
Teensy loader 1.23
ESPTool 2.6 for ESP32
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
This file has been truncated. show original
//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
cippe
August 14, 2023, 3:37pm
5
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.
cippe
August 14, 2023, 3:44pm
7
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.
cippe
August 14, 2023, 3:52pm
9
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?
cippe
August 14, 2023, 4:06pm
11
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
cippe
August 14, 2023, 4:08pm
12
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.
cippe
August 14, 2023, 6:24pm
14
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
Koepel
August 14, 2023, 9:48pm
15
Both topics have evolved into the same thing: Frequency rate of serial monitor
cippe
August 14, 2023, 9:53pm
16
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
cippe
August 18, 2023, 1:46pm
17
jremington:
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?
hello!
do you have any idea why it gives me the error I showed you in the previous post?
system
Closed
February 14, 2024, 1:46pm
18
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.