-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
I try to simultaneously take acceleration and magnetic field readings from the sensor (otherwise why would there be an accelerometer and a magnetometer in the chip).
To get acceleration I take this library.
Call it with this code.
#include <Adafruit_LSM303_Accel.h>
#include <Adafruit_LSM303DLH_Mag.h>
Adafruit_LSM303_Accel_Unified accel(123);
Adafruit_LSM303DLH_Mag_Unified mag(321);
#define SerialPort Serial
void setup()
{
if (!accel.begin() && !mag.begin())
{
SerialPort.println("Oops ... unable to initialize the LSM303(accel + mag). Check your wiring!");
while (1);
}
}
void loop()
{
sensors_event_t accelEvent, magEvent;
accel.getEvent(&accelEvent);
mag.getEvent(&magEvent);
ax = accelEvent.acceleration.x;
ay = accelEvent.acceleration.y;
az = accelEvent.acceleration.z;
mx = magEvent.magnetic.x;
my = magEvent.magnetic.y
mz = magEvent.magnetic.z;
SerialPort.print("\t\tAccel X: ");
SerialPort.print(ax);
SerialPort.print(" \tY: ");
SerialPort.print(ay);
SerialPort.print(" \tZ: ");
SerialPort.print(az);
SerialPort.println(" m/s^2 ");
SerialPort.print("\t\tMag X: ");
SerialPort.print(mx);
SerialPort.print(" \tY: ");
SerialPort.print(my);
SerialPort.print(" \tZ: ");
SerialPort.print(mz);
Serial.print(" ");
Serial.println("uT");
}
But something is wrong and I only see acceleration values, while the values from the magnetometer are frozen at the same numbers.
Accel X: 2.30 Y: 4.14 Z: 6.44 m/s^2
Mag X: 10684.78 Y: -1996.96 Z: 15.61 uT
Separately, the example for the magnetometer works fine.
Is there some problem with calling events
sensors_event_t
from both the magnetometer and accelerometer?
Is it not possible to call them simultaneously using these libraries?
Metadata
Metadata
Assignees
Labels
No labels