Comments (8)
from elmduino.
@PowerBroker2 @DerKleinePunk THX!
According to the sample code, It is supposed to use the switch case. I modified the code template as follows:
int switchNum = 1;
uint32_t rpm = 0;
......
uint32_t coolant = 0;
//_____________________________________________________________
void updateRpm(uint32_t rpm, bool error) {
canvas.fillScreen(BLACK);
gfx.setFont(u8g2_font_wqy15_t_gb2312b);
gfx.setForegroundColor(LIME);
gfx.setCursor(2, 14); gfx.println(F("发动机转速 rpm"));
gfx.setFont(dsdigital_42);
gfx.setForegroundColor(WHITE);
gfx.setCursor(0, 62);
if (error) {
gfx.println(F("-"));
} else {
gfx.println(rpm);
}
//show_canvas_on_screen();
}
......
void updateCoolant(uint32_t coolant, bool error) {
//canvas.fillScreen(BLACK);
gfx.setFont(u8g2_font_wqy15_t_gb2312b);
gfx.setForegroundColor(LIME);
gfx.setCursor(2, 80); gfx.println(F("冷却液温度 °C"));
gfx.setForegroundColor(WHITE);
gfx.setFont(dsdigital_47);
gfx.setCursor(0, 128);
if (error) {
gfx.println(F("-"));
} else {
gfx.println(coolant);
}
show_canvas_on_screen();
}
//_____________________________________________________________
void loop() {
switch (switchNum) {
case 1: {
float tempRPM = myELM327.rpm();
if (myELM327.nb_rx_state == ELM_SUCCESS) {
rpm = (uint32_t)tempRPM;
updateRpm(rpm, false);
switchNum == 2;
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG) {
updateRpm(0, true);
switchNum == 2;
}
break;
}
......
case n: {
float tempCoolant = myELM327.engineCoolantTemp();
if (myELM327.nb_rx_state == ELM_SUCCESS) {
coolant = (uint32_t)tempCoolant;
updateCoolant(coolant, false);
switchNum == 1;
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG) {
updateCoolant(0, true);
switchNum == 1;
}
break;
}
}
}
Now I can get the PIDs value.
However, there is a delay in displaying multiple PID queries, and the more PID queries there are, the greater the delay in displaying them, whereas ELMduino v2.6.4 has no delay at all.
Overall this delay seems acceptable though, so if there's nothing better to do, that's it. Thanks again guys!
from elmduino.
@wcjxixi I think it is the display.clearDisplay(); Because non Blocking from new Lib version.
void UpdateDisplay(uint32_t rpm, bool error)
{
display.clearDisplay();
display.fillRect(0, 0, 128, 32, WHITE);
u8g2.setForegroundColor(BLACK);
u8g2.setFont(u8g2_font_wqy16_t_gb2312a);
u8g2.setFontMode(1);
u8g2.setCursor(5, 22);
u8g2.print("RPM: ");
u8g2.setBackgroundColor(WHITE);
u8g2.setFont(u8g2_font_freedoomr25_mn);
u8g2.setCursor(50, 30);
if(error) {
u8g2.print("-");
} else {
u8g2.print(rpm);
}
display.display();
}
void loop() {
float tempRPM = myELM327.rpm();
if (myELM327.nb_rx_state == ELM_SUCCESS)
{
rpm = (uint32_t)tempRPM;
UpdateDisplay(rpm, false);
Serial.print("RPM: "); Serial.println(rpm);
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG) {
UpdateDisplay(0, true);
myELM327.printError();
}
}
The Code is written hier not Tested. I hope it helps
from elmduino.
You'll want to look at the multiple PIDs example
from elmduino.
@DerKleinePunk Thank you very much, your code I tested works fine and the RPM value doesn't flicker anymore!
I'll test it on a real car after I've changed all the code.
from elmduino.
How can I get the values of multiple PIDs and display them at the same time?
For example, I want to display two PIDs (e.g. rpm and coolant) on my SSD1306 LCD at the same time, but the correct value and the error value will be displayed alternately.
My code is as follows:
void show_canvas_on_screen() {
screen.drawRGBBitmap(0, 0, canvas.getBuffer(), canvas.width(), canvas.height());
}
//_____________________________________________________________
void updateRpm(uint32_t rpm, bool error) {
canvas.fillScreen(BLACK);
gfx.setFont(u8g2_font_wqy15_t_gb2312b);
gfx.setForegroundColor(LIME);
gfx.setCursor(2, 14); gfx.println(F("发动机转速 rpm"));
gfx.setFont(dsdigital_42);
gfx.setForegroundColor(WHITE);
gfx.setCursor(0, 62);
if (error) {
gfx.println(F("-"));
} else {
gfx.println(rpm);
}
//show_canvas_on_screen();
}
void updateCoolant(uint32_t coolant, bool error) {
//canvas.fillScreen(BLACK);
gfx.setFont(u8g2_font_wqy15_t_gb2312b);
gfx.setForegroundColor(LIME);
gfx.setCursor(2, 80); gfx.println(F("冷却液温度 °C"));
gfx.setForegroundColor(WHITE);
gfx.setFont(dsdigital_47);
gfx.setCursor(0, 128);
if (error) {
gfx.println(F("-"));
} else {
gfx.println(coolant);
}
show_canvas_on_screen();
}
//_____________________________________________________________
void loop() {
float tempRPM = myELM327.rpm();
if (myELM327.nb_rx_state == ELM_SUCCESS) {
rpm = (uint32_t)tempRPM;
updateRpm(rpm, false);
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG) {
updateRpm(0, true);
}
float tempCoolant = myELM327.engineCoolantTemp();
if (myELM327.nb_rx_state == ELM_SUCCESS) {
coolant = (uint32_t)tempCoolant;
updateCoolant(coolant, false);
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG) {
updateCoolant(0, true);
}
}
The debug log is attached:
debug_log.txt
from elmduino.
@DerKleinePunk thanks for sharing that link. There's some interesting code there, I like how you've integrated BLE/classic BT. Nice work.
from elmduino.
@jimwhitelaw Thanks
from elmduino.
Related Issues (20)
- ELM327::isPidSupported Error
- Custom PID, how it works HOT 9
- PID 70: Boost pressure control (Service 01) HOT 1
- ESP32 not connecting to ELM327 HOT 5
- Protocol Data Point HOT 4
- Couldn't connect to OBD scanner (stucked) HOT 18
- First time Bluetooth pairing between ESP32 and ELM327 HOT 1
- custom pid for DPF HOT 17
- BT Pairing problem between ESP-32 and ELM327 HOT 6
- How to change OBD protocol HOT 5
- Response not detected HOT 28
- Error in getting Multiple PID's HOT 6
- ESP32 s3 BLE compatibility? HOT 3
- Attempting to read non-standard PID HOT 1
- When does `queryPid` return `true`? HOT 4
- ESP32_CheckPIDs_1_20.ino HOT 1
- How to read data if I know TXD RXF RXD and MTH HOT 2
- ERROR: ELM_BUFFER_OVERFLOW on Honda Vezel 2023 HOT 4
- Problems in phase 1, can't connect with ELM327 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elmduino.