From dbe5bac427642b3cd3cec031e2c52d9b975f216f Mon Sep 17 00:00:00 2001 From: Porter Fencl Date: Mon, 20 Oct 2025 19:28:52 -0500 Subject: [PATCH 1/6] initial design --- include/gyro.h | 22 ++++++++++++++++++++++ src/gyro.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 22 ++++++++++++---------- 3 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 include/gyro.h create mode 100644 src/gyro.cpp diff --git a/include/gyro.h b/include/gyro.h new file mode 100644 index 0000000..9c34626 --- /dev/null +++ b/include/gyro.h @@ -0,0 +1,22 @@ +#ifndef __gyro__h__ +#define __gyro__h__ +#include +#include +#include + +#define LSM6DS3_OUTX_L_G 0X22 //gyroscope +#define LSM6DS3_OUTX_L_XL 0x28 //accelerometer +#define LSM6DS3_OUT_TEMP_L 0x20 //temperature + +class LSM6DS3 { + public: + void readRegisters(uint8_t address, uint8_t* data, size_t length); + + void readGyroData(float* x, float* y, float* z); + void readAccelData(float* x, float* y, float* z); + void readTempData(float* t); +}; + + + +#endif \ No newline at end of file diff --git a/src/gyro.cpp b/src/gyro.cpp new file mode 100644 index 0000000..642b3b0 --- /dev/null +++ b/src/gyro.cpp @@ -0,0 +1,41 @@ +#include "gyro.h" + +void LSM6DS3::readRegisters(uint8_t address, uint8_t * data, size_t length){ + + SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0)); + SPI.transfer(address | 0x80); + SPI.transfer(data,length); + SPI.endTransaction(); + +} + +void LSM6DS3::readGyroData(float* x, float* y, float* z){ + + int16_t data[3]; + readRegisters(LSM6DS3_OUTX_L_G, (uint8_t*)data, sizeof(data)); + + *x = data[0] * 2000.0 / 32768.0; + *y = data[1] * 2000.0 / 32768.0; + *z = data[2] * 2000.0 / 32768.0; + +} + +void LSM6DS3::readAccelData(float* x, float* y, float* z){ + + int16_t data[3]; + readRegisters(LSM6DS3_OUTX_L_XL, (uint8_t*)data, sizeof(data)); + + *x = data[0] * 4.0 / 32768.0; + *y = data[1] * 4.0 / 32768.0; + *z = data[2] * 4.0 / 32768.0; + +} + +void LSM6DS3::readTempData(float* t){ + + int16_t data[1]; + + readRegisters(LSM6DS3_OUT_TEMP_L, (uint8_t*)data, sizeof(data)); + *t = data[0] / 16.0 + 2; + +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index cb9fbba..547f7ec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,18 +1,20 @@ -#include +#include "gyro.h" + -// put function declarations here: -int myFunction(int, int); void setup() { - // put your setup code here, to run once: - int result = myFunction(2, 3); + SPI.begin(); + Serial.begin(115200); + Wire.begin(); + + float x; + float y; + float z; } void loop() { - // put your main code here, to run repeatedly: + LSM6DS3.readGyroData(x, y, z); + Serial.println(); + } -// put function definitions here: -int myFunction(int x, int y) { - return x + y; -} \ No newline at end of file From 120b71c0f803f6436e2d5ea1b56d2997e75fa0f7 Mon Sep 17 00:00:00 2001 From: Porter Fencl Date: Mon, 20 Oct 2025 19:29:06 -0500 Subject: [PATCH 2/6] fixed errors --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 547f7ec..3994cf1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,8 +13,8 @@ void setup() { } void loop() { - LSM6DS3.readGyroData(x, y, z); - Serial.println(); + // LSM6DS3.readGyroData(x, y, z); + // Serial.println(); } From 6b011db0bf8c0b8ac2184a0031e4613b32c5a82e Mon Sep 17 00:00:00 2001 From: Porter Fencl Date: Thu, 23 Oct 2025 19:43:22 -0500 Subject: [PATCH 3/6] pushh --- .vscode/settings.json | 7 +++++ include/gyro.h | 18 ++++++++---- platformio.ini | 1 + src/gyro.cpp | 32 ++++++++++++++++++++- src/main.cpp | 65 +++++++++++++++++++++++++++++++++++++++---- 5 files changed, 111 insertions(+), 12 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..45203bc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "array": "cpp", + "string": "cpp", + "string_view": "cpp" + } +} \ No newline at end of file diff --git a/include/gyro.h b/include/gyro.h index 9c34626..b5cb7e3 100644 --- a/include/gyro.h +++ b/include/gyro.h @@ -2,17 +2,25 @@ #define __gyro__h__ #include #include -#include -#define LSM6DS3_OUTX_L_G 0X22 //gyroscope -#define LSM6DS3_OUTX_L_XL 0x28 //accelerometer -#define LSM6DS3_OUT_TEMP_L 0x20 //temperature +#define LSM6S3_WHO_AM_I 0x0F + +#define LSM6DS3_OUTX_L_G 0X22 //Angular rate sensor pitch axis (X) angular rate output register (r). The value is expressed as a 16-bit word in two’s complement +//#define LSM6DS3_OUTY_L_G 0x24 //Angular rate sensor roll axis (Y) angular rate output register (r). The value is expressed as a 16-bit word in two’s complement + +#define LSM6DS3_OUTX_L_XL 0x28 //Linear acceleration sensor X-axis output register (r). The value is expressed as a 16-bit word in two’s complement +#define LSM6DS3_OUT_TEMP_L 0x20 //Temperature data output register (r). L and H registers together express a 16-bit word in two’s complement. + class LSM6DS3 { public: void readRegisters(uint8_t address, uint8_t* data, size_t length); + + boolean whoAmICheck(); - void readGyroData(float* x, float* y, float* z); + void readGyroData(float* x, float* y, float* z); + //void readRollData(float* x, float* y, float* z); + void readAccelData(float* x, float* y, float* z); void readTempData(float* t); }; diff --git a/platformio.ini b/platformio.ini index 345e039..3d967ee 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,3 +13,4 @@ platform = ststm32 board = nucleo_l432kc framework = arduino lib_extra_dirs = ./embedded-pio +lib_deps = arduino-libraries/Arduino_LSM6DS3@^1.0.3 diff --git a/src/gyro.cpp b/src/gyro.cpp index 642b3b0..23f960f 100644 --- a/src/gyro.cpp +++ b/src/gyro.cpp @@ -2,13 +2,30 @@ void LSM6DS3::readRegisters(uint8_t address, uint8_t * data, size_t length){ - SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0)); + SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE3)); + digitalWrite(D3, LOW); SPI.transfer(address | 0x80); SPI.transfer(data,length); + digitalWrite(D3, HIGH); SPI.endTransaction(); } +boolean LSM6DS3::whoAmICheck(){ + int16_t data[1] = {0}; + Serial.printf("verified: %x \n", data[0]); + readRegisters(LSM6S3_WHO_AM_I, (uint8_t*)data, sizeof(data)); + + int verified = data[0]; + Serial.printf("verified: %x \n", verified); + + if (verified == 0b01101010) { + return true; + } else { + return false; + } +} + void LSM6DS3::readGyroData(float* x, float* y, float* z){ int16_t data[3]; @@ -20,6 +37,19 @@ void LSM6DS3::readGyroData(float* x, float* y, float* z){ } +/* +void LSM6DS3::readRollData(float* x, float* y, float* z){ + + int16_t data[3]; + readRegisters(LSM6DS3_OUTY_L_G, (uint8_t*)data, sizeof(data)); + + *x = data[0] * 2000.0 / 32768.0; + *y = data[1] * 2000.0 / 32768.0; + *z = data[2] * 2000.0 / 32768.0; + +} +*/ + void LSM6DS3::readAccelData(float* x, float* y, float* z){ int16_t data[3]; diff --git a/src/main.cpp b/src/main.cpp index 3994cf1..603d1cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,20 +1,73 @@ #include "gyro.h" +#include + float* x; + float* y; + float* z; + + float* f; + float* g; + float* h; + + float* t; + + #define SPI_CS D3 + #define SPI_SCLK A4 + #define SPI_MOSI D2 + #define SPI_MISO A5 + +SPIClass spi1(SPI_CS,SPI_SCLK,SPI_MOSI,SPI_MISO); + +LSM6DS3Class board(spi1, SPI_CS, D6 ); + +LSM6DS3 board2; void setup() { SPI.begin(); Serial.begin(115200); - Wire.begin(); + pinMode(D3, OUTPUT); + digitalWrite(D3, HIGH); + + // if (IMU.begin() == 0) { + // Serial.printf("Failed\n"); + // while(true); + // } + + if (board2.whoAmICheck() != true) { + Serial.printf("Failed\n"); + while(true); + } + Serial.printf("Not Failed\n"); - float x; - float y; - float z; } void loop() { - // LSM6DS3.readGyroData(x, y, z); - // Serial.println(); + // //board.readGyroData(x, y, z); + // IMU.readGyroscope(*x, *y, *z); + // Serial.print("Gyro X,Y,Z: "); + // Serial.print(*x, 2); + // Serial.print(" "); + // Serial.print(*y, 2); + // Serial.print(" "); + // Serial.print(*z, 2); + // Serial.print(" || "); + + // //board.readAccelData(f, g, h); + // IMU.readAcceleration(*f, *g, *h); + // Serial.print("Accel X,Y,Z: "); + // Serial.print(*f, 2); + // Serial.print(" "); + // Serial.print(*g, 2); + // Serial.print(" "); + // Serial.print(*h, 2); + // Serial.print(" || "); + + // //board.readTempData(t); + // IMU.readTemperature(*t); + // Serial.print("Temp: "); + // Serial.println(*t, 2); + // delay(100); } From 367fe18ae575fcf961d5dd1d068fe2ee46eac63f Mon Sep 17 00:00:00 2001 From: Aditya YV Date: Thu, 23 Oct 2025 23:26:32 -0500 Subject: [PATCH 4/6] code clean up --- include/gyro.h | 5 +++++ platformio.ini | 1 - src/gyro.cpp | 17 ++++++++++------- src/main.cpp | 37 +++++++++++++++++++------------------ 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/include/gyro.h b/include/gyro.h index b5cb7e3..2690ea8 100644 --- a/include/gyro.h +++ b/include/gyro.h @@ -11,6 +11,11 @@ #define LSM6DS3_OUTX_L_XL 0x28 //Linear acceleration sensor X-axis output register (r). The value is expressed as a 16-bit word in two’s complement #define LSM6DS3_OUT_TEMP_L 0x20 //Temperature data output register (r). L and H registers together express a 16-bit word in two’s complement. +#define SPI_CS PB_0 //Need to use this instead of A3 because A3 is mapped to something else +#define SPI_SCLK PA_5 // OR D13 +#define SPI_MOSI PA_7 //OR D11 +#define SPI_MISO PA_6 //OR D12 + class LSM6DS3 { public: diff --git a/platformio.ini b/platformio.ini index 3d967ee..345e039 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,4 +13,3 @@ platform = ststm32 board = nucleo_l432kc framework = arduino lib_extra_dirs = ./embedded-pio -lib_deps = arduino-libraries/Arduino_LSM6DS3@^1.0.3 diff --git a/src/gyro.cpp b/src/gyro.cpp index 23f960f..783273b 100644 --- a/src/gyro.cpp +++ b/src/gyro.cpp @@ -2,19 +2,22 @@ void LSM6DS3::readRegisters(uint8_t address, uint8_t * data, size_t length){ - SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE3)); - digitalWrite(D3, LOW); + SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE3)); + digitalWrite(SPI_CS, LOW); SPI.transfer(address | 0x80); - SPI.transfer(data,length); - digitalWrite(D3, HIGH); - SPI.endTransaction(); + for (size_t i = 0; i < length; i++){ + data[i] = SPI.transfer(0x00); // Send dummy bytes to keep SPI happy + } + + digitalWrite(SPI_CS, HIGH); + SPI.endTransaction(); } boolean LSM6DS3::whoAmICheck(){ - int16_t data[1] = {0}; + uint8_t data[1] = {0}; Serial.printf("verified: %x \n", data[0]); - readRegisters(LSM6S3_WHO_AM_I, (uint8_t*)data, sizeof(data)); + readRegisters(LSM6S3_WHO_AM_I, data, sizeof(data)); int verified = data[0]; Serial.printf("verified: %x \n", verified); diff --git a/src/main.cpp b/src/main.cpp index 603d1cc..17831b7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,26 +1,15 @@ #include "gyro.h" -#include - float* x; - float* y; - float* z; +float* x; +float* y; +float* z; - float* f; - float* g; - float* h; - - float* t; - - #define SPI_CS D3 - #define SPI_SCLK A4 - #define SPI_MOSI D2 - #define SPI_MISO A5 - -SPIClass spi1(SPI_CS,SPI_SCLK,SPI_MOSI,SPI_MISO); - -LSM6DS3Class board(spi1, SPI_CS, D6 ); +float* f; +float* g; +float* h; +float* t; LSM6DS3 board2; void setup() { @@ -40,6 +29,18 @@ void setup() { } Serial.printf("Not Failed\n"); + + //pointers need memory allocation + x = (float*)malloc(sizeof(float)); + y = (float*)malloc(sizeof(float)); + z = (float*)malloc(sizeof(float)); + + f = (float*)malloc(sizeof(float)); + g = (float*)malloc(sizeof(float)); + h = (float*)malloc(sizeof(float)); + + t = (float*)malloc(sizeof(float)); + } void loop() { From c64c4774ad34cc64fa76b55df29bfb98ea2a157a Mon Sep 17 00:00:00 2001 From: Porter Fencl Date: Sun, 9 Nov 2025 14:10:03 -0600 Subject: [PATCH 5/6] version1 --- include/gyro.h | 11 ++++++----- platformio.ini | 1 + src/gyro.cpp | 13 ++++++++----- src/main.cpp | 15 ++++++++------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/include/gyro.h b/include/gyro.h index 2690ea8..037fd86 100644 --- a/include/gyro.h +++ b/include/gyro.h @@ -11,17 +11,18 @@ #define LSM6DS3_OUTX_L_XL 0x28 //Linear acceleration sensor X-axis output register (r). The value is expressed as a 16-bit word in two’s complement #define LSM6DS3_OUT_TEMP_L 0x20 //Temperature data output register (r). L and H registers together express a 16-bit word in two’s complement. -#define SPI_CS PB_0 //Need to use this instead of A3 because A3 is mapped to something else -#define SPI_SCLK PA_5 // OR D13 -#define SPI_MOSI PA_7 //OR D11 -#define SPI_MISO PA_6 //OR D12 +#define SPI_CS PA4 //Need to use this instead of A3 because A3 is mapped to something else +#define SPI_SCLK D13 // OR D13 +#define SPI_MOSI D11 //OR D11 +#define SPI_MISO D12 //OR D12 +extern SPIClass SPI_gyro; class LSM6DS3 { public: void readRegisters(uint8_t address, uint8_t* data, size_t length); - boolean whoAmICheck(); + bool whoAmICheck(); void readGyroData(float* x, float* y, float* z); //void readRollData(float* x, float* y, float* z); diff --git a/platformio.ini b/platformio.ini index 345e039..b60e17d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,3 +13,4 @@ platform = ststm32 board = nucleo_l432kc framework = arduino lib_extra_dirs = ./embedded-pio +lib_deps = adafruit/Adafruit LSM6DS@^4.7.4 diff --git a/src/gyro.cpp b/src/gyro.cpp index 783273b..4f7700a 100644 --- a/src/gyro.cpp +++ b/src/gyro.cpp @@ -1,20 +1,23 @@ #include "gyro.h" +SPIClass SPI_gyro(SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS); + + void LSM6DS3::readRegisters(uint8_t address, uint8_t * data, size_t length){ - SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE3)); + SPI_gyro.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3)); digitalWrite(SPI_CS, LOW); - SPI.transfer(address | 0x80); + SPI_gyro.transfer(address | 0x80); for (size_t i = 0; i < length; i++){ - data[i] = SPI.transfer(0x00); // Send dummy bytes to keep SPI happy + data[i] = SPI_gyro.transfer(0x00); // Send dummy bytes to keep SPI happy } digitalWrite(SPI_CS, HIGH); - SPI.endTransaction(); + SPI_gyro.endTransaction(); } -boolean LSM6DS3::whoAmICheck(){ +bool LSM6DS3::whoAmICheck(){ uint8_t data[1] = {0}; Serial.printf("verified: %x \n", data[0]); readRegisters(LSM6S3_WHO_AM_I, data, sizeof(data)); diff --git a/src/main.cpp b/src/main.cpp index 17831b7..8e181fb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,8 +12,9 @@ float* h; float* t; LSM6DS3 board2; + void setup() { - SPI.begin(); + SPI_gyro.begin(); Serial.begin(115200); pinMode(D3, OUTPUT); digitalWrite(D3, HIGH); @@ -22,13 +23,13 @@ void setup() { // Serial.printf("Failed\n"); // while(true); // } - - if (board2.whoAmICheck() != true) { - Serial.printf("Failed\n"); - while(true); + while(1==1){ + board2.whoAmICheck(); + delay(1000); + + + } - Serial.printf("Not Failed\n"); - //pointers need memory allocation x = (float*)malloc(sizeof(float)); From c121138b8e146ee3aeea0a8c4a0e035bf66c960e Mon Sep 17 00:00:00 2001 From: Porter Fencl Date: Sun, 9 Nov 2025 14:47:38 -0600 Subject: [PATCH 6/6] working with adafruit example --- src/main.cpp | 249 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 186 insertions(+), 63 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8e181fb..d31eca7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,75 +1,198 @@ -#include "gyro.h" +// Basic demo for accelerometer/gyro readings from Adafruit ISM330DHCX +#include -float* x; -float* y; -float* z; +// For SPI mode, we need a CS pin +#define LSM_CS PA4 +// For software-SPI mode we need SCK/MOSI/MISO pins +#define LSM_SCK D13 +#define LSM_MISO D12 +#define LSM_MOSI D11 -float* f; -float* g; -float* h; - -float* t; -LSM6DS3 board2; - - -void setup() { - SPI_gyro.begin(); +Adafruit_ISM330DHCX ism330dhcx; +void setup(void) { Serial.begin(115200); - pinMode(D3, OUTPUT); - digitalWrite(D3, HIGH); - - // if (IMU.begin() == 0) { - // Serial.printf("Failed\n"); - // while(true); - // } - while(1==1){ - board2.whoAmICheck(); - delay(1000); - - - + while (!Serial) + delay(10); // will pause Zero, Leonardo, etc until serial console opens + + Serial.println("Adafruit ISM330DHCX test!"); + + // if (!ism330dhcx.begin_I2C()) { + // if (!ism330dhcx.begin_SPI(LSM_CS)) { + if (!ism330dhcx.begin_SPI(LSM_CS, LSM_SCK, LSM_MISO, LSM_MOSI)) { + Serial.println("Failed to find ISM330DHCX chip1"); + while (1) { + delay(10); + } + } + + Serial.println("ISM330DHCX Found!"); + + // ism330dhcx.setAccelRange(LSM6DS_ACCEL_RANGE_2_G); + Serial.print("Accelerometer range set to: "); + switch (ism330dhcx.getAccelRange()) { + case LSM6DS_ACCEL_RANGE_2_G: + Serial.println("+-2G"); + break; + case LSM6DS_ACCEL_RANGE_4_G: + Serial.println("+-4G"); + break; + case LSM6DS_ACCEL_RANGE_8_G: + Serial.println("+-8G"); + break; + case LSM6DS_ACCEL_RANGE_16_G: + Serial.println("+-16G"); + break; } - //pointers need memory allocation - x = (float*)malloc(sizeof(float)); - y = (float*)malloc(sizeof(float)); - z = (float*)malloc(sizeof(float)); + // ism330dhcx.setGyroRange(LSM6DS_GYRO_RANGE_250_DPS); + Serial.print("Gyro range set to: "); + switch (ism330dhcx.getGyroRange()) { + case LSM6DS_GYRO_RANGE_125_DPS: + Serial.println("125 degrees/s"); + break; + case LSM6DS_GYRO_RANGE_250_DPS: + Serial.println("250 degrees/s"); + break; + case LSM6DS_GYRO_RANGE_500_DPS: + Serial.println("500 degrees/s"); + break; + case LSM6DS_GYRO_RANGE_1000_DPS: + Serial.println("1000 degrees/s"); + break; + case LSM6DS_GYRO_RANGE_2000_DPS: + Serial.println("2000 degrees/s"); + break; + case ISM330DHCX_GYRO_RANGE_4000_DPS: + Serial.println("4000 degrees/s"); + break; + } - f = (float*)malloc(sizeof(float)); - g = (float*)malloc(sizeof(float)); - h = (float*)malloc(sizeof(float)); + // ism330dhcx.setAccelDataRate(LSM6DS_RATE_12_5_HZ); + Serial.print("Accelerometer data rate set to: "); + switch (ism330dhcx.getAccelDataRate()) { + case LSM6DS_RATE_SHUTDOWN: + Serial.println("0 Hz"); + break; + case LSM6DS_RATE_12_5_HZ: + Serial.println("12.5 Hz"); + break; + case LSM6DS_RATE_26_HZ: + Serial.println("26 Hz"); + break; + case LSM6DS_RATE_52_HZ: + Serial.println("52 Hz"); + break; + case LSM6DS_RATE_104_HZ: + Serial.println("104 Hz"); + break; + case LSM6DS_RATE_208_HZ: + Serial.println("208 Hz"); + break; + case LSM6DS_RATE_416_HZ: + Serial.println("416 Hz"); + break; + case LSM6DS_RATE_833_HZ: + Serial.println("833 Hz"); + break; + case LSM6DS_RATE_1_66K_HZ: + Serial.println("1.66 KHz"); + break; + case LSM6DS_RATE_3_33K_HZ: + Serial.println("3.33 KHz"); + break; + case LSM6DS_RATE_6_66K_HZ: + Serial.println("6.66 KHz"); + break; + } - t = (float*)malloc(sizeof(float)); + // ism330dhcx.setGyroDataRate(LSM6DS_RATE_12_5_HZ); + Serial.print("Gyro data rate set to: "); + switch (ism330dhcx.getGyroDataRate()) { + case LSM6DS_RATE_SHUTDOWN: + Serial.println("0 Hz"); + break; + case LSM6DS_RATE_12_5_HZ: + Serial.println("12.5 Hz"); + break; + case LSM6DS_RATE_26_HZ: + Serial.println("26 Hz"); + break; + case LSM6DS_RATE_52_HZ: + Serial.println("52 Hz"); + break; + case LSM6DS_RATE_104_HZ: + Serial.println("104 Hz"); + break; + case LSM6DS_RATE_208_HZ: + Serial.println("208 Hz"); + break; + case LSM6DS_RATE_416_HZ: + Serial.println("416 Hz"); + break; + case LSM6DS_RATE_833_HZ: + Serial.println("833 Hz"); + break; + case LSM6DS_RATE_1_66K_HZ: + Serial.println("1.66 KHz"); + break; + case LSM6DS_RATE_3_33K_HZ: + Serial.println("3.33 KHz"); + break; + case LSM6DS_RATE_6_66K_HZ: + Serial.println("6.66 KHz"); + break; + } + ism330dhcx.configInt1(false, false, true); // accelerometer DRDY on INT1 + ism330dhcx.configInt2(false, true, false); // gyro DRDY on INT2 } void loop() { - // //board.readGyroData(x, y, z); - // IMU.readGyroscope(*x, *y, *z); - // Serial.print("Gyro X,Y,Z: "); - // Serial.print(*x, 2); - // Serial.print(" "); - // Serial.print(*y, 2); - // Serial.print(" "); - // Serial.print(*z, 2); - // Serial.print(" || "); - - // //board.readAccelData(f, g, h); - // IMU.readAcceleration(*f, *g, *h); - // Serial.print("Accel X,Y,Z: "); - // Serial.print(*f, 2); - // Serial.print(" "); - // Serial.print(*g, 2); - // Serial.print(" "); - // Serial.print(*h, 2); - // Serial.print(" || "); - - // //board.readTempData(t); - // IMU.readTemperature(*t); - // Serial.print("Temp: "); - // Serial.println(*t, 2); - - // delay(100); -} - + // /* Get a new normalized sensor event */ + sensors_event_t accel; + sensors_event_t gyro; + sensors_event_t temp; + ism330dhcx.getEvent(&accel, &gyro, &temp); + + Serial.print("\t\tTemperature "); + Serial.print(temp.temperature); + Serial.println(" deg C"); + + /* Display the results (acceleration is measured in m/s^2) */ + Serial.print("\t\tAccel X: "); + Serial.print(accel.acceleration.x); + Serial.print(" \tY: "); + Serial.print(accel.acceleration.y); + Serial.print(" \tZ: "); + Serial.print(accel.acceleration.z); + Serial.println(" m/s^2 "); + + /* Display the results (rotation is measured in rad/s) */ + Serial.print("\t\tGyro X: "); + Serial.print(gyro.gyro.x); + Serial.print(" \tY: "); + Serial.print(gyro.gyro.y); + Serial.print(" \tZ: "); + Serial.print(gyro.gyro.z); + Serial.println(" radians/s "); + Serial.println(); + + delay(100); + + // // serial plotter friendly format + + // Serial.print(temp.temperature); + // Serial.print(","); + + // Serial.print(accel.acceleration.x); + // Serial.print(","); Serial.print(accel.acceleration.y); + // Serial.print(","); Serial.print(accel.acceleration.z); + // Serial.print(","); + + // Serial.print(gyro.gyro.x); + // Serial.print(","); Serial.print(gyro.gyro.y); + // Serial.print(","); Serial.print(gyro.gyro.z); + // Serial.println(); + // delayMicroseconds(10000); +} \ No newline at end of file