Toyota GR86, 86, FR-S and Subaru BRZ Forum & Owners Community - FT86CLUB

Toyota GR86, 86, FR-S and Subaru BRZ Forum & Owners Community - FT86CLUB (https://www.ft86club.com/forums/index.php)
-   Electronics | Audio | NAV | Infotainment (https://www.ft86club.com/forums/forumdisplay.php?f=27)
-   -   New gauge project... (https://www.ft86club.com/forums/showthread.php?t=64562)

robot 08-04-2014 03:14 AM

Quote:

Originally Posted by mabviper (Post 1880771)
Anytime I have timing issues, I usually relax all timings. For CAN, the identifier ID also relates to priority. The higher the number, the lower the priority. If you're reading all values by sending out a request for each value, I suggest increasing your loop delay.

Sent from my Nexus 4 using Tapatalk

I'm sending out a request like this:

Code:

if (whichSensor.indexOf("obdbrzoiltempf") >= 0){
    Serial1.println("2101");
    getResponse2();
    Serial.println("brz oil temp");
    delay(40);
    value = ((float)strtol(&rxData[109],0,16) - 40) * 1.8 + 32;
    Serial.println(value);

Serial1 is the obd ii uart device.
Serial is just a usb serial monitor (standard arduino stuff)

There are two versions of getResponse() that I've been toying with. One of which uses peek in a nice way. I think that's the right one to work on. I need to modify it to pick up multiple lines in the return of a CAN message.

Code:

void getResponse(void){
  char obdIn=0;
  int i=0;
  int start=millis();
  //If nothing is currently available do nothing and break after 3 seconds
  while(Serial1.available()==0){if(millis()-start>3000){break;}}
  while(Serial1.available()){
    //check to see if end of line/message
    if (Serial1.peek()=='\r'){
      obdIn=Serial1.read();
      rxData[i]='\0';
      Serial.println(rxData);
      i=0;
    }
    // The prompt is sometimes the only thing recieved so this needs to be taken care of
    else if(Serial1.peek()=='>'){
      obdIn=Serial1.read();
      //Serial.write(obdIn);
    }
    // Add next character to string
    else{
      obdIn=Serial1.read();
      rxData[i++]=obdIn;
    }
  }
  Serial.print("rxData(in getResponse): ");
  Serial.println(rxData);
  rxIndex=0;
}


This is the other one:

Code:

//from:  https://forum.sparkfun.com/viewtopic.php?f=14&t=32457&start=60 and https://forum.sparkfun.com/viewtopic.php?f=14&t=38253
void getResponse2(void){
  char c;
  int start=millis();
  //If nothing is currently available do nothing and break after 3 seconds
  while(Serial1.available()==0){if(millis()-start>3000){break;}}
  do {
    if (Serial1.available() > 0)
    {
      c = Serial1.read();
      if ((c != '>') && (c != '\r') && (c != '\n')) //Keep these out of our buffer
      {
        rxData[rxIndex++] = c; //Add whatever we receive to the buffer
      }
    }
  }
  while (c != '>'); //The ELM327 ends its response with this char so when we get it we exit out.
  rxData[rxIndex++] = '\0';  //Converts the array into a string
  Serial.print("rxData(in getResponse2): ");
  Serial.println(rxData);
  rxIndex = 0; //Set this to 0 so next time we call the read we get a "clean" buffer
}

I'm sure I've screwed something fundamental up here.

I can use a basic program to send typed commands directly to the device and it seems to work, which leads me to believe that this is timing related.

At the moment after doing an ATZ and ATE0 the first display page/sensor reading is water temp and it just returns "?".

If I stick entirely to using the second getResponse (without the peek). Everything works, except the water temp...this is what really has me stumped.

robot 08-04-2014 03:35 AM

So, using the getResponse() without the peek I added a reading of water temp in my initial setup routines. It reads correctly there, but screws up in the actual display code.

I must be close to solving it, right :) .

Sleep, or code, hmmm....

robot 08-04-2014 03:53 AM

I chose sleep: https://github.com/stirobot/arduinoM...6fd00e4247274e is where i left off. Maybe fresh eyes can figure out why all normal PID's and oil temp work but the !#$!@# coolant temp won't show up.

(yet it shows up in that initial setup if I put it there FFS)


All times are GMT -4. The time now is 01:26 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
User Alert System provided by Advanced User Tagging v3.3.0 (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.


Garage vBulletin Plugins by Drive Thru Online, Inc.