I2C sensor test program, derived from testI2C program. Simple test for FXOS8700CQ, HIH6130, MAG3110, MMA8451Q, MMA8452Q, MPL3115A2, MAX44000, MAX44005, MAX44008, MAX30101 included beside simple I2C read/write from testI2C.
Dependencies: FXOS8700CQ HIH6130 IS31SE5000 MAG3110 MAX44000 MAX44005 MAX44008 MMA8451Q MMA8452Q MPL3115A2 VEML6040 VEML6075 mbed vt100 LM75B FXAS21002 MAX30101 VCNL4020 VCNL4100
Diff: MSU.cpp
- Revision:
- 0:d4bbd473a83c
- Child:
- 1:9450e20cf688
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MSU.cpp Tue Apr 26 02:38:14 2016 +0000 @@ -0,0 +1,168 @@ +#include "mbed.h" +#include "vt100.h" +#include "MSS.h" +#include "MSU.h" +#include "MMA8451Q.h" +#include "MMA8452Q.h" +#include "MAG3110.h" +#include "HIH6130.h" +#include "FXOS8700CQ.h" +#include "MAX44000.h" +#include "MAX44005.h" +#include "MAX44008.h" +#include "MPL3115A2.h" +#include "VEML6040.h" +#include "VEML6075.h" + + +extern int test_loop ; + +extern vt100 *tty ; + +i2c_sensor_type i2c_sensor[] = { + {MSU_MMA8451Q_ADDRESS, "MMA8451Q", testMMA8451Q}, + {MSU_MMA8452Q_ADDRESS, "MMA8452Q", testMMA8452Q}, + {MSU_MAG3110_ADDRESS, "MAG3110", testMAG3110}, + {MSU_HIH6130_ADDRESS, "HIH6130", testHIH6130}, + {MSU_FXOS8700CQ_ADDRESS, "FXOS8700CQ", testFXOS8700CQ}, + {MSU_MAX44000_ADDRESS, "MAX44000", testMAX44000}, + {MSU_MAX44005_ADDRESS, "MAX44005", testMAX44005}, + {MSU_MAX44008_ADDRESS, "MAX44008", testMAX44008}, + {MSU_MAX30101_ADDRESS, "MAX30101", testMAX30101}, + {MSU_MPL3115A2_ADDRESS, "MPL3115A2", testMPL3115A2}, + {MSU_IS31SE5000_ADDRESS, "IS31SE5000", testIS31SE5000}, + {MSU_VEML6040A_ADDRESS, "VEML6040A", testVEML6040A}, + {MSU_VEML6075A_ADDRESS, "VEML6075A", testVEML6075A}, + {0x00, 0, 0} +} ; + +void testMMA8451Q(void) +{ + uint16_t ix, iy, iz ; + float fx, fy, fz ; + + printf("test MMA8451Q\n") ; + MMA8451Q *acc = new MMA8451Q(PIN_SDA, PIN_SCL, MSU_MMA8451Q_ADDRESS) ; + for(int i = 0 ; i < test_loop ; i++) { + ix = acc->getRawX() ; + iy = acc->getRawY() ; + iz = acc->getRawZ() ; + fx = acc->getAccX() ; + fy = acc->getAccY() ; + fz = acc->getAccZ() ; + printf("X = %d [ %.2f ], Y = %d [ %.2f ], Z = %d [ %.2f ]\n", + ix, fx, iy, fy, iz, fz ) ; + wait(0.2) ; + } + delete acc ; +} + +void testMMA8452Q(void) +{ + float x, y, z ; + printf("test MMA8452Q\n") ; + MMA8452Q *acc = new MMA8452Q(PIN_SDA, PIN_SCL, MSU_MMA8452Q_ADDRESS) ; + for(int i = 0 ; i < test_loop ; i++) { + x = acc->getAccX() ; + y = acc->getAccY() ; + z = acc->getAccZ() ; + printf("X[%.2f] Y[%.2f] Z[%.2f]\n",x, y, z) ; + wait(0.1); + } + delete acc ; +} + +void testMAG3110(void) +{ + uint8_t status = 0 ; + int16_t mX, mY, mZ ; + float fx, fy, fz ; + int x = 10 ; + int y = 5 ; + MAG3110 *mag = new MAG3110(PIN_SDA, PIN_SCL, MSU_MAG3110_ADDRESS) ; + mag->activate() ; + tty->cls() ; + printf("test MAG3110\n") ; + for (int i = 0 ; i < test_loop ; i++) { + wait(0.01) ; + status = mag->getStatus() ; + while((status & 0x80) == 0) { // wait for ZYXOW + wait(0.01) ; + status = mag->getStatus() ; + } + + tty->locate(x+5, y) ; + printf("--- MAG3110 ---") ; + tty->locate(x, y+4) ; + printf("Temperature: %02X",mag->getTemp()) ; + tty->locate(x, y+5) ; + printf("status: 0x%02X",mag->getStatus()) ; + tty->locate(x, y+6) ; + printf("ctrl reg1: 0x%02X ", mag->getCtrlReg1()) ; + printf("reg2: 0x%02X", mag->getCtrlReg2()) ; + mX = mag->getX() ; // here reset takes place! + mY = mag->getY() ; + mZ = mag->getZ() ; + fx = 10000 * (float)mX / (float)0x7FFF ; + fy = 10000 * (float)mY / (float)0x7FFF ; + fz = 10000 * (float)mZ / (float)0x7FFF ; + tty->locate(x, y+1) ; + printf("X : ") ; + if (fx >= 0) { printf(" ") ; } + printf("%.2f uT : 0x%08X ", fx, mX) ; + + tty->locate(x, y+2) ; + printf("Y : ") ; + if (fy >= 0) { printf(" ") ; } + printf("%.2f uT : 0x%08X ", fy, mY) ; + + tty->locate(x, y+3) ; + printf("Z : ") ; + if (fz >= 0) { printf(" ") ; } + printf("%.2f uT : 0x%08X ", fz, mZ) ; + } + tty->locate(0, 20) ; + mag->standby() ; + delete mag ; +} + +void testHIH6130(void) +{ + uint16_t result = 0 ; + float humidity = 0 ; + float temperature = 0 ; + HIH6130 *hih = new HIH6130(PIN_SDA, PIN_SCL, MSU_HIH6130_ADDRESS) ; + printf("test HIH6130\n") ; + for (int i = 0 ; i < test_loop ; i++) { + result = hih->getValue(&humidity, &temperature) ; + printf("Temp %.1f C Humidity %.1f %%\n", temperature, humidity) ; + wait(1) ; + } +} + +void testFXOS8700CQ(void) +{ + int16_t accData[3], mgnData[3] ; + + printf("test FXOS8700CQ\n") ; + FXOS8700CQ *fxos = new FXOS8700CQ(PIN_SDA, PIN_SCL, MSU_FXOS8700CQ_ADDRESS) ; + fxos->init() ; + + for (int i = 0 ; i < test_loop ; i++) { + fxos->readAccMgnData(accData, mgnData) ; + printf("ACC X[%d], Y[%d], Z[%d], MGN X[%d], Y[%d], Z[%d]\n", + accData[0], accData[1], accData[2], + mgnData[0], mgnData[1], mgnData[2]) ; + wait(0.2) ; + } + delete fxos ; +} + +void testMAX44000(void) {printf("test MAX44000\n") ; } +void testMAX44005(void) {printf("test MAX44005\n") ; } +void testMAX44008(void) {printf("test MAX44008\n") ; } +void testMAX30101(void) {printf("test MAX30101\n") ; } +void testMPL3115A2(void) {printf("test MPL3115A2\n") ; } +void testIS31SE5000(void) {printf("test ISI31SE5000\n") ; } +void testVEML6040A(void) {printf("test VEML6040A\n") ; } +void testVEML6075A(void) {printf("test VEML6075A\n") ; } \ No newline at end of file