fezder
Well-Known Member
This is teensy 3.2 so perhaps wrong place?
Right, so I'm making an car computer (I know, there are pre-made and cheaper models out there) by using sparkfun's obd-uart board, teensy 3.2 and i2c 16x2 lcd. Idea is simple: Send AT commands to obd and display result (converted/calculated) on screen, while also updating. The problem currently is that even with that one Serial print,menu system doesn't update conveniently quick & doesn't update, seems it only sends one serial string data in current code. What I'd like it to do, is that it constantly updates screen, and menu could be changed.
Code I'm currently working on:
obd-uart board:
https://www.sparkfun.com/products/9555
I've managed to get couple live information as real-life data, but there are many stuff hidden in that sketch....
Ask if there is anything confusing!
Right, so I'm making an car computer (I know, there are pre-made and cheaper models out there) by using sparkfun's obd-uart board, teensy 3.2 and i2c 16x2 lcd. Idea is simple: Send AT commands to obd and display result (converted/calculated) on screen, while also updating. The problem currently is that even with that one Serial print,menu system doesn't update conveniently quick & doesn't update, seems it only sends one serial string data in current code. What I'd like it to do, is that it constantly updates screen, and menu could be changed.
Code I'm currently working on:
obd-uart board:
https://www.sparkfun.com/products/9555
I've managed to get couple live information as real-life data, but there are many stuff hidden in that sketch....
Ask if there is anything confusing!
C:
int const UpButton = 2;
int const DownButton = 3;
int UpButtonState;
int LastUpButtonState;
int DownButtonState;
int LastDownButtonState;
int counter;
char rxData[20];
char rxIndex = 0;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
String a;
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
pinMode (UpButton, INPUT);
pinMode (DownButton, INPUT);
lcd.begin();
lcd.backlight();
Serial1.begin(9600);
//ODB_init();
}
void loop()
{
menuselect();
}
void menuselect()
{
UpButtonState = digitalRead (UpButton);
if (UpButtonState != LastUpButtonState)
{
lcd.clear();
if (UpButtonState == HIGH)
{
counter++;
}
LastUpButtonState = UpButtonState;
}
if (counter > 9)
{ (counter = 1);
}
DownButtonState = digitalRead (DownButton);
if (DownButtonState != LastDownButtonState)
{
lcd.clear();
if (DownButtonState == HIGH)
{
counter--;
}
LastDownButtonState = DownButtonState;
}
if (counter == 0)
{
(counter = 9);
}
switch (counter) //switch what is displayed depending on number of counter
{
case 1: //speed
lcd.setCursor(0, 0);
lcd.print("KM/h:");
lcd.setCursor(5,0);
Serial1.print("H"); //just for testing, but even this causes momentary freeze
a = Serial1.readString(); // read the incoming data as string
lcd.print(a);
lcd.setCursor(0, 1);
lcd.print("<-Clear RPM->");
break;
case 2: //RPM
lcd.setCursor(0, 0);
lcd.print("RPM:");
lcd.setCursor(0, 1);
lcd.print("<-Speed Cool.->");
break;
case 3: //coolant
lcd.setCursor(0, 0);
lcd.print("`c");
lcd.setCursor(0, 1);
lcd.print("<-RPM Intake->");
break;
case 4:
lcd.setCursor(0, 0);
lcd.print("`c");
lcd.setCursor(0, 1); //Intake
lcd.print("<-Coolant MAF->");
break;
case 5:
lcd.setCursor(0, 0);
lcd.print("g/sec:");
lcd.setCursor(0, 1); //MAF
lcd.print("<-Intake Pedal->");
break;
case 6:
lcd.setCursor(0, 0);
lcd.print("%:");
lcd.setCursor(0, 1); //Pedal
lcd.print("<-MAF Stress->");
break;
case 7:
lcd.setCursor(0, 0);
lcd.print("%:");
lcd.setCursor(0, 1); //Stress
lcd.print("<-Pedal RunT.->");
break;
case 8:
lcd.setCursor(0, 0);
lcd.print("T:");
lcd.setCursor(0, 1); //Run Time
lcd.print("<-Stress Clear->");
break;
case 9:
lcd.setCursor(0, 0);
lcd.print("Clear codes?");
lcd.setCursor(0, 1); //clear
lcd.print("<-RunT. Speed->");
break;
}
}
/*void ODB_init(void)
{
//Wait for a little while before sending the reset command to the OBD-II-UART
delay(2000);
//Reset the OBD-II-UART
Serial1.print("ATZ\r");
//Wait for a bit before starting to send commands after the reset.
delay(2000);
OBD_read();
Serial1.print("ATE0\r");
OBD_read();
Serial1.flush();
}
void OBD_read(void)
{
char c;
do {
if (Serial1.available() > 0)
{
c = Serial1.read();
//lcd.print(c);
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
rxIndex = 0; //Set this to 0 so next time we call the read we get a "clean buffer"
}
int getSpeed(void)
{
//Query the OBD-II-UART for the Vehicle rpm
Serial1.flush();
Serial1.print("0111\r");
OBD_read();
return strtol(&rxData[6], 0, 16) * 100 / 255;
}*/