
ECE 4180 Team iBox
Fork of 4180_LSM9DS0_lab by
main.cpp@0:29ab304ca8ce, 2015-01-26 (annotated)
- Committer:
- aswild
- Date:
- Mon Jan 26 01:43:00 2015 +0000
- Revision:
- 0:29ab304ca8ce
- Child:
- 1:ae1cefe9aa38
Initial Publish
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aswild | 0:29ab304ca8ce | 1 | // LSM9DS90/uLCD Demo |
aswild | 0:29ab304ca8ce | 2 | // ECE 4180 Lab Code Template |
aswild | 0:29ab304ca8ce | 3 | |
aswild | 0:29ab304ca8ce | 4 | #include "mbed.h" |
aswild | 0:29ab304ca8ce | 5 | #include "LSM9DS0.h" |
aswild | 0:29ab304ca8ce | 6 | #include "uLCD_4DGL.h" |
aswild | 0:29ab304ca8ce | 7 | |
aswild | 0:29ab304ca8ce | 8 | // SDO_XM and SDO_G are pulled up, so our addresses are: |
aswild | 0:29ab304ca8ce | 9 | #define LSM9DS0_XM_ADDR 0x1D // Would be 0x1E if SDO_XM is LOW |
aswild | 0:29ab304ca8ce | 10 | #define LSM9DS0_G_ADDR 0x6B // Would be 0x6A if SDO_G is LOW |
aswild | 0:29ab304ca8ce | 11 | |
aswild | 0:29ab304ca8ce | 12 | #define REFRESH_TIME_MS 50 |
aswild | 0:29ab304ca8ce | 13 | |
aswild | 0:29ab304ca8ce | 14 | // Verify that the pin assignments below match your breadboard |
aswild | 0:29ab304ca8ce | 15 | LSM9DS0 imu(p9, p10, LSM9DS0_G_ADDR, LSM9DS0_XM_ADDR); |
aswild | 0:29ab304ca8ce | 16 | uLCD_4DGL lcd(p28, p27, p30); |
aswild | 0:29ab304ca8ce | 17 | Serial pc(USBTX, USBRX); // tx, rx |
aswild | 0:29ab304ca8ce | 18 | |
aswild | 0:29ab304ca8ce | 19 | //Init Serial port and LSM9DS0 chip |
aswild | 0:29ab304ca8ce | 20 | void setup() |
aswild | 0:29ab304ca8ce | 21 | { |
aswild | 0:29ab304ca8ce | 22 | lcd.baudrate(3000000); |
aswild | 0:29ab304ca8ce | 23 | lcd.background_color(0); |
aswild | 0:29ab304ca8ce | 24 | lcd.cls(); |
aswild | 0:29ab304ca8ce | 25 | |
aswild | 0:29ab304ca8ce | 26 | lcd.printf("Initializing..."); |
aswild | 0:29ab304ca8ce | 27 | // Use the begin() function to initialize the LSM9DS0 library. |
aswild | 0:29ab304ca8ce | 28 | // You can either call it with no parameters (the easy way): |
aswild | 0:29ab304ca8ce | 29 | uint16_t status = imu.begin(); |
aswild | 0:29ab304ca8ce | 30 | |
aswild | 0:29ab304ca8ce | 31 | //Make sure communication is working |
aswild | 0:29ab304ca8ce | 32 | pc.printf("LSM9DS0 WHO_AM_I's returned: 0x%X\n", status); |
aswild | 0:29ab304ca8ce | 33 | pc.printf("Should be 0x49D4\n\n"); |
aswild | 0:29ab304ca8ce | 34 | } |
aswild | 0:29ab304ca8ce | 35 | |
aswild | 0:29ab304ca8ce | 36 | int main() |
aswild | 0:29ab304ca8ce | 37 | { |
aswild | 0:29ab304ca8ce | 38 | setup(); //Setup sensor and Serial |
aswild | 0:29ab304ca8ce | 39 | pc.printf("------ LSM0DS0 Demo -----------\n"); |
aswild | 0:29ab304ca8ce | 40 | |
aswild | 0:29ab304ca8ce | 41 | while (true) |
aswild | 0:29ab304ca8ce | 42 | { |
aswild | 0:29ab304ca8ce | 43 | // TODO - add code here to read compass or accelerometer data |
aswild | 0:29ab304ca8ce | 44 | // and display it on the uLCD |
aswild | 0:29ab304ca8ce | 45 | |
aswild | 0:29ab304ca8ce | 46 | // Compass Trigonometry tip: you can retrieve the compass heading (in degrees) directly from |
aswild | 0:29ab304ca8ce | 47 | // the IMU library. Example: |
aswild | 0:29ab304ca8ce | 48 | // imu.readMag(); |
aswild | 0:29ab304ca8ce | 49 | // float heading = imu.calcHeading(); |
aswild | 0:29ab304ca8ce | 50 | // Remember that x = length*cos(heading) and y = length*sin(heading) |
aswild | 0:29ab304ca8ce | 51 | // to convert from degrees to radians (for sin/cos functions), multiply by pi/180 |
aswild | 0:29ab304ca8ce | 52 | |
aswild | 0:29ab304ca8ce | 53 | wait_ms(REFRESH_TIME_MS); |
aswild | 0:29ab304ca8ce | 54 | } |
aswild | 0:29ab304ca8ce | 55 | } |