Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Quick-and-dirty IMU Sensor Graphing

View ascii_graph
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
/*
* Here is a sketch that "graphs" the accelerometer and gyroscope data coming from
* the Pololu L3G and LSM303 libraries--by rapidly outputting graphically-arranged
* strings to the Arduino serial monitor. It's much easier than strings of numbers
* to look at and tell whether your sensors are working properly.
*/
 
#include <Wire.h>
#include <String.h>
#include <L3G.h>
#include <LSM303.h>
 
LSM303 compass;
L3G gyro;
 
void setup() {
Serial.begin(115200);
Wire.begin();
if (!gyro.init())
{
Serial.println("Failed to autodetect gyro type!");
while (1);
}
if (!compass.init())
{
Serial.println("Failed to initialize compass!");
while (1);
}
gyro.enableDefault();
compass.enableDefault();
}
 
void loop() {
static int barcounter = 0;
String spacestring = " ";
String barstring = "----------------------------------------------------------------";
String outstring;
 
barcounter++;
if(barcounter==10){
barcounter=0;
outstring=barstring;
outstring += millis()/100;
}
else outstring=spacestring;
 
gyro.read();
compass.read();
 
//gyro axes are drawn with thin lines, accelerometer are drawn with thick lines
outstring.setCharAt(11+((int)gyro.g.x)/3277, ':');
outstring.setCharAt(11+((int)compass.a.x)/3277, 'X');
outstring.setCharAt(32+((int)gyro.g.y)/3277, ':');
outstring.setCharAt(32+((int)compass.a.y)/3277, 'X');
outstring.setCharAt(53+((int)gyro.g.z)/3277, ':');
outstring.setCharAt(53+((int)compass.a.z)/3277, 'X');
Serial.println(outstring);
 
delay(20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.