OBD2 Fuel Consumption Gauge

Picked up an STM32F103 micro, an ILI9341 and a ELM327 OBD BT dongle clone and off it goes!!!

Similar projects worth following
My car doesn't have an onboard computer but I want to monitor the fuel consumption.
I've tried to use a ELM327 Bluetooth dongle (china clone) and Torque app but the dongle doesn't support all the AT commands needed to read the fuel data from the OBD bus.
So I found a KW1281 arduino library, (im)ported/improved/modded it to STM32 running arduino IDE and added the ILI9341 code.

The first attempt at this project was using the ELM327 Bluetooth dongle.

But I came to find that the available OBD info provided by the dongle was insufficient. It only provided speed, RPM, water temperature and a couple other sensor readings.

But nothing relative to fuel consumption...

Then I switched to another approach: "what if I could drive the OBD bus directly?"

So I searched the web for OBD implementations using arduinos and found this web page (OBD2_KW1281) that described very well the KW1281 protocol (used by my Audi A4) and had the code for arduino too! Nice!

I'm using STM32 with the arduino IDE gathering the best of three worlds: good performance, low price and vast libraries/code available. You can check it out at

  • 1 × STM32F103 Microprocessors, Microcontrollers, DSPs / Microcontrollers (MCUs)
  • 1 × ILI9341 2.8" 320x240 TFT LCD display
  • 1 × ELM327 Bluetooth Dongle OBD2 to Bluetooth dongle
  • 1 × MCP9801 Sensors / Temperature, Thermal

  • Why 90? (part 2)

    Rui Rex7 days ago 0 comments

    I've made some code optimizations to try to reduce the display printing times.

    Got it to a minimum still using only the STM32 but even at idle engine I got some connection fails and retries.

    So the "diy" "hacked" UART TX signal inverting using an interrupt might be ruining the communication. Either that or the long cable carrying the UART signals from the OBD plug location to the dash... :) I have to fix the inverting and retry...


    Meanwhile I got the ILI9341 to refresh at 60fps on the ESP8266 xD

    I'm able to run the display at 80Mhz SPI speeds!!!! xDDD

  • Why 90?

    Rui Rex04/12/2017 at 08:40 0 comments

    So, I've managed to get some cables on the car and route the K-line control signals from the OBD adapter to the dashboard. This way I can drive and look at the display without loosing sight of the road!!! Drive safely!! :)

    Then I hit the road and all was fine. An occasional reconnection here and there but all seems ok.

    But then I entered the highway and everything went crazy! I noticed that after 90Km/h the OBD seems to stop responding.

    When I come back under 90 it reconnects and everything is ok.

    The code is not very optimized because I read the OBD values (3 blocks) and then I update the display and also read the temperature sensor and also update the display with that. This takes around 130+90=220ms. From what I've seen using the VAG-COM software on the laptop and capturing the control signal, when the software is idling it sends ACK frames back and forth to the ECU. So this 220ms might be too long between communications and the ECU might drop the connection. Still have to investigate further...

    But I'm planning to add a ESP8266 to be in charge of the display control and leave the STM32 only with the OBD tasks. This way I can leave it reading the blocks at max speed and reporting them to the ESP through RS232 and leave it to display the data.

    More to come...

View all 2 project logs

Enjoy this project?



Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates