Intended to include a screen indicating the battery voltage, as it has in OBDuino, but do not know how can I include this code in MPGuino, would could give me some tips to do this, what are the points that should be taken into account.
Hope I'm not asking for much.
The code seems to be the only OBDuino this.
Code:
#define BatteryVoltageSensor
#ifdef BatteryVoltageSensor
#define BatteryVoltagePin 14 // Battery voltage sensor, on analog 0
#endif
#define BATT_VOLTAGE 0xF9
"Batt Vlt", // 0xF9 Battery Voltage
#ifdef BatteryVoltageSensor
// Wiring:
// 12V ---- 30kOhm ---|--- 10kOhm ---- 0V(GND)
// |
// A0 (analog pin)
void get_batteryvoltage(char *retbuf)
{
#define VoltageDevider 1955L // (30kOhm+10kOhm) / 10kOhm * 5V / 1023 * 100000
long Voltage = analogRead(BatteryVoltagePin-14);
#ifdef DEBUGOutput
Voltage = 535;
#endif
Voltage = (Voltage * VoltageDevider) / 1000L;
char decs[16];
long_to_dec_str(Voltage, decs, 2);
sprintf_P(retbuf, PSTR("%s V"), decs);
}
#endif
#ifdef ELM
else if(pid==BATT_VOLTAGE)
elm_command(str, PSTR("ATRV\r"));
else if(pid==CAN_STATUS)
elm_command(str, PSTR("ATCS\r"));
#endif
#ifdef BatteryVoltageSensor
else if(pid==BATT_VOLTAGE)
get_batteryvoltage(str);
#endif
// Voltage sensor init
#ifdef BatteryVoltageSensor
pinMode(BatteryVoltagePin, INPUT);
#endif
Thank you
José Rodrigues