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

Discussion about software developed by Freematics, including Freematics Builder and Freematics Emulator GUI
Post Reply
extremerotary
Posts: 5
Joined: Tue Dec 19, 2023 2:55 am

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

Post 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();
    }
  }
  }

stanley
Site Admin
Posts: 1039
Joined: Sat Mar 01, 2014 3:15 am

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

Post by stanley »

No operation including reading voltage can be done in low power mode.
minionrush
Posts: 2
Joined: Fri Aug 23, 2024 6:45 pm

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

Post 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
ColeHarry
Posts: 1
Joined: Tue Nov 12, 2024 2:53 pm

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

Post by ColeHarry »

It sounds like the issue you're experiencing with the getVoltage() function could be related to the STM/ELM firmware. Have you tried reaching out to the manufacturer or checking for any firmware updates that may address this issue?
Post Reply