diff --git a/examples/Modulino_Movement/Basic/Basic.ino b/examples/Modulino_Movement/Basic/Basic.ino deleted file mode 100644 index 956ae54..0000000 --- a/examples/Modulino_Movement/Basic/Basic.ino +++ /dev/null @@ -1,29 +0,0 @@ -#include "Modulino.h" - -ModulinoMovement movement; - -float x; -float y; -float z; - -void setup() { - Serial.begin(9600); - Modulino.begin(); - movement.begin(); -} - -void loop() { - movement.update(); - - x = movement.getX(); - y = movement.getY(); - z = movement.getZ(); - - Serial.print("Movement data: "); - Serial.print("x "); - Serial.print(x, 3); - Serial.print(" y "); - Serial.print(y, 3); - Serial.print(" z "); - Serial.println(z, 3); -} \ No newline at end of file diff --git a/examples/Modulino_Movement/Movement_Basic/Movement_Basic.ino b/examples/Modulino_Movement/Movement_Basic/Movement_Basic.ino new file mode 100644 index 0000000..dc8ccfb --- /dev/null +++ b/examples/Modulino_Movement/Movement_Basic/Movement_Basic.ino @@ -0,0 +1,57 @@ +/* + * Modulino Movement - Simple Serial Output + * + * This example code is in the public domain. + * Copyright (c) 2025 Arduino + * SPDX-License-Identifier: MPL-2.0 + */ + +#include "Modulino.h" + +// Create a ModulinoMovement +ModulinoMovement movement; + +float x, y, z; +float roll, pitch, yaw; + +void setup() { + Serial.begin(9600); + // Initialize Modulino I2C communication + Modulino.begin(); + // Detect and connect to movement sensor module + movement.begin(); + +} + +void loop() { + // Read new movement data from the sensor + movement.update(); + + // Get acceleration and gyroscope values + x = movement.getX(); + y = movement.getY(); + z = movement.getZ(); + roll = movement.getRoll(); + pitch = movement.getPitch(); + yaw = movement.getYaw(); + + // Print acceleration values + Serial.print("A: "); + Serial.print(x, 3); + Serial.print(", "); + Serial.print(y, 3); + Serial.print(", "); + Serial.print(z, 3); + + // Print divider between acceleration and gyroscope + Serial.print(" | G: "); + + // Print gyroscope values + Serial.print(roll, 1); + Serial.print(", "); + Serial.print(pitch, 1); + Serial.print(", "); + Serial.println(yaw, 1); + + delay(200); +} \ No newline at end of file diff --git a/src/Modulino.h b/src/Modulino.h index 128c46d..aa37d47 100644 --- a/src/Modulino.h +++ b/src/Modulino.h @@ -313,13 +313,15 @@ class ModulinoMovement : public Module { } int update() { if (initialized) { - return _imu->readAcceleration(x, y, z); + int accel = _imu->readAcceleration(x, y, z); + int gyro = _imu->readGyroscope(roll, pitch, yaw); + return accel && gyro; } return 0; } int available() { if (initialized) { - return _imu->accelerationAvailable(); + return _imu->accelerationAvailable() && _imu->gyroscopeAvailable(); } return 0; } @@ -332,9 +334,19 @@ class ModulinoMovement : public Module { float getZ() { return z; } + float getRoll() { + return roll; + } + float getPitch() { + return pitch; + } + float getYaw() { + return yaw; + } private: LSM6DSOXClass* _imu = nullptr; float x,y,z; + float roll,pitch,yaw; //gx, gy, gz int initialized = 0; };