CruizCore XG1300L IMU for LEGO Mindstorms NXT

The Instrumentation

The XG1300L contains a single axis gyroscope and a three-axis accelerometer. The directions of these axes may be seen in the picture below.

/media/uploads/mjenkins11/12100200.jpg

Connecting via NXT

Lego NXT is a proprietary method of consolidating an analog I/O and an I2C bus into a single 6 connector cable. This allows the same cable to be utilized for many different sensors. In order to make connecting to the LG1300L sensor easier, we used a breakout module to attach an NXT cable to the breadboard. The pinout for this breakout board may be seen below.

/media/uploads/mjenkins11/_scaled_breadboard-adapter---sensor.gif.png

Information

NXT connectors use a heavily modified RJ-12 connector. If acquiring NXT cables is not convenient for you(or you just don't want to spend the money on them), a tutorial explaining how you can synthesize your own NXT cables from classic RJ-12 phone jacks can be found here

Noting that all NXT sensors are 5V tolerant, the mbed should be connected to the adapter using the following convention:

MBEDNXT
--Analog
GNDGND
GNDGND
4.3VVU(5V)
SCLP27
SDAP28

Below is a schematic giving a full layout of all of the connections between the mbed and the NXT breakout board. /media/uploads/mjenkins11/nxt_schematic_1.png

PLEASE NOTE!

Because the NXT interface is a standard I2C bus, both SDA and SDL must be connected to pull-up resistors in order to function properly. Failure to do so will create unpredictable (and unintelligible) readings from the sensor.

Library API

Import library

Public Member Functions

LG1300L (I2C &i2c, int ACC_SETTING)
Create an IMU readout interface.
float GetAngle ()
Returns a float containing the current Accumulated Angle.
float GetROT ()
Returns a float containing the current ROT.
float GetACC_X ()
Returns a float containing the current acceleration on the X axis.
float GetACC_Y ()
Returns a float containing the current acceleration on the Y axis.
float GetACC_Z ()
Returns a float containing the current acceleration on the Z axis.

Implementation

Import programLG1300L_Hello_World

Hello Word for the LG1300L IMU

LG1300L _Hello_World.cpp

#include "mbed.h"
#include "LG1300L.h"

Serial pc(USBTX, USBRX); // tx, rx

I2C i2c(p28,p27);
DigitalOut LED (LED1);

int main() {
    LG1300L IMU(i2c, 2);

    while(1) {
        float angle = IMU.GetAngle();
        float ROT= IMU.GetROT();
        float X_ACC = IMU.GetACC_X();
        float Y_ACC = IMU. GetACC_Y();
        float Z_ACC = IMU. GetACC_Z();
        pc.printf("///////////////////////////////////\n");
        pc.printf("//ANGLE: %f\n", angle);
        pc.printf("//ROT: %f\n", ROT);
        pc.printf("//X-Axis: %f\n", X_ACC );
        pc.printf("//Y-Axis: %f\n", Y_ACC );
        pc.printf("//Z-axis: %f\n", Z_ACC );
        pc.printf("///////////////////////////////////\n");
        wait(1);
    }
}
    

Demos

The LG1300L_Hello_World_LCD program outputs the IMU sensor reading to the LCD display. The LCD displays both the gyroscope and the accelerometer readings. Clockwise rotation results in a positive angle from 0 to 180 degrees. Counter-clockwise rotation results in a negative angle from 0 to -179.99. Acceleration around the X-axis is displayed in Gs.

Import programLG1300L_Hello_World_LCD

Demo Program

LG1300L_Hello_World_LCD

#include "mbed.h"
#include "TextLCD.h"
#include "LG1300L.h"

TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7

I2C i2c(p28,p27);

int main() {
    LG1300L IMU(i2c, 2);

    while(1) {
        float angle = IMU.GetAngle();
        float X_ACC = IMU.GetACC_X();
        pc.printf("//ANGLE: %f\n", angle);
        pc.printf("//X-Axis: %f\n", X_ACC );

        wait(1);
    }
}
    

This video demonstrates the functionality of the LG1300L Hello World program.


Please log in to post comments.