Page 1 of 1

getVoltage() gets "stuck" and returns same value over and over

Posted: Fri May 10, 2024 9:00 am
by extremerotary
Stanley,
I am using the OBD2UARTv1. My code detects when it can no longer communicate with the vehicle and then puts the ELM/STM chip to sleep using the built in lowpowermode function. Once that completes, I then leavelowpowermode and request the voltage using obd.getVoltage(). Then repeat the loop. When using debug mode to determine the issue, I've found that after some period of iterations and loops, the getVoltage function begins to just return the same value over and over with no change despite the vehicle being started and the voltage increasing. If I simply unplug the OBD2UART from the vehicle and reconnect it, it then reads the voltage correctly and functions as expected. I would consider this issue to be a bug in the STM/ELM firmware. Can anyone confirm? Code to replicate:

Code: Select all


void setup() {
  
  // Set up Serial Monitor
  Serial.begin(115200);

  for (;;) {
    byte version = obd.begin();
    Serial.print("Freematics OBD-II Adapter ");
    if (version > 0) {
      char buf[64];
      obd.sendCommand("ATM0\r", buf, sizeof(buf));  // added this command in hopes it would stop "remembering" the voltage; didn't work
      Serial.println("detected");
      Serial.print("OBD firmware version ");
      Serial.print(version / 10);
      Serial.print('.');
      Serial.println(version % 10);
      break;
    } else {
      Serial.println("not detected");
    }
  }

  float voltage;
  voltage = obd.getVoltage();
  Serial.print("voltage at DLC is: ");
  Serial.println(voltage);
if (voltage >=13) {
  obd.loadPidMap()
  // run other proprietary functions here when vehicle is deemed to be running and voltage is above 13V.
} else {
  status = 5; // start loop of checking for the voltage
}
}

void loop() {
if (status == 5) {
      obd.enterLowPowerMode();
      delay(20000); //let the battery voltage level off for 20ish seconds
      status=7;
  } 
  else if (status == 7) {
    Serial.println("status 7");
    float voltage;
    int value;
    obd.leaveLowPowerMode();
    voltage = obd.getVoltage();
    Serial.print("obd adaptor reading voltage: ");
    Serial.println(voltage);  // this is where, after a few minutes or so, the voltage will never change even if you start the vehicle
    if (voltage >=13) {
          wakeUp(0);
        } else {
          obd.enterLowPowerMode();
    }
  }
  }


Re: getVoltage() gets "stuck" and returns same value over and over

Posted: Tue May 21, 2024 10:17 am
by stanley
No operation including reading voltage can be done in low power mode.

Re: getVoltage() gets "stuck" and returns same value over and over

Posted: Fri Aug 23, 2024 6:46 pm
by minionrush
This is such a great resource that you are providing and you give it away for free. I love seeing blogs that understand the value of providing a quality resource for free. happy wheels