![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ECE 4180 Team iBox
Fork of 4180_LSM9DS0_lab by
Revision 6:5fd5ddcdca1c, committed 2015-05-01
- Comitter:
- Ratchapong
- Date:
- Fri May 01 18:37:17 2015 +0000
- Parent:
- 5:942e184c4977
- Commit message:
- MBED3
Changed in this revision
4DGL-uLCD-SE.lib | Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/4DGL-uLCD-SE.lib Mon Feb 02 21:51:57 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/4180_1/code/4DGL-uLCD-SE/#e39a44de229a
--- a/main.cpp Mon Feb 02 21:51:57 2015 +0000 +++ b/main.cpp Fri May 01 18:37:17 2015 +0000 @@ -1,65 +1,72 @@ -// LSM9DS90/uLCD Demo -// ECE 4180 Lab Code Template - -#include "mbed.h" #include "LSM9DS0.h" -#include "uLCD_4DGL.h" - -// uncomment this line to enable the uLCD for Part 4 of the lab -//#define PART_4 - -// SDO_XM and SDO_G are pulled up, so our addresses are: +#include <sstream> #define LSM9DS0_XM_ADDR 0x1D // Would be 0x1E if SDO_XM is LOW #define LSM9DS0_G_ADDR 0x6B // Would be 0x6A if SDO_G is LOW +#include "mbed.h" -// refresh time. set to 500 for part 2 and 50 for part 4 -#define REFRESH_TIME_MS 500 +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); -// Verify that the pin assignments below match your breadboard LSM9DS0 imu(p9, p10, LSM9DS0_G_ADDR, LSM9DS0_XM_ADDR); Serial pc(USBTX, USBRX); -#ifdef PART_4 -uLCD_4DGL lcd(p28, p27, p30);X -#endif +void print_accelerometer(); +void print_compass_data(); +void print_temperature(); -//Init Serial port and LSM9DS0 chip -void setup() +int main() { -#ifdef PART_4 - lcd.baudrate(3000000); - lcd.background_color(0); - lcd.cls(); - - lcd.printf("Initializing..."); -#endif - - // Use the begin() function to initialize the LSM9DS0 library. - // You can either call it with no parameters (the easy way): uint16_t status = imu.begin(); //Make sure communication is working pc.printf("LSM9DS0 WHO_AM_I's returned: 0x%X\n", status); - pc.printf("Should be 0x49D4\n\n"); + pc.printf("------ LSM0DS0 Demo -----------\n"); + while(1) { + led1 = !led1; + print_accelerometer(); + print_compass_data(); + print_temperature(); + wait_ms(500); + } } -int main() +void print_accelerometer() +{ + imu.readAccel(); + pc.printf("A: x-axis: %d y-axis: %d z-axis: %d\n", imu.ax, imu.ay, imu.az); +} +void print_compass_data() { - setup(); //Setup sensor and Serial - pc.printf("------ LSM0DS0 Demo -----------\n"); + imu.readMag(); + float compassHeading = imu.calcHeading(); + std::string direction = ""; + if (compassHeading > 22.5 & compassHeading <= 67.5) { + direction = "NE"; + } else if (compassHeading > 67.5 & compassHeading <= 112.5) { + direction = "E"; + } else if (compassHeading > 112.5 & compassHeading <= 157.5) { + direction = "SE"; + } else if (compassHeading > 157.5 & compassHeading <= 202.5) { + direction = "S"; + } else if (compassHeading > 202.5 & compassHeading <= 247.5) { + direction = "SW"; + } else if (compassHeading > 247.5 & compassHeading <= 292.5) { + direction = "W"; + } else if (compassHeading > 292.5 & compassHeading <= 337.5) { + direction = "NW"; + } else { + direction = "N"; + } + pc.printf(direction.c_str()); + pc.printf("\n"); + pc.printf("Degree: %f\n", compassHeading); - while (true) - { - // TODO - add code here to read compass or accelerometer data - // and print it to the USB serial port (part 2) and display it on the uLCD (part 3) - - // Compass Trigonometry tip: you can retrieve the compass heading (in degrees) directly from - // the IMU library. Example: - // imu.readMag(); - // float heading = imu.calcHeading(); - // Remember that x = length*cos(heading) and y = length*sin(heading) - // to convert from degrees to radians (for sin/cos functions), multiply by pi/180 - - wait_ms(REFRESH_TIME_MS); - } + } +void print_temperature() +{ + imu.readTemp(); + pc.printf("T: %f C\n", imu.temperature_c); +}