Open mjs513 opened 6 years ago
The "library" was written for the STM32L4 development boards which use a non-standard wire method. So rewriting to something more like the ESP8285 uses should fix this "problem". RTC is also a STM32L4 method.
Are you still having trouble?
On Thu, Feb 8, 2018 at 2:42 PM, Mike S notifications@github.com wrote:
Hi Kris,
I am trying to get this to work with the Teensy's. A few things:
- LIS2MDL., LSM6DSM (i2cscan wire.transfer has to be commented out and the two previous lines uncommented) both use wire.transfer method for readbyte and readbytes. I changed them to match what was in LPS22HB and that seemed to resolve that issue. But other issues are cropping up, more on that later.
- I changed rtc stuff in the main sketch to use elapsedMillis for printing time and that seemed to work.
- Changed Wire.begin to just Wire.begin();
All seemed to work but I noticed that values for ay were around 7-10 when I did the calibration which was below the ranges specified. When the sketch ran the magnetometer values were always zero. Eventually no values were returned from the imu. Now, for the wiring I am not sure about if I got the interrupt pins correct so here is what I have: //LSM6DSM definitions
define LSM6DSM_intPin1 13 // interrupt1 pin definitions, significant
motion: goes to gnt
define LSM6DSM_intPin2 12 // interrupt2 pin definitions, data ready: goes
to ant
Writing this I figured out the issue with my magnet and barometer - had wires switch.
Thanks Mike
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kriswiner/LSM6DSM_LIS2MDL_LPS22HB/issues/3, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qoCU5aC-nkuVBeRIlauZDEZgl7sEks5tS3g9gaJpZM4R_JCO .
No I don't think so. Yaw doesn't update but I will figure it out. Do have a question though. What are units for the magnetometer, mx,my mz. Are they gauss or milligauss. Looks like it's gauss
Oh when I get every thing updated I will post the code for the arduino
I think I usually use milliGauss.
Not quite sure why you;re having trouble here, the code works well for me. At least on the STM32L4 MCUs.
On Thu, Feb 8, 2018 at 5:11 PM, Mike S notifications@github.com wrote:
Oh when I get every thing updated I will post the code for the arduino
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/LSM6DSM_LIS2MDL_LPS22HB/issues/3#issuecomment-364303493, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qsodK-KYu5f2rTzPiRVZX15HT8kNks5tS5tBgaJpZM4R_JCO .
Hi Kris, Actually, the example sketch for the teensy 3.2 that I am using with the IMU works fine. I found another wire to the interrupts I had backwards which was causing the problem originally. I was just curious about the units. Got that figured out now. Again it all works on a Teensy 3,2 and probably for any Arduino board now with the changes I made. Sorry if I did not make it clear what MCU's' I was using.
I am having a devil of a time getting it to work in a different sketch and not sure what the problem is, reads the data once and the not again. Have to go through the code again. If not I may ask you what I am doing wrong - hope you don't mind. This is for another project I am involved in over on the Teensy forum.
Hi, I give up. I repurposed your example sketch that I modified for the Teensy 3.2 and got everything working except for the magnetometer in the loop. Accel and gyro updates fine. Setup seems to work because it goes through the calibration no problem. Any help would be appreciated:
#include "uNavAHRS.h"
#include <Wire.h>
#include <LSM6DSM.h>
#include <LIS2MDL.h>
#include <elapsedMillis.h>
#include <ArduinoLog.h>
elapsedMillis sincePrint;
#define SerialDebug true // set to true to get Serial output for debugging
#define myLed 13
float pitch, yaw, roll; // absolute orientation
float a12, a22, a31, a32, a33; // rotation matrix coefficients for Euler angles and gravity components
float lin_ax, lin_ay, lin_az; // linear acceleration (acceleration with gravity component subtracted)
float q[4] = {1.0f, 0.0f, 0.0f, 0.0f}; // vector to hold quaternion
//============================================================================
float q0, q1, q2, q3;
float a_x, a_y, a_z, g_x, g_y, g_z; // variables to hold latest accel/gyro data values
float m_x, m_y, m_z;
#define G 9.809
//Needed for Tviewer
char gbx_text[30];
char gby_text[30];
char gbz_text[30];
char yawf_text[30];
char pitchf_text[30];
char rollf_text[30];
char yaw_text[30];
char pitch_text[30];
char roll_text[30];
char q0_text[30];
char q1_text[30];
char q2_text[30];
char q3_text[30];
char heading_text[30];
//==============================
// a uNavAHRS object
uNavAHRS FilterUNAV;
//==============================
//LSM6DSM definitions
#define LSM6DSM_intPin1 13 // interrupt1 pin definitions, significant motion
#define LSM6DSM_intPin2 12 // interrupt2 pin definitions, data ready
/* Specify sensor parameters (sample rate is twice the bandwidth)
* choices are:
AFS_2G, AFS_4G, AFS_8G, AFS_16G
GFS_245DPS, GFS_500DPS, GFS_1000DPS, GFS_2000DPS
AODR_12_5Hz, AODR_26Hz, AODR_52Hz, AODR_104Hz, AODR_208Hz, AODR_416Hz, AODR_833Hz, AODR_1660Hz, AODR_3330Hz, AODR_6660Hz
GODR_12_5Hz, GODR_26Hz, GODR_52Hz, GODR_104Hz, GODR_208Hz, GODR_416Hz, GODR_833Hz, GODR_1660Hz, GODR_3330Hz, GODR_6660Hz
*/
uint8_t Ascale = AFS_2G, Gscale = GFS_245DPS, AODR = AODR_208Hz, GODR = GODR_416Hz;
float aRes, gRes; // scale resolutions per LSB for the accel and gyro sensor2
float accelBias[3] = {0., 0., 0.}, gyroBias[3] = {0., 0., 0.}; // offset biases for the accel and gyro
int16_t LSM6DSMData[7]; // Stores the 16-bit signed sensor output
float Gtemperature; // Stores the real internal gyro temperature in degrees Celsius
float ax, ay, az, gx, gy, gz; // variables to hold latest accel/gyro data values
bool newLSM6DSMData = false;
bool newLSM6DSMTap = false;
LSM6DSM LSM6DSM(LSM6DSM_intPin1, LSM6DSM_intPin2); // instantiate LSM6DSM class
//LIS2MDL definitions
#define LIS2MDL_intPin 4 // interrupt for magnetometer data ready
/* Specify sensor parameters (sample rate is twice the bandwidth)
* choices are: MODR_10Hz, MOIDR_20Hz, MODR_50 Hz and MODR_100Hz
*/
uint8_t MODR = MODR_100Hz;
float mRes = 0.0015f; // mag sensitivity
float magBias[3] = {0,0,0}, magScale[3] = {0,0,0}; // Bias corrections for magnetometer
int16_t LIS2MDLData[4]; // Stores the 16-bit signed sensor output
float Mtemperature; // Stores the real internal chip temperature in degrees Celsius
float mx, my, mz; // variables to hold latest mag data values
uint8_t LIS2MDLstatus;
bool newLIS2MDLData = false;
LIS2MDL LIS2MDL(LIS2MDL_intPin); // instantiate LIS2MDL class
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while(!Serial && millis() < 2000 ) {}
delay(4000);
// Configure led
pinMode(myLed, OUTPUT);
digitalWrite(myLed, HIGH); // start with led off
Wire.begin(); // set master mode
Wire.setClock(400000); // I2C frequency at 400 kHz
delay(1000);
// Pass log level, whether to show log level, and print interface.
// Available levels are:
// LOG_LEVEL_SILENT, LOG_LEVEL_FATAL, LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, LOG_LEVEL_NOTICE, LOG_LEVEL_TRACE, LOG_LEVEL_VERBOSE
// Note: if you want to fully remove all logging code, uncomment #define DISABLE_LOGGING in Logging.h
// this will significantly reduce your project size
Log.begin(LOG_LEVEL_SILENT, &Serial);
//Log.setPrefix(printTimestamp); // Uncomment to get timestamps as prefix
//Log.setSuffix(printNewline); // Uncomment to get newline as suffix
//Start logging
Log.notice(F(CR "******************************************" CR)); // Info string with Newline
Log.notice( "*** Logging example " CR); // Info string in flash memory
Log.notice(F("******************* ")); Log.notice("*********************** " CR); // two info strings without newline
LSM6DSM.I2Cscan();
// Read the LSM6DSM Chip ID register, this is a good test of communication
Serial.println("LSM6DSM accel/gyro...");
byte c = LSM6DSM.getChipID(); // Read CHIP_ID register for LSM6DSM
Serial.print("LSM6DSM "); Serial.print("I AM "); Serial.print(c, HEX); Serial.print(" I should be "); Serial.println(0x6A, HEX);
Serial.println(" ");
delay(1000);
// Read the LIS2MDL Chip ID register, this is a good test of communication
Serial.println("LIS2MDL mag...");
byte d = LIS2MDL.getChipID(); // Read CHIP_ID register for LSM6DSM
Serial.print("LIS2MDL "); Serial.print("I AM "); Serial.print(d, HEX); Serial.print(" I should be "); Serial.println(0x40, HEX);
Serial.println(" ");
delay(1000);
if(c == 0x6A && d == 0x40) // check if all I2C sensors have acknowledged
{
Serial.println("LSM6DSM and LIS2MDL are online..."); Serial.println(" ");
digitalWrite(myLed, LOW);
LSM6DSM.reset(); // software reset LSM6DSM to default registers
// get sensor resolutions, only need to do this once
aRes = LSM6DSM.getAres(Ascale);
gRes = LSM6DSM.getGres(Gscale);
LSM6DSM.init(Ascale, Gscale, AODR, GODR);
LSM6DSM.selfTest();
LSM6DSM.offsetBias(gyroBias, accelBias);
Serial.println("accel biases (g)"); Serial.println(accelBias[0]); Serial.println(accelBias[1]); Serial.println( accelBias[2]);
Serial.println("gyro biases (dps)"); Serial.println(gyroBias[0]); Serial.println(gyroBias[1]); Serial.println(gyroBias[2]);
delay(1000);
LIS2MDL.reset(); // software reset LIS2MDL to default registers
mRes = 0.0015f; // fixed sensitivity and full scale (+/- 49.152 Gauss);
LIS2MDL.init(MODR);
LIS2MDL.selfTest();
LIS2MDL.offsetBias(magBias, magScale);
Serial.println("mag biases (G)"); Serial.println(magBias[0],6); Serial.println(magBias[1],6); Serial.println(magBias[2],6);
Serial.println("mag scale (G)"); Serial.println(magScale[0],6); Serial.println(magScale[1],6); Serial.println(magScale[2],6);
delay(2000); // add delay to see results before serial spew of data
digitalWrite(myLed, HIGH);
}
else
{
if(c != 0x6A) Serial.println(" LSM6DSM not functioning!");
if(d != 0x40) Serial.println(" LIS2MDL not functioning!");
}
attachInterrupt(LSM6DSM_intPin2, myinthandler1, RISING); // define interrupt for intPin2 output of LSM6DSM
attachInterrupt(LIS2MDL_intPin , myinthandler2, RISING); // define interrupt for intPin output of LIS2MDL
LIS2MDL.readData(LIS2MDLData); // read data register to clear interrupt before main loop
}
/* End of setup */
void loop() {
// If intPin goes high, either all data registers have new data
if(newLSM6DSMData == true) { // On interrupt, read data
newLSM6DSMData = false; // reset newData flag
LSM6DSM.readData(LSM6DSMData); // INT2 cleared on any read
// Now we'll calculate the accleration value into actual g's
a_x = (float)LSM6DSMData[4]*aRes - accelBias[0]; // get actual g value, this depends on scale being set
a_y = (float)LSM6DSMData[5]*aRes - accelBias[1];
a_z = (float)LSM6DSMData[6]*aRes - accelBias[2];
// Calculate the gyro value into actual degrees per second
g_x = (float)LSM6DSMData[1]*gRes - gyroBias[0]; // get actual gyro value, this depends on scale being set
g_y = (float)LSM6DSMData[2]*gRes - gyroBias[1];
g_z = (float)LSM6DSMData[3]*gRes - gyroBias[2];
}
// If intPin goes high, either all data registers have new data
if(newLIS2MDLData == true) { // On interrupt, read data
newLIS2MDLData = false; // reset newData flag
LIS2MDLstatus = LIS2MDL.status();
if(LIS2MDLstatus & 0x08) // if all axes hae new data ready
{
LIS2MDL.readData(LIS2MDLData);
// Now we'll calculate the magnetometer value into actual G's
m_x = (float)LIS2MDLData[0]*mRes - magBias[0]; // get actual G value
m_y = (float)LIS2MDLData[1]*mRes - magBias[1];
m_z = (float)LIS2MDLData[2]*mRes - magBias[2];
m_x *= magScale[0];
m_y *= magScale[1];
m_z *= magScale[2];
}
}
FilterUNAV.update(g_x*PI/180.0f, g_y*PI/180.0f, g_z*PI/180.0f, a_x*G, a_y*G, a_z*G, m_x*0.1, m_y*0.1, m_z*0.1);
if (sincePrint > 100){
sincePrint=0;
if(SerialDebug) {
Serial.print("ax = "); Serial.print(a_x);
Serial.print(" ay = "); Serial.print(a_y);
Serial.print(" az = "); Serial.print(a_z); Serial.println(" g");
Serial.print("gx = "); Serial.print( g_x, 2);
Serial.print(" gy = "); Serial.print( g_y, 2);
Serial.print(" gz = "); Serial.print( g_z, 2); Serial.println(" deg/s");
Serial.print("mx = "); Serial.print(m_x);
Serial.print(" my = "); Serial.print(m_y);
Serial.print(" mz = "); Serial.print(m_z); Serial.println(" G");
Serial.print("q0 = "); Serial.print(q[0]);
Serial.print(" qx = "); Serial.print(q[1]);
Serial.print(" qy = "); Serial.print(q[2]);
Serial.print(" qz = "); Serial.println(q[3]);
}
FilterUNAV.getQuaternion(&q0, &q1, &q2, &q3);
float gbx = FilterUNAV.getGyroBiasX_rads();
float gby = FilterUNAV.getGyroBiasY_rads();
float gbz = FilterUNAV.getGyroBiasZ_rads();
float yawf = FilterUNAV.getYaw_rad()*180.0f/PI;
float pitchf = FilterUNAV.getPitch_rad()*180.0f/PI;
float rollf = FilterUNAV.getRoll_rad()*180.0f/PI;
float yaw = g_x;
float pitch = g_y;
float roll = g_z;
float heading;
FilterUNAV.getDipAngle(&heading);
dtostrf(gbx, 10, 10, gbx_text);
dtostrf(gby, 10, 10, gby_text);
dtostrf(gbz, 10, 10, gbz_text);
dtostrf(yawf, 10, 10, yawf_text);
dtostrf(pitchf, 10, 10, pitchf_text);
dtostrf(rollf, 10, 10, rollf_text);
dtostrf(yaw, 10, 10, yaw_text);
dtostrf(pitch, 10, 10, pitch_text);
dtostrf(roll, 10, 10, roll_text);
dtostrf(q0, 10, 10, q0_text);
dtostrf(q1, 10, 10, q1_text);
dtostrf(q2, 10, 10, q2_text);
dtostrf(q3, 10, 10, q3_text);
dtostrf(heading, 10, 10, heading_text);
char text[434];
snprintf(text, 434, "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", gbx_text, gby_text, gbz_text, yawf_text, pitchf_text, rollf_text, yaw_text, pitch_text, roll_text, q0_text, q1_text, q2_text, q3_text, heading_text);
Serial.println(text);
/* Gtemperature = ((float) LSM6DSMData[0]) / 256.0f + 25.0f; // Gyro chip temperature in degrees Centigrade
// Print temperature in degrees Centigrade
if(SerialDebug) {
Serial.print("Gyro temperature is "); Serial.print(Gtemperature, 1); Serial.println(" degrees C"); // Print T values to tenths of s degree C
}
LIS2MDLData[3] = LIS2MDL.readTemperature();
Mtemperature = ((float) LIS2MDLData[3]) / 8.0f + 25.0f; // Mag chip temperature in degrees Centigrade
// Print temperature in degrees Centigrade
if(SerialDebug) {
Serial.print("Mag temperature is "); Serial.print(Mtemperature, 1); Serial.println(" degrees C"); // Print T values to tenths of s degree C
}
*/
}
digitalWrite(myLed, LOW); delay(1); digitalWrite(myLed, HIGH);
}
/* End of main loop */
void myinthandler1()
{
newLSM6DSMData = true;
}
void myinthandler2()
{
newLIS2MDLData = true;
}
I assume you get the correct WHO_AM_I response and that the magBias and magScale are non-zero?
I would try moving the pinMode calls out of the classes and put them into the main sketc. I don't think this is your problem but I was informed leaving these in the class structure is bad practice and it did cure a problem I was having with the SPI flash (not your problem here).
The mag values are Gauss. Did you verify that you get mag data with polling? In other words is the problem the interrupt or reading the data registers? If the latter, what does the raw data look like?
The code looks right so it should work barring a hook up problem.
On Thu, Feb 8, 2018 at 8:45 PM, Mike S notifications@github.com wrote:
Hi, I give up. I repurposed your example sketch that I modified for the Teensy 3.2 and got everything working except for the magnetometer in the loop. Accel and gyro updates fine. Setup seems to work because it goes through the calibration no problem. Any help would be appreciated:
include "uNavAHRS.h"
include
include
include
include
include
elapsedMillis sincePrint;
define SerialDebug true // set to true to get Serial output for debugging
define myLed 13
float pitch, yaw, roll; // absolute orientation float a12, a22, a31, a32, a33; // rotation matrix coefficients for Euler angles and gravity components float lin_ax, lin_ay, lin_az; // linear acceleration (acceleration with gravity component subtracted) float q[4] = {1.0f, 0.0f, 0.0f, 0.0f}; // vector to hold quaternion //============================================================================ float q0, q1, q2, q3; float a_x, a_y, a_z, g_x, g_y, g_z; // variables to hold latest accel/gyro data values float m_x, m_y, m_z;
define G 9.809
//Needed for Tviewer char gbx_text[30]; char gby_text[30]; char gbz_text[30]; char yawf_text[30]; char pitchf_text[30]; char rollf_text[30]; char yaw_text[30]; char pitch_text[30]; char roll_text[30]; char q0_text[30]; char q1_text[30]; char q2_text[30]; char q3_text[30]; char heading_text[30];
//============================== // a uNavAHRS object uNavAHRS FilterUNAV; //==============================
//LSM6DSM definitions
define LSM6DSM_intPin1 13 // interrupt1 pin definitions, significant motion
define LSM6DSM_intPin2 12 // interrupt2 pin definitions, data ready
/* Specify sensor parameters (sample rate is twice the bandwidth)
- choices are: AFS_2G, AFS_4G, AFS_8G, AFS_16G GFS_245DPS, GFS_500DPS, GFS_1000DPS, GFS_2000DPS AODR_12_5Hz, AODR_26Hz, AODR_52Hz, AODR_104Hz, AODR_208Hz, AODR_416Hz, AODR_833Hz, AODR_1660Hz, AODR_3330Hz, AODR_6660Hz GODR_12_5Hz, GODR_26Hz, GODR_52Hz, GODR_104Hz, GODR_208Hz, GODR_416Hz, GODR_833Hz, GODR_1660Hz, GODR_3330Hz, GODR_6660Hz */ uint8_t Ascale = AFS_2G, Gscale = GFS_245DPS, AODR = AODR_208Hz, GODR = GODR_416Hz;
float aRes, gRes; // scale resolutions per LSB for the accel and gyro sensor2 float accelBias[3] = {0., 0., 0.}, gyroBias[3] = {0., 0., 0.}; // offset biases for the accel and gyro int16_t LSM6DSMData[7]; // Stores the 16-bit signed sensor output float Gtemperature; // Stores the real internal gyro temperature in degrees Celsius float ax, ay, az, gx, gy, gz; // variables to hold latest accel/gyro data values
bool newLSM6DSMData = false; bool newLSM6DSMTap = false;
LSM6DSM LSM6DSM(LSM6DSM_intPin1, LSM6DSM_intPin2); // instantiate LSM6DSM class
//LIS2MDL definitions
define LIS2MDL_intPin 4 // interrupt for magnetometer data ready
/* Specify sensor parameters (sample rate is twice the bandwidth)
- choices are: MODR_10Hz, MOIDR_20Hz, MODR_50 Hz and MODR_100Hz */ uint8_t MODR = MODR_100Hz;
float mRes = 0.0015f; // mag sensitivity float magBias[3] = {0,0,0}, magScale[3] = {0,0,0}; // Bias corrections for magnetometer int16_t LIS2MDLData[4]; // Stores the 16-bit signed sensor output float Mtemperature; // Stores the real internal chip temperature in degrees Celsius float mx, my, mz; // variables to hold latest mag data values uint8_t LIS2MDLstatus;
bool newLIS2MDLData = false;
LIS2MDL LIS2MDL(LIS2MDL_intPin); // instantiate LIS2MDL class
void setup() { // put your setup code here, to run once: Serial.begin(115200); while(!Serial && millis() < 2000 ) {} delay(4000);
// Configure led pinMode(myLed, OUTPUT); digitalWrite(myLed, HIGH); // start with led off
Wire.begin(); // set master mode Wire.setClock(400000); // I2C frequency at 400 kHz delay(1000);
// Pass log level, whether to show log level, and print interface. // Available levels are: // LOG_LEVEL_SILENT, LOG_LEVEL_FATAL, LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, LOG_LEVEL_NOTICE, LOG_LEVEL_TRACE, LOG_LEVEL_VERBOSE // Note: if you want to fully remove all logging code, uncomment #define DISABLE_LOGGING in Logging.h // this will significantly reduce your project size Log.begin(LOG_LEVEL_SILENT, &Serial); //Log.setPrefix(printTimestamp); // Uncomment to get timestamps as prefix //Log.setSuffix(printNewline); // Uncomment to get newline as suffix //Start logging Log.notice(F(CR "******************************************" CR)); // Info string with Newline Log.notice( "*** Logging example " CR); // Info string in flash memory Log.notice(F("******************* ")); Log.notice("*********************** " CR); // two info strings without newline
LSM6DSM.I2Cscan();
// Read the LSM6DSM Chip ID register, this is a good test of communication Serial.println("LSM6DSM accel/gyro..."); byte c = LSM6DSM.getChipID(); // Read CHIP_ID register for LSM6DSM Serial.print("LSM6DSM "); Serial.print("I AM "); Serial.print(c, HEX); Serial.print(" I should be "); Serial.println(0x6A, HEX); Serial.println(" "); delay(1000);
// Read the LIS2MDL Chip ID register, this is a good test of communication Serial.println("LIS2MDL mag..."); byte d = LIS2MDL.getChipID(); // Read CHIP_ID register for LSM6DSM Serial.print("LIS2MDL "); Serial.print("I AM "); Serial.print(d, HEX); Serial.print(" I should be "); Serial.println(0x40, HEX); Serial.println(" "); delay(1000);
if(c == 0x6A && d == 0x40) // check if all I2C sensors have acknowledged { Serial.println("LSM6DSM and LIS2MDL are online..."); Serial.println(" ");
digitalWrite(myLed, LOW);
LSM6DSM.reset(); // software reset LSM6DSM to default registers
// get sensor resolutions, only need to do this once aRes = LSM6DSM.getAres(Ascale); gRes = LSM6DSM.getGres(Gscale);
LSM6DSM.init(Ascale, Gscale, AODR, GODR);
LSM6DSM.selfTest();
LSM6DSM.offsetBias(gyroBias, accelBias); Serial.println("accel biases (g)"); Serial.println(accelBias[0]); Serial.println(accelBias[1]); Serial.println( accelBias[2]); Serial.println("gyro biases (dps)"); Serial.println(gyroBias[0]); Serial.println(gyroBias[1]); Serial.println(gyroBias[2]); delay(1000);
LIS2MDL.reset(); // software reset LIS2MDL to default registers
mRes = 0.0015f; // fixed sensitivity and full scale (+/- 49.152 Gauss);
LIS2MDL.init(MODR);
LIS2MDL.selfTest();
LIS2MDL.offsetBias(magBias, magScale); Serial.println("mag biases (G)"); Serial.println(magBias[0],6); Serial.println(magBias[1],6); Serial.println(magBias[2],6); Serial.println("mag scale (G)"); Serial.println(magScale[0],6); Serial.println(magScale[1],6); Serial.println(magScale[2],6); delay(2000); // add delay to see results before serial spew of data
digitalWrite(myLed, HIGH);
} else { if(c != 0x6A) Serial.println(" LSM6DSM not functioning!"); if(d != 0x40) Serial.println(" LIS2MDL not functioning!"); }
attachInterrupt(LSM6DSM_intPin2, myinthandler1, RISING); // define interrupt for intPin2 output of LSM6DSM attachInterrupt(LIS2MDL_intPin , myinthandler2, RISING); // define interrupt for intPin output of LIS2MDL
LIS2MDL.readData(LIS2MDLData); // read data register to clear interrupt before main loop
} / End of setup /
void loop() {
// If intPin goes high, either all data registers have new data if(newLSM6DSMData == true) { // On interrupt, read data newLSM6DSMData = false; // reset newData flag
LSM6DSM.readData(LSM6DSMData); // INT2 cleared on any read
// Now we'll calculate the accleration value into actual g's a_x = (float)LSM6DSMData[4]aRes - accelBias[0]; // get actual g value, this depends on scale being set a_y = (float)LSM6DSMData[5]aRes - accelBias[1]; a_z = (float)LSM6DSMData[6]*aRes - accelBias[2];
// Calculate the gyro value into actual degrees per second g_x = (float)LSM6DSMData[1]gRes - gyroBias[0]; // get actual gyro value, this depends on scale being set g_y = (float)LSM6DSMData[2]gRes - gyroBias[1]; g_z = (float)LSM6DSMData[3]*gRes - gyroBias[2]; }
// If intPin goes high, either all data registers have new data
if(newLIS2MDLData == true) { // On interrupt, read data newLIS2MDLData = false; // reset newData flag
LIS2MDLstatus = LIS2MDL.status(); if(LIS2MDLstatus & 0x08) // if all axes hae new data ready { LIS2MDL.readData(LIS2MDLData);
// Now we'll calculate the magnetometer value into actual G's m_x = (float)LIS2MDLData[0]mRes - magBias[0]; // get actual G value m_y = (float)LIS2MDLData[1]mRes - magBias[1]; m_z = (float)LIS2MDLData[2]mRes - magBias[2]; m_x = magScale[0]; m_y = magScale[1]; m_z = magScale[2]; } }
FilterUNAV.update(g_xPI/180.0f, g_yPI/180.0f, g_zPI/180.0f, a_xG, a_yG, a_zG, m_x0.1, m_y0.1, m_z*0.1);
if (sincePrint > 100){ sincePrint=0;
if(SerialDebug) { Serial.print("ax = "); Serial.print(a_x); Serial.print(" ay = "); Serial.print(a_y); Serial.print(" az = "); Serial.print(a_z); Serial.println(" g"); Serial.print("gx = "); Serial.print( g_x, 2); Serial.print(" gy = "); Serial.print( g_y, 2); Serial.print(" gz = "); Serial.print( g_z, 2); Serial.println(" deg/s"); Serial.print("mx = "); Serial.print(m_x); Serial.print(" my = "); Serial.print(m_y); Serial.print(" mz = "); Serial.print(m_z); Serial.println(" G"); Serial.print("q0 = "); Serial.print(q[0]); Serial.print(" qx = "); Serial.print(q[1]); Serial.print(" qy = "); Serial.print(q[2]); Serial.print(" qz = "); Serial.println(q[3]); } FilterUNAV.getQuaternion(&q0, &q1, &q2, &q3); float gbx = FilterUNAV.getGyroBiasX_rads(); float gby = FilterUNAV.getGyroBiasY_rads(); float gbz = FilterUNAV.getGyroBiasZ_rads(); float yawf = FilterUNAV.getYaw_rad()*180.0f/PI; float pitchf = FilterUNAV.getPitch_rad()*180.0f/PI; float rollf = FilterUNAV.getRoll_rad()*180.0f/PI; float yaw = g_x; float pitch = g_y; float roll = g_z; float heading; FilterUNAV.getDipAngle(&heading); dtostrf(gbx, 10, 10, gbx_text); dtostrf(gby, 10, 10, gby_text); dtostrf(gbz, 10, 10, gbz_text); dtostrf(yawf, 10, 10, yawf_text); dtostrf(pitchf, 10, 10, pitchf_text); dtostrf(rollf, 10, 10, rollf_text); dtostrf(yaw, 10, 10, yaw_text); dtostrf(pitch, 10, 10, pitch_text); dtostrf(roll, 10, 10, roll_text); dtostrf(q0, 10, 10, q0_text); dtostrf(q1, 10, 10, q1_text); dtostrf(q2, 10, 10, q2_text); dtostrf(q3, 10, 10, q3_text); dtostrf(heading, 10, 10, heading_text); char text[434]; snprintf(text, 434, "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", gbx_text, gby_text, gbz_text, yawf_text, pitchf_text, rollf_text, yaw_text, pitch_text, roll_text, q0_text, q1_text, q2_text, q3_text, heading_text); Serial.println(text);
/* Gtemperature = ((float) LSM6DSMData[0]) / 256.0f + 25.0f; // Gyro chip temperature in degrees Centigrade // Print temperature in degrees Centigrade if(SerialDebug) { Serial.print("Gyro temperature is "); Serial.print(Gtemperature, 1); Serial.println(" degrees C"); // Print T values to tenths of s degree C }
LIS2MDLData[3] = LIS2MDL.readTemperature(); Mtemperature = ((float) LIS2MDLData[3]) / 8.0f + 25.0f; // Mag chip temperature in degrees Centigrade // Print temperature in degrees Centigrade if(SerialDebug) { Serial.print("Mag temperature is "); Serial.print(Mtemperature, 1); Serial.println(" degrees C"); // Print T values to tenths of s degree C }
*/ }
digitalWrite(myLed, LOW); delay(1); digitalWrite(myLed, HIGH);
} / End of main loop /
void myinthandler1() { newLSM6DSMData = true; }
void myinthandler2() { newLIS2MDLData = true; }
— You are receiving this because you commented. Reply to this email directly, view it on GitHub <https://github.com/kriswiner/LSM6DSM_LIS2MDL_LPS22HB/issues/3#issuecomment-364333806>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AGY1quDEjlxkTeVrWJypZvYj6VVLiuc5ks5tS81mgaJpZM4R_JCO> .
Thanks for the sanity check on the code. Sure the hookup is right cause it works in the other sketch. Yes wia is all right and the biases and offsets look ok.
I will work try your recommendations in the morning. Done for tonight.
Thanks Mike
Hi Kris, Got it working now. Moved pinMode out of the class for the magnetometer and redid the wiring so all is right with the world. I will go ahead and close this if you don't mind.
OK, glad it's working, so the pin mode was the issue?
On Fri, Feb 9, 2018 at 10:00 AM, Mike S notifications@github.com wrote:
Hi Kris, Got it working now. Moved pinMode out of the class for the magnetometer and redid the wiring so all is right with the world. I will go ahead and close this if you don't mind.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/LSM6DSM_LIS2MDL_LPS22HB/issues/3#issuecomment-364510136, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qixJCkomr2K37fNshMRatGwe5vkzks5tTIe9gaJpZM4R_JCO .
Not 100% sure had mag and baro wires crossed as well. Made a change late last night and forgot to change it in the code. But since you recommended to remove it from the class I did. If you want I can do a double check later.
No, most likely the wires were the cause since having the pin mode in the class didn't both me, just not good practice.
On Fri, Feb 9, 2018 at 10:09 AM, Mike S notifications@github.com wrote:
Not 100% sure had mag and baro wires crossed as well. Made a change late last night and forgot to change it in the code. But since you recommended to remove it from the class I did. If you want I can do a double check later.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/LSM6DSM_LIS2MDL_LPS22HB/issues/3#issuecomment-364512496, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qrt9M679lZ7OqlJ0wkwIbwOpQZDAks5tTIn1gaJpZM4R_JCO .
Hi Kris,
I am trying to get this to work with the Teensy's. A few things:
All seemed to work but I noticed that values for ay were around 7-10 when I did the calibration which was below the ranges specified. When the sketch ran the magnetometer values were always zero. Eventually no values were returned from the imu. Now, for the wiring I am not sure about if I got the interrupt pins correct so here is what I have: //LSM6DSM definitions
define LSM6DSM_intPin1 13 // interrupt1 pin definitions, significant motion: goes to gnt
define LSM6DSM_intPin2 12 // interrupt2 pin definitions, data ready: goes to ant
Writing this I figured out the issue with my magnet and barometer - had wires switch.
Thanks Mike