0

Self leveling platform. Need tilt angle feedback
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Self leveling platform. Need tilt angle feedback

by BVarv on Fri May 19, 2017 11:40 pm

Hey there,

I ordered two Flora 9-dof accelerometer/gyroscope/magentometer LSM9DS0 sensors thinking I could use them with an arduino. Only after digging deeper did I realize they are a break out board for the Flora device.

my order number is 1433786-2359699268

I'm trying to make a self leveling platform using an arduino. I have the axis of the platform servo controlled, I just need tilt angle feedback to tell the arduino what adjustments to make to keep the platform level.

Do you have any recommendations for a sensor that will give me tilt information Via an Arduino?

If I am correct and the parts I purchased will not work, I would please like to return them.

Thank you,
Ben

BVarv
 
Posts: 9
Joined: Fri May 19, 2017 11:37 pm

Re: Self leveling platform. Need tilt angle feedback

by adafruit_support_mike on Sat May 20, 2017 4:08 am

Those sensors will also work with an Arduino. The LSM9DS0 is an I2C device, so it doesn't really care what kind of microcontroller is at the other end of the connection.

The Flora breakout just happens to be on a PCB that's easy to use in wearable circuits.

adafruit_support_mike
 
Posts: 45246
Joined: Thu Feb 11, 2010 2:51 pm

Re: Self leveling platform. Need tilt angle feedback

by BVarv on Sat May 20, 2017 12:00 pm

YES. It's great news that I can make the hardware I purchased work. Thank you.

After some reading about i2C (https://learn.sparkfun.com/tutorials/i2c) and about the LSM9DS0 chip (https://cdn-shop.adafruit.com/datasheets/LSM9DS0.pdf), I now see what you mean about how Flora is just a clever means of connecting to the LSM9DSO chip (the real wizardry) and that there are a variety of differently board shapes available. My application has space, so although the circular board isn't ideal, I can use this version. Great news.

Ok, I'm off to tackle the wiring and coding challenges.
Thanks again!

BVarv
 
Posts: 9
Joined: Fri May 19, 2017 11:37 pm

Re: Self leveling platform. Need tilt angle feedback

by BVarv on Sat May 20, 2017 7:47 pm

I did not find documentation showing how to wire the Flora LSM9DS0. However, this documentation (https://learn.adafruit.com/adafruit-9-d ... ting-it-up) motivated me to connect as follows:

Flora to Arduino
SCL to A4
SDA to A5
3V to 3.3V
GND to GND

I added libraries, opened the LSM9DOFtest example, compiled it, uploaded it and then opened the serial monitor. I received a short garbled message after a few seconds:

The garbled data tells me I'm close, but clearly have more to learn. I'll continue reading, but in the meantime, any insights related to the following questions would be much appreciated.

1. How is the Flora LSM9DSO breakout board supposed to be wired?
2. Why are there 2 sets of SCL and SDA connections? One for XYZ, one for accelerometer info?
3. The end goal is to have the Arduino read the LSM9DSO in order to drive a servo that maintains a level platform. Any tips/tricks?

Thanks in advance for any help.

Arduino version 1.6.5
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LSM9DS0.h>
#include <Adafruit_Sensor.h>  // not used in this demo but required!

// i2c
Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0();

// You can also use software SPI
//Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(13, 12, 11, 10, 9);
// Or hardware SPI! In this case, only CS pins are passed in
//Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(10, 9);

void setupSensor()
{
  // 1.) Set the accelerometer range
  lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G);
  //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_4G);
  //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_6G);
  //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_8G);
  //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_16G);
 
  // 2.) Set the magnetometer sensitivity
  lsm.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS);
  //lsm.setupMag(lsm.LSM9DS0_MAGGAIN_4GAUSS);
  //lsm.setupMag(lsm.LSM9DS0_MAGGAIN_8GAUSS);
  //lsm.setupMag(lsm.LSM9DS0_MAGGAIN_12GAUSS);

  // 3.) Setup the gyroscope
  lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_245DPS);
  //lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_500DPS);
  //lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_2000DPS);
}

void setup()
{
#ifndef ESP8266
  while (!Serial);     // will pause Zero, Leonardo, etc until serial console opens
#endif
  Serial.begin(9600);
  Serial.println("LSM raw read demo");
 
  // Try to initialise and warn if we couldn't detect the chip
  if (!lsm.begin())
  {
    Serial.println("Oops ... unable to initialize the LSM9DS0. Check your wiring!");
    while (1);
  }
  Serial.println("Found LSM9DS0 9DOF");
  Serial.println("");
  Serial.println("");
}

void loop()
{
  lsm.read();

  Serial.print("Accel X: "); Serial.print((int)lsm.accelData.x); Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.accelData.y);       Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.accelData.z);     Serial.print(" ");
  Serial.print("Mag X: "); Serial.print((int)lsm.magData.x);     Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.magData.y);         Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.magData.z);       Serial.print(" ");
  Serial.print("Gyro X: "); Serial.print((int)lsm.gyroData.x);   Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.gyroData.y);        Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.gyroData.z);      Serial.println(" ");
  Serial.print("Temp: "); Serial.print((int)lsm.temperature);    Serial.println(" ");
  delay(200);
}
Attachments
Serial monitor LSM9OFtest.png
Serial monitor LSM9OFtest.png (75.67 KiB) Viewed 282 times
IMG_1012.JPG
IMG_1012.JPG (159.3 KiB) Viewed 282 times

BVarv
 
Posts: 9
Joined: Fri May 19, 2017 11:37 pm

Re: Self leveling platform. Need tilt angle feedback

by franklin97355 on Sat May 20, 2017 9:27 pm

You are not getting proper output to the serial monitor. If you disconnect the LSM9DS0 do you get correct output characters? If not you need to run an example program that just prints to the serial port and get that working first.

franklin97355
 
Posts: 16865
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Self leveling platform. Need tilt angle feedback

by BVarv on Sun May 21, 2017 1:59 am

Thank you franklin97355.

I added Serial.begin(9600) and Serial.println("Hello world") to the blink example. The serial terminal showed the same garbage data as when connected to the LSM9DSO. Twenty or so seconds later, the serial terminal starts saying "Hello world, hello world, ..." Something changed, so I reconnect the LSM9DSO and run the test example and sure enough the serial terminal shows real data. I do not understand what just happened, but I'm on to the next step.

It would be fascinating if what just happened could be explained by someone who understands.

On to the challenge of using the tilt angle to drive corrective servo motion.
Attachments
serial terminal working.png
serial terminal working.png (62.79 KiB) Viewed 260 times

BVarv
 
Posts: 9
Joined: Fri May 19, 2017 11:37 pm

Re: Self leveling platform. Need tilt angle feedback

by BVarv on Sun May 21, 2017 4:42 pm

I'm linking the Flora sensor data to servo motion when suddenly the Arduino freezes in the uploading process.
"WARNING: Spurious .github folder in 'Adafruit LSM9DS0 Library' library"

I restart and try to upload a blank sketch. Same result.

I found this conversation which seems relevant, but doesn't solve the issue. https://github.com/adafruit/Adafruit_BM ... /issues/21

Any ideas?

Thanks for the help!
Attachments
error message Spurious adafruit file.jpg
error message Spurious adafruit file.jpg (51.71 KiB) Viewed 234 times

BVarv
 
Posts: 9
Joined: Fri May 19, 2017 11:37 pm

Re: Self leveling platform. Need tilt angle feedback

by adafruit_support_bill on Sun May 21, 2017 4:47 pm

That is not a fatal error - just a warning. That warning does not prevent the compile or upload from completing. You can safely ignore it.

adafruit_support_bill
 
Posts: 62964
Joined: Sat Feb 07, 2009 10:11 am

Re: Self leveling platform. Need tilt angle feedback

by BVarv on Sun May 21, 2017 5:59 pm

Thank you. Good to know.

Something else killed the ability to upload. After a few more full resets, and lunch, the upload process went back to normal.

I'm not sure what happened, but you are right, the warning was not the culprit.

BVarv
 
Posts: 9
Joined: Fri May 19, 2017 11:37 pm

Re: Self leveling platform. Need tilt angle feedback

by BVarv on Tue May 23, 2017 10:36 pm

I'm struggling to connect real world motions to the data received from the Flora LSM9DS0.
As a simple test, I am tracking data as I do various things. Here are results from the com port as I run the lsm9doftest example sketch: (I excluded temp data)

sensor resting level and stationary
Accel X: -24539 Y: -24539 Z: 24539
Mag X: -6827 Y: 3945 Z: 9145
Gyro X: -1396 Y: 11 Z: -1360

Introduce a magnet to the situation
Accel X: -24539 Y: -24539 Z: 24539
Mag X: -32768 Y: 6704 Z: 24696
Gyro X: -1507 Y: 18 Z: -1381

shake the sensor gently, without tilting it
Accel X: -24539 Y: -24539 Z: 24539
Mag X: -7413 Y: 4026 Z: 8979
Gyro X: -1708 Y: 104 Z: -455
I'm assuming the acceleration data is frozen because I am not connected to the SCL/SDA pins on both sides of the sensor

sensor resting at 30 degrees tilt about the y-axis (as printed on the sensor PCB)
Accel X: -24539 Y: -24539 Z: 24539
Mag X: -4625 Y: 4223 Z: 9051 <--- marked change in Mag x
Gyro X: -1543 Y: 64 Z: -1459 <--- not much change

Interestingly, as I move the sensor to the 30 degree tilt position, this is what I see:
Accel X: -24539 Y: -24539 Z: 24539
Mag X: -2940 Y: 4374 Z: 8024
Gyro X: -2439 Y: 2062 Z: -1525 <-- huge change

is the gyro data telling me information about the rate at which the tilt is occurring? it seems this way.
Magnetic data about the X axis seems promising, but my system has motors/magnets/flowing current all over the place.

Does anybody know how I could use this Flora LSM9DSO to indicate tilt angle while working around magnets?

Open to all ideas, getting discouraged.
Thanks!

BVarv
 
Posts: 9
Joined: Fri May 19, 2017 11:37 pm

Re: Self leveling platform. Need tilt angle feedback

by adafruit_support_bill on Wed May 24, 2017 6:06 am

Introduce a magnet to the situation
Accel X: -24539 Y: -24539 Z: 24539
Mag X: -32768 Y: 6704 Z: 24696
Gyro X: -1507 Y: 18 Z: -1381

Be careful with strong magnets around magnetometers. It is possible to magnetize the magnetometer itself which will distort all your readings - even after the magnet is removed. Using magnetometers in and around electro-mechanical systems such as a robot can be a problem. In general, you want to mount the device as far as possible from motors and high-current wiring. It is also good to keep it away from any large masses of magnetically permeable materials such as iron & steel.

shake the sensor gently, without tilting it
Accel X: -24539 Y: -24539 Z: 24539
Mag X: -7413 Y: 4026 Z: 8979
Gyro X: -1708 Y: 104 Z: -455
I'm assuming the acceleration data is frozen because I am not connected to the SCL/SDA pins on both sides of the sensor

The accelerometer uses the same SDA/SCL connections. It appears that yours is not working properly.

sensor resting at 30 degrees tilt about the y-axis (as printed on the sensor PCB)
Accel X: -24539 Y: -24539 Z: 24539
Mag X: -4625 Y: 4223 Z: 9051 <--- marked change in Mag x
Gyro X: -1543 Y: 64 Z: -1459 <--- not much change

Interestingly, as I move the sensor to the 30 degree tilt position, this is what I see:
Accel X: -24539 Y: -24539 Z: 24539
Mag X: -2940 Y: 4374 Z: 8024
Gyro X: -2439 Y: 2062 Z: -1525 <-- huge change

A gyro reports rate of rotation. So at rest, it should report near-zero readings on all axis.

The output of your sensor does not look right. Both accelerometer and gyro data do not appear to be normal. We can try replacing it. Please contact support@adafruit.com with a link to this thread.

adafruit_support_bill
 
Posts: 62964
Joined: Sat Feb 07, 2009 10:11 am

Re: Self leveling platform. Need tilt angle feedback

by BVarv on Sat May 27, 2017 4:03 am

Thank you Bill. When robots take over, I'll be throwing magnets at them.

I was able to get what I needed by using the Mag X data. I'm definitely vulnerable to magnetic interference, but it hasn't been a problem so far in my testing.

In this video, you see the platform-servo reacting to me manually tilting the Flora LSM9DS0 sensor.
https://youtu.be/c6_KA-Zk5RQ

Thank you for the support.
-Ben.

BVarv
 
Posts: 9
Joined: Fri May 19, 2017 11:37 pm

Re: Self leveling platform. Need tilt angle feedback

by adafruit_support_bill on Sat May 27, 2017 6:16 am

Looks good! Thanks for the video.

adafruit_support_bill
 
Posts: 62964
Joined: Sat Feb 07, 2009 10:11 am

Re: Self leveling platform. Need tilt angle feedback

by BVarv on Sun May 28, 2017 3:58 pm

No problem!
I'm not sure how to give credit where credit is due... so I added "Special thanks to the adafruit support forum" in step 10, linking to this thread.
https://www.instructables.com/id/Pool-Playing-Robot/

Contest winners announced on Tuesday. Thanks again!

BVarv
 
Posts: 9
Joined: Fri May 19, 2017 11:37 pm

Please be positive and constructive with your questions and comments.