for textbook v4.4

Dependencies:   mbed HEPTA_EPS

Committer:
HeptaSatTraining2019
Date:
Tue Aug 27 04:11:33 2019 +0000
Revision:
26:8ef365eb183e
Parent:
25:2c0dd68faae0

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:bdbd3d6fc5d5 1 #include "mbed.h"
HeptaSatTraining2019 26:8ef365eb183e 2 #include "HEPTA_EPS.h"
umeume 2:1c5cdb2c3e0f 3
umeume 2:1c5cdb2c3e0f 4 Serial pc(USBTX,USBRX);
HeptaSatTraining2019 21:92c25e853b87 5 HEPTA_EPS eps(p16,p26);
HeptaSatTraining2019 25:2c0dd68faae0 6 I2C i2c(p28, p27);
umeume 2:1c5cdb2c3e0f 7
HeptaSatTraining2019 25:2c0dd68faae0 8 const int addr_accel_gyro = 0xD0;
HeptaSatTraining2019 25:2c0dd68faae0 9 char cmd[2];
HeptaSatTraining2019 25:2c0dd68faae0 10 short int gxl,gxh,gyl,gyh,gzl,gzh;
umeume 2:1c5cdb2c3e0f 11 int main()
umeume 2:1c5cdb2c3e0f 12 {
HeptaSatTraining2019 25:2c0dd68faae0 13 i2c.frequency(100000);
HeptaSatTraining2019 25:2c0dd68faae0 14 cmd[0]=0x6B;
HeptaSatTraining2019 25:2c0dd68faae0 15 cmd[1]=0x00;
HeptaSatTraining2019 25:2c0dd68faae0 16 i2c.write(addr_accel_gyro,cmd,2);
HeptaSatTraining2019 25:2c0dd68faae0 17 cmd[0] = 0x37;
HeptaSatTraining2019 25:2c0dd68faae0 18 cmd[1] = 0x02;
HeptaSatTraining2019 25:2c0dd68faae0 19 i2c.write(addr_accel_gyro,cmd,2);
HeptaSatTraining2019 25:2c0dd68faae0 20 i2c.stop();
HeptaSatTraining2019 25:2c0dd68faae0 21 while(1) {
HeptaSatTraining2019 25:2c0dd68faae0 22 i2c.start();
HeptaSatTraining2019 25:2c0dd68faae0 23 i2c.write(addr_accel_gyro);
HeptaSatTraining2019 25:2c0dd68faae0 24 i2c.write(0x43);
HeptaSatTraining2019 25:2c0dd68faae0 25 i2c.start();
HeptaSatTraining2019 25:2c0dd68faae0 26 i2c.write(addr_accel_gyro|0x01);
HeptaSatTraining2019 25:2c0dd68faae0 27 gxh = i2c.read(0);
HeptaSatTraining2019 25:2c0dd68faae0 28 i2c.stop();
HeptaSatTraining2019 25:2c0dd68faae0 29 i2c.start();
HeptaSatTraining2019 25:2c0dd68faae0 30 i2c.write(addr_accel_gyro);
HeptaSatTraining2019 25:2c0dd68faae0 31 i2c.write(0x44);
HeptaSatTraining2019 25:2c0dd68faae0 32 i2c.start();
HeptaSatTraining2019 25:2c0dd68faae0 33 i2c.write(addr_accel_gyro|0x01);
HeptaSatTraining2019 25:2c0dd68faae0 34 gxl = i2c.read(0);
HeptaSatTraining2019 25:2c0dd68faae0 35 i2c.stop();
HeptaSatTraining2019 25:2c0dd68faae0 36 double gyro_ax = short((gxh<<8) | (gxl));
HeptaSatTraining2019 25:2c0dd68faae0 37 double GX = (gyro_ax)*0.00763;
HeptaSatTraining2019 25:2c0dd68faae0 38 pc.printf("GX = %f\r\n",GX);
HeptaSatTraining2019 25:2c0dd68faae0 39 wait(0.5);
HeptaSatTraining2019 25:2c0dd68faae0 40 }
umeume 2:1c5cdb2c3e0f 41 }