Unit testing and development for 9DOF sparkfun sensor stick

Dependencies:   ADXL345 HMC5883L ITG3200 mbed

Committer:
tylerjw
Date:
Thu Nov 01 18:46:58 2012 +0000
Revision:
2:d7e66940541d
Parent:
1:dc730a26cdc2
Child:
3:5e21a352e236
ADXL345 unit test initial commit, built in self test (not tested)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tylerjw 0:ac2f55940442 1 /**
tylerjw 2:d7e66940541d 2 9-dof unit testing
tylerjw 0:ac2f55940442 3
tylerjw 0:ac2f55940442 4 The purpose of this program is to demonstrate and calibrate the three
tylerjw 0:ac2f55940442 5 sensors on teh 9-doft board.
tylerjw 0:ac2f55940442 6
tylerjw 0:ac2f55940442 7 The first version of this software will test the ITG3200 gyro to find
tylerjw 0:ac2f55940442 8 the temperature drift line. Data will be logged to help determine the
tylerjw 0:ac2f55940442 9 thermal drift line.
tylerjw 0:ac2f55940442 10 See: http://mbed.org/users/gltest26/code/ITG3200/wiki/Thermal-Drift
tylerjw 1:dc730a26cdc2 11
tylerjw 1:dc730a26cdc2 12 The second versoin of this will test the HMC5883L 3 axis magnometer
tylerjw 2:d7e66940541d 13
tylerjw 2:d7e66940541d 14 The thrid version tests the ADXL345 library.
tylerjw 0:ac2f55940442 15 */
tylerjw 0:ac2f55940442 16
tylerjw 0:ac2f55940442 17 #include "mbed.h"
tylerjw 1:dc730a26cdc2 18 //#include "ITG3200.h"
tylerjw 2:d7e66940541d 19 //#include "HMC5883L.h"
tylerjw 1:dc730a26cdc2 20
tylerjw 2:d7e66940541d 21 I2C i2c_bus(p28, p27);
tylerjw 0:ac2f55940442 22
tylerjw 0:ac2f55940442 23 int main()
tylerjw 0:ac2f55940442 24 {
tylerjw 2:d7e66940541d 25
tylerjw 2:d7e66940541d 26 }
tylerjw 2:d7e66940541d 27
tylerjw 2:d7e66940541d 28 /*
tylerjw 2:d7e66940541d 29 void hmc5883l_test()
tylerjw 2:d7e66940541d 30 {
tylerjw 1:dc730a26cdc2 31 Serial pc(USBTX, USBRX);
tylerjw 2:d7e66940541d 32
tylerjw 1:dc730a26cdc2 33 pc.baud(9600);
tylerjw 1:dc730a26cdc2 34
tylerjw 2:d7e66940541d 35 HMC5883L compass(i2c_bus);
tylerjw 2:d7e66940541d 36
tylerjw 1:dc730a26cdc2 37 int data[3];
tylerjw 2:d7e66940541d 38
tylerjw 2:d7e66940541d 39 while(1) {
tylerjw 2:d7e66940541d 40 compass.getXYZ(data);
tylerjw 2:d7e66940541d 41 pc.printf("x: %4d, y: %4d, z: %4d\r\n", data[0], data[1], data[2]);
tylerjw 1:dc730a26cdc2 42 wait(0.067);
tylerjw 1:dc730a26cdc2 43 }
tylerjw 1:dc730a26cdc2 44 }
tylerjw 2:d7e66940541d 45 */
tylerjw 1:dc730a26cdc2 46 /*
tylerjw 1:dc730a26cdc2 47 void itg3200_test()
tylerjw 1:dc730a26cdc2 48 {
tylerjw 1:dc730a26cdc2 49 DigitalOut myled(LED1);
tylerjw 0:ac2f55940442 50 LocalFileSystem local("local"); // Create the local filesystem under the name "local"
tylerjw 0:ac2f55940442 51 ITG3200 gyro(p28, p27); // sda, scl - gyro
tylerjw 1:dc730a26cdc2 52 const float offset[3] = {99.5, -45.0, -29.7}; // taken from itg3200.xls curve fit test
tylerjw 1:dc730a26cdc2 53 const float slope[3] = {-1.05, 0.95, 0.47};
tylerjw 1:dc730a26cdc2 54
tylerjw 1:dc730a26cdc2 55 gyro.setCalibrationCurve(offset, slope);
tylerjw 1:dc730a26cdc2 56 gyro.setLpBandwidth(LPFBW_5HZ); // lowest rate low-pass filter
tylerjw 1:dc730a26cdc2 57
tylerjw 0:ac2f55940442 58 Serial pc(USBTX, USBRX);
tylerjw 0:ac2f55940442 59
tylerjw 0:ac2f55940442 60 pc.baud(9600);
tylerjw 0:ac2f55940442 61
tylerjw 0:ac2f55940442 62 myled = 0;
tylerjw 0:ac2f55940442 63 FILE *fp = fopen("/local/itg3200.csv", "w"); // Open "itg3200.csv" for writing
tylerjw 0:ac2f55940442 64 fputs("Temp, X, Y, Z\r\n", fp); // place the header at the top
tylerjw 0:ac2f55940442 65
tylerjw 0:ac2f55940442 66 float temperature = 0.0;
tylerjw 0:ac2f55940442 67 int gyro_readings[3];
tylerjw 0:ac2f55940442 68
tylerjw 0:ac2f55940442 69 for(int i = 0; i < 120; i++) { // 120 seconds - 600 samples
tylerjw 0:ac2f55940442 70 myled = 1;
tylerjw 1:dc730a26cdc2 71 //gyro.calibrate(1.0);
tylerjw 1:dc730a26cdc2 72 wait(0.5);
tylerjw 0:ac2f55940442 73 myled = 0;
tylerjw 1:dc730a26cdc2 74 gyro.getGyroXYZ(gyro_readings, ITG3200::Calibration);
tylerjw 1:dc730a26cdc2 75 //gyro.getOffset(gyro_readings);
tylerjw 0:ac2f55940442 76 temperature = gyro.getTemperature();
tylerjw 0:ac2f55940442 77 pc.printf("%3d,%f,%d,%d,%d\r\n",i,temperature,gyro_readings[0],gyro_readings[1],gyro_readings[2]);
tylerjw 0:ac2f55940442 78 fprintf(fp, "%f,%d,%d,%d\r\n",temperature,gyro_readings[0],gyro_readings[1],gyro_readings[2]);
tylerjw 0:ac2f55940442 79 }
tylerjw 0:ac2f55940442 80 fclose(fp);
tylerjw 0:ac2f55940442 81 myled = 0;
tylerjw 0:ac2f55940442 82 }
tylerjw 1:dc730a26cdc2 83 */