Skip to content

Commit

Permalink
Fix readout offset (possibly PCB issue)
Browse files Browse the repository at this point in the history
  • Loading branch information
nekomona committed Sep 7, 2023
1 parent 4710ffe commit 43a0894
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/batterymonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void BatteryMonitor::Loop()
}
#endif
#if BATTERY_MONITOR == BAT_EXTERNAL
voltage = ((float)analogRead(PIN_BATTERY_LEVEL)) * batteryADCMultiplier;
voltage = ((float)analogRead(PIN_BATTERY_LEVEL)) * batteryADCMultiplier + batteryADCOffset;
#endif
#if BATTERY_MONITOR == BAT_MCP3021 || BATTERY_MONITOR == BAT_INTERNAL_MCP3021
if (address > 0)
Expand Down
4 changes: 4 additions & 0 deletions src/batterymonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
#define BATTERY_SHIELD_R2 220.0
#endif

#ifndef batteryADCOffset
#define batteryADCOffset 0
#endif

#if BATTERY_MONITOR == BAT_EXTERNAL
#ifndef PIN_BATTERY_LEVEL
#error Internal ADC enabled without pin! Please select a pin.
Expand Down
13 changes: 7 additions & 6 deletions src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ IMU_DESC_ENTRY(IMU_BMP160, PRIMARY_IMU_ADDRESS_ONE, IMU_ROTATION, PIN_IMU_SCL, P
#endif

// Battery monitoring options (comment to disable):
// BAT_EXTERNAL for ADC pin,
// BAT_INTERNAL for internal - can detect only low battery,
// BAT_EXTERNAL for ADC pin,
// BAT_INTERNAL for internal - can detect only low battery,
// BAT_MCP3021 for external ADC connected over I2C
#define BATTERY_MONITOR BAT_EXTERNAL

Expand All @@ -100,7 +100,7 @@ IMU_DESC_ENTRY(IMU_BMP160, PRIMARY_IMU_ADDRESS_ONE, IMU_ROTATION, PIN_IMU_SCL, P
// LED_PIN
// - Number or Symbol (D1,..) of the Output
// - To turn off the LED, set LED_PIN to LED_OFF
// LED_INVERTED
// LED_INVERTED
// - false for output 3.3V on high
// - true for pull down to GND on high

Expand All @@ -116,7 +116,7 @@ IMU_DESC_ENTRY(IMU_BMP160, PRIMARY_IMU_ADDRESS_ONE, IMU_ROTATION, PIN_IMU_SCL, P
#ifndef BATTERY_SHIELD_RESISTANCE
#define BATTERY_SHIELD_RESISTANCE 0
#endif
#ifndef BATTERY_SHIELD_R1
#ifndef BATTERY_SHIELD_R1
#define BATTERY_SHIELD_R1 10
#endif
#ifndef BATTERY_SHIELD_R2
Expand All @@ -133,7 +133,7 @@ IMU_DESC_ENTRY(IMU_BMP160, PRIMARY_IMU_ADDRESS_ONE, IMU_ROTATION, PIN_IMU_SCL, P
#ifndef BATTERY_SHIELD_RESISTANCE
#define BATTERY_SHIELD_RESISTANCE 0
#endif
#ifndef BATTERY_SHIELD_R1
#ifndef BATTERY_SHIELD_R1
#define BATTERY_SHIELD_R1 10
#endif
#ifndef BATTERY_SHIELD_R2
Expand All @@ -150,7 +150,7 @@ IMU_DESC_ENTRY(IMU_BMP160, PRIMARY_IMU_ADDRESS_ONE, IMU_ROTATION, PIN_IMU_SCL, P
#ifndef BATTERY_SHIELD_RESISTANCE
#define BATTERY_SHIELD_RESISTANCE 180
#endif
#ifndef BATTERY_SHIELD_R1
#ifndef BATTERY_SHIELD_R1
#define BATTERY_SHIELD_R1 100
#endif
#ifndef BATTERY_SHIELD_R2
Expand Down Expand Up @@ -217,4 +217,5 @@ IMU_DESC_ENTRY(IMU_BMP160, PRIMARY_IMU_ADDRESS_ONE, IMU_ROTATION, PIN_IMU_SCL, P
#define BATTERY_SHIELD_RESISTANCE 0 //130k BatteryShield, 180k SlimeVR or fill in external resistor value in kOhm
#define BATTERY_SHIELD_R1 1000 // Board voltage divider resistor Ain to GND in kOhm
#define BATTERY_SHIELD_R2 1000 // Board voltage divider resistor Ain to INPUT_BOARD in kOhm
#define batteryADCOffset 0.5
#endif

0 comments on commit 43a0894

Please sign in to comment.