-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc31701
commit 6424e0c
Showing
9 changed files
with
289 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include <Alfredo_NoU3.h> | ||
|
||
int interruptPinLSM6 = 48; | ||
int interruptPinMMC5 = 47; | ||
|
||
float acceleration_x, acceleration_y, acceleration_z; | ||
float gyroscope_x, gyroscope_y, gyroscope_z; | ||
float magnetometer_X, magnetometer_Y, magnetometer_Z; | ||
|
||
volatile bool newDataAvailableLSM6 = true; | ||
volatile bool newDataAvailableMMC5 = true; | ||
|
||
void setup() { | ||
NoU3.begin(); | ||
Serial.begin(115200); | ||
|
||
// Initialize LSM6 | ||
if (LSM6.begin(Wire1) == false) { | ||
Serial.println("LSM6 did not respond - check your wiring. Freezing."); | ||
while (true) {}; | ||
} | ||
pinMode(interruptPinLSM6, INPUT); | ||
attachInterrupt(digitalPinToInterrupt(interruptPinLSM6), interruptRoutineLSM6, RISING); | ||
LSM6.enableInterrupt(); | ||
|
||
// Initialize MMC5 | ||
if (MMC5.begin(Wire1) == false) { | ||
Serial.println("MMC5983MA did not respond - check your wiring. Freezing."); | ||
while (true) {}; | ||
} | ||
MMC5.softReset(); | ||
MMC5.setFilterBandwidth(800); | ||
MMC5.setContinuousModeFrequency(100); | ||
MMC5.enableAutomaticSetReset(); | ||
MMC5.enableContinuousMode(); | ||
pinMode(interruptPinMMC5, INPUT); | ||
attachInterrupt(digitalPinToInterrupt(interruptPinMMC5), interruptRoutineMMC5, RISING); | ||
MMC5.enableInterrupt(); | ||
|
||
Serial.println(); | ||
Serial.println("Accel_X\tAccel_Y\tAccel_Z\tGyro_X\tGyro_Y\tGyro_Z\tMag_X\tMag_Y\tMag_Z"); | ||
} | ||
|
||
void loop() { | ||
// Check LSM6 for new data | ||
if (newDataAvailableLSM6) { | ||
newDataAvailableLSM6 = false; | ||
|
||
if (LSM6.accelerationAvailable()) { | ||
LSM6.readAcceleration(&acceleration_x, &acceleration_y, &acceleration_z); | ||
} | ||
|
||
if (LSM6.gyroscopeAvailable()) { | ||
LSM6.readGyroscope(&gyroscope_x, &gyroscope_y, &gyroscope_z); | ||
} | ||
} | ||
|
||
// Check MMC5983MA for new data | ||
if (newDataAvailableMMC5) { | ||
newDataAvailableMMC5 = false; | ||
MMC5.clearMeasDoneInterrupt(); | ||
|
||
MMC5.readAccelerometer(&magnetometer_X, &magnetometer_Y, &magnetometer_Z); // Results in µT (microteslas). | ||
} | ||
|
||
formatPrint(acceleration_x); | ||
formatPrint(acceleration_y); | ||
formatPrint(acceleration_z); | ||
formatPrint(gyroscope_x); | ||
formatPrint(gyroscope_y); | ||
formatPrint(gyroscope_z); | ||
formatPrint(magnetometer_X); | ||
formatPrint(magnetometer_Y); | ||
formatPrint(magnetometer_Z); | ||
Serial.println('\t'); | ||
} | ||
|
||
void interruptRoutineLSM6() { | ||
newDataAvailableLSM6 = true; | ||
} | ||
|
||
void interruptRoutineMMC5() { | ||
newDataAvailableMMC5 = true; | ||
} | ||
|
||
void formatPrint(float num) { | ||
char buffer[11]; | ||
snprintf(buffer, sizeof(buffer), "%7.3f ", num); | ||
Serial.print(buffer); | ||
} |
76 changes: 44 additions & 32 deletions
76
examples/LSM6DSO_Wire1_SimpleAccelerometer/LSM6DSO_Wire1_SimpleAccelerometer.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,63 @@ | ||
/* | ||
Arduino LSM6DSOX - Simple Accelerometer | ||
This example reads the acceleration values from the LSM6DSOX | ||
sensor and continuously prints them to the Serial Monitor | ||
or Serial Plotter. | ||
#include <Alfredo_NoU3.h> | ||
|
||
The circuit: | ||
- Arduino Nano RP2040 Connect | ||
int interruptPinLSM6 = 48; | ||
|
||
created 10 May 2021 | ||
by Arturo Guadalupi | ||
float acceleration_x, acceleration_y, acceleration_z; | ||
float gyroscope_x, gyroscope_y, gyroscope_z; | ||
|
||
This example code is in the public domain. | ||
*/ | ||
|
||
#include <Alfredo_NoU3.h> | ||
volatile bool newDataAvailable = true; | ||
|
||
void setup() { | ||
Wire1.setPins(35, 36); | ||
|
||
Serial.begin(9600); | ||
while (!Serial); | ||
|
||
if (!IMU.begin()) { | ||
Serial.println("Failed to initialize IMU!"); | ||
NoU3.begin(); | ||
Serial.begin(115200); | ||
|
||
while (1); | ||
if (LSM6.begin(Wire1) == false) { | ||
Serial.println("LSM6 did not respond - check your wiring. Freezing."); | ||
while (true) {}; | ||
} | ||
pinMode(interruptPinLSM6, INPUT); | ||
attachInterrupt(digitalPinToInterrupt(interruptPinLSM6), interruptRoutine, RISING); | ||
LSM6.enableInterrupt(); | ||
|
||
Serial.print("Accelerometer sample rate = "); | ||
Serial.print(IMU.accelerationSampleRate()); | ||
Serial.print(LSM6.accelerationSampleRate()); | ||
Serial.println(" Hz"); | ||
Serial.println(); | ||
Serial.println("Acceleration in g's"); | ||
Serial.println("X\tY\tZ"); | ||
Serial.println("X\tY\tZ\tX\tY\tZ"); | ||
|
||
newDataAvailable = true; | ||
} | ||
|
||
void loop() { | ||
float x, y, z; | ||
if (newDataAvailable == true) { | ||
newDataAvailable = false; | ||
if (LSM6.accelerationAvailable()) { | ||
LSM6.readAcceleration(&acceleration_x, &acceleration_y, &acceleration_z); // Results are in g (earth gravity). | ||
} | ||
|
||
if (IMU.accelerationAvailable()) { | ||
IMU.readAcceleration(x, y, z); | ||
if (LSM6.gyroscopeAvailable()) { | ||
LSM6.readGyroscope(&gyroscope_x, &gyroscope_y, &gyroscope_z); // Results are in degrees/second. | ||
} | ||
|
||
Serial.print(x); | ||
Serial.print('\t'); | ||
Serial.print(y); | ||
Serial.print('\t'); | ||
Serial.println(z); | ||
printState(); | ||
} | ||
} | ||
|
||
void interruptRoutine() { | ||
newDataAvailable = true; | ||
} | ||
|
||
void printState() { | ||
Serial.print(acceleration_x); | ||
Serial.print('\t'); | ||
Serial.print(acceleration_y); | ||
Serial.print('\t'); | ||
Serial.print(acceleration_z); | ||
Serial.print('\t'); | ||
Serial.print(gyroscope_x); | ||
Serial.print('\t'); | ||
Serial.print(gyroscope_y); | ||
Serial.print('\t'); | ||
Serial.println(gyroscope_z); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.