Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ADXL345_I2C INA226_120 mbed
Revision 1:497ad7f0e39b, committed 2016-01-20
- Comitter:
- YusukeWakuta
- Date:
- Wed Jan 20 13:42:30 2016 +0000
- Parent:
- 0:fe607370807b
- Commit message:
- 1?20????????
Changed in this revision
| INA226.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/INA226.lib Fri Jan 15 15:33:40 2016 +0000 +++ b/INA226.lib Wed Jan 20 13:42:30 2016 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/tosihisa/code/INA226/#8950b0f31d73 +https://developer.mbed.org/teams/albatross/code/INA226_120/#f6587f5cc2fb
--- a/main.cpp Fri Jan 15 15:33:40 2016 +0000
+++ b/main.cpp Wed Jan 20 13:42:30 2016 +0000
@@ -3,6 +3,7 @@
#include "INA226.hpp"
#define BUFFER 30
+
Serial rs485(p13,p14);
DigitalOut Receiver(p5);
ADXL345_I2C accelerometer(p9, p10);
@@ -10,48 +11,46 @@
PwmOut servo2(p22);
I2C i2c_Ina(p28,p27);
INA226 Ina226(i2c_Ina);
-
-//ADXL345 accelerometer(p5, p6, p7, p8);
-ADXL345_I2C accelerometer(p9, p10);
+
Serial pc(USBTX, USBRX);
-
+
void ADXL345(int *x)
{
- x[3] = {0, 0, 0};
-
- // pc.printf("Starting ADXL345 test...\n");
+
+ // pc.printf("Starting ADXL345 test...\n");
//pc.printf("Device ID is: 0x%02x\n", accelerometer.getDevId());
-
+
//Go into standby mode to configure the device.
accelerometer.setPowerControl(0x00);
-
+
//Full resolution, +/-16g, 4mg/LSB.
accelerometer.setDataFormatControl(0x0B);
-
+
//3.2kHz data rate.
accelerometer.setDataRate(ADXL345_3200HZ);
-
+
//Measurement mode.
accelerometer.setPowerControl(0x08);
- accelerometer.getOutput(x);
-
- //13-bit, sign extended values.
- //pc.printf("%6i, %6i, %6i\n\r", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]);
-
+ accelerometer.getOutput(x);
+
+ //13-bit, sign extended values.
+ //pc.printf("%6i, %6i, %6i\n\r", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]);
+
}
-int INA226(double *Voltage,double *Current){
- while(1){
- if(Ina226.isExist() == 0){
- Ina226.getVoltage(Voltage);
- Ina226.getCurrent(Current);
+int INA226_check(double *Voltage,double *Current)
+{
+ while(1) {
+ if(Ina226.isExist() == 0) {
+ Ina226.getVoltage(Voltage);
+ Ina226.getCurrent(Current);
}
- //pc.printf("V : %lf, C : %lf \n\r",Voltage,Current);
-
+ //pc.printf("V : %lf, C : %lf \n\r",Voltage,Current);
+
}
return 0;
- }
+}
@@ -64,40 +63,34 @@
void rs485_rx()
{
int acc[3];
+ double *Voltage = 0;
+ double *Current = 0;
signed char rec_data = rs485.getc();
switch(rec_data) {
case 'C':
servo_deg1 = rs485.getc();
- // pc.printf("counter1:%d\n\r",servo_deg1);
+ // pc.printf("counter1:%d\n\r",servo_deg1);
break;
case 'D':
servo_deg2 = rs485.getc();
//pc.printf("counter2:%d\n\r",servo_deg2);
break;
case 'P':
- INA226_check(Voltage,Current);
- ADXL345(acc);
- //counter++;
- // if(counter > 1000){
- // counter = 0;
- // }
+ INA226_check(Voltage,Current);
+ ADXL345(acc);
Receiver = 1;
wait_ms(3);
- // if(counter % 2 == 0){
- rs485.putc('X');
- // pc.printf("X");
+ rs485.putc('X');
+ pc.printf("X");
rs485.putc((signed char)acc[0]);
- //pc.printf("%5d",(signed char)acc[0]);
+ pc.printf("%5d",(signed char)acc[0]);
rs485.putc('Y');
- //pc.printf("Y");
+ pc.printf("Y");
rs485.putc((signed char)acc[1]);
- // pc.printf("%5d",(signed char)acc[1]);
+ pc.printf("%5d",(signed char)acc[1]);
rs485.putc('Z');
- //pc.printf("Z");
- rs485.putc((signed char)acc[2]);
- //}
- // else{
- // pc.printf("%5d",(signed char)acc[2]);
+ pc.printf("Z");
+ pc.printf("%5d",(signed char)acc[2]);
rs485.putc('V');
pc.printf("V");
rs485.putc((signed char)Voltage);
@@ -106,7 +99,7 @@
pc.printf("C");
rs485.putc((signed char)Current);
pc.printf("%5d\n\r",(signed char)Current);
- //}
+
//pc.printf("\n\r");
// rs485.printf("X%iY%iZ%i\n\r",(short)acc[0],(short)acc[1],(short)acc[2]);
wait_ms(15);
@@ -115,7 +108,7 @@
break;
default:
wait_us(5);
- // pc.printf("%d\n\r",rec_data);
+ // pc.printf("%d\n\r",rec_data);
}
}