added delay before reading current sensor

pull/33/merge
alanbjohnston 6 years ago committed by GitHub
parent 88f1358a9f
commit 7337eb3bdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -91,6 +91,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) {
wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue);
wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config);
wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue);
delay(1);
int value = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT);
if (value == -1)
{
@ -104,6 +105,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) {
value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd);
data.voltage = ((float)(value >> 3) * 4) / 1000;
// power has very low resolution, seems to step in 512mW values
delay(1);
data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier;
return data;

Loading…
Cancel
Save

Powered by TurnKey Linux.