1. Welcome to Tacoma World!

    You are currently viewing as a guest! To get full-access, you need to register for a FREE account.

    As a registered member, you’ll be able to:
    • Participate in all Tacoma discussion topics
    • Communicate privately with other Tacoma owners from around the world
    • Post your own photos in our Members Gallery
    • Access all special features of the site

Raspberry Pi OBDII Project - MPG monitoring and more!

Discussion in '2nd Gen. Tacomas (2005-2015)' started by twhalm, Feb 26, 2018.

  1. Feb 26, 2018 at 6:32 PM
    #1
    twhalm

    twhalm [OP] Well-Known Member

    Joined:
    Aug 19, 2016
    Member:
    #194983
    Messages:
    247
    Denver, CO
    Vehicle:
    2015 TRD/OR Manual, OME , Dual battery
    I have owned a Bluetooth OBDII reader for a while and I had previously planned to either get a scangauge, ultragauge or mount an old cellphone to view my truck's data. Instead I made things monumentally more difficult and decided to make a project out of it. Mostly for the fun of it.

    I live near a Microcenter and they were selling Raspberry Pi Zero W's for $5 each so I decided to buy a few. At the time, I had never used a raspberry pi, so I had a lot of learning to do.

    For those of you unfamiliar, a Raspberry Pi is essentially a tiny Linux computer. People use them for all sorts of things from game emulators to controlling DIY robots.

    If anyone wants more details feel free to ask, but the final results was a OLED screen mounted near my dash that can display any OBD data I request. Right now I have it displaying my current MPG's, intake temp, water(coolant) temp, MAF reading, Trip OD, Trip fuel used, and Trip average MPG. This project was aimed at getting insight into my fuel usage so the display current shows that info, but theoretically I could display any info output by my truck.

    Since I was already fiddling with the wiring under my dash I also added in LCD voltage gauges for my starter and house batteries.

    Pics:

    What the screen looks like from the drivers view. I like it because it is tiny and does not obstruct my view in any way. For being so small it is still fairly info dense. The 'case' is some scraps of walnut I lying around. Also, it is hard to read the small text in the picture, but in person it is easy, it is about the same sized font as the KPH numbers around the speedometer.
    [​IMG]



    The screen is mounted with dual lock velcro and a tiny piece of aluminum. It is all light enough that I am not worried about it smacking me in the face in an accident.
    [​IMG]


    The raspberry pi sits in the little storage box (I don't know what it is called). This is also where I added LCD voltage indicators for both of my batteries. The LCD's are also wired to a switch so they are not on all of the time. Once again scrap walnut was used for this.
    [​IMG]


    Close view with LCD's on. They are MUCH easier to read in person.

    [​IMG]

    And a video of it coming up when my car starts - not sure how to embed so here is the link: https://streamable.com/wm9gv


    In parts only the total cost of the project is relatively cheap, but I ended up buying all sorts of tools and other items that drove the cost up. However the goal of the project was not to be cheap. To give a general idea of cost here is a very rough part list:
    • Raspberry Pi Zero W & case - $10
    • OLED screen - $20
    • Voltage Step-down - $5
    • LCD screens - $5
    • Tools and other small things - Who even knows at this point
    • Laying around - wire and cable making stuff, walnut scrap
    I learned a bunch during this project and I am still amazed that it actually works.


    VERY rough tutorial here: https://www.tacomaworld.com/threads...mpg-monitoring-and-more.536192/#post-17251356
     
    Last edited: Feb 27, 2018
  2. Feb 26, 2018 at 6:37 PM
    #2
    D2.

    D2. Well-Known Member

    Joined:
    Dec 1, 2016
    Member:
    #203759
    Messages:
    1,578
    Gender:
    Male
    First Name:
    Dan
    Nova Scotia, Canada
    Vehicle:
    2009 Tacoma - access cab 4x4 2TR-FE
    Cruise Control install. Intermittent wipers Hood lights Bed Lights Sliders 3" lift 886's on Billy 5100's Icon AAL 285/75 R16 Falken Wildpeak AT3W's
    Thats Fantastic!
    I've been thinking for a while now, how I'd like to swap out the clock under my radio for a Oled display and have it show useful stuff.

    Care to share your setup / code in more detail?
     
  3. Feb 26, 2018 at 6:38 PM
    #3
    Trouble_The_Tacoma

    Trouble_The_Tacoma Well-Known Member

    Joined:
    Dec 26, 2016
    Member:
    #205749
    Messages:
    2,268
    Gender:
    Male
    First Name:
    Conrad
    Running Board Man and twhalm[OP] like this.
  4. Feb 26, 2018 at 6:42 PM
    #4
    twhalm

    twhalm [OP] Well-Known Member

    Joined:
    Aug 19, 2016
    Member:
    #194983
    Messages:
    247
    Denver, CO
    Vehicle:
    2015 TRD/OR Manual, OME , Dual battery
    The code heavily used this: https://github.com/brendan-w/python-OBD

    I modified things to watch for errors and things but that like is 90% of the functionality.

    Wiring and getting the screen working was also a pain, but that is pretty screen specific.

    Also another important thing to keep in mind with wiring is raspberry pi's are 5V. So you can go as simple as a USB cigarette adapter.

    Feel free to ask more specifics.
     
  5. Feb 26, 2018 at 6:46 PM
    #5
    twhalm

    twhalm [OP] Well-Known Member

    Joined:
    Aug 19, 2016
    Member:
    #194983
    Messages:
    247
    Denver, CO
    Vehicle:
    2015 TRD/OR Manual, OME , Dual battery
    Only if you know what you are doing and I sure didn't!
     
  6. Feb 26, 2018 at 6:48 PM
    #6
    Trouble_The_Tacoma

    Trouble_The_Tacoma Well-Known Member

    Joined:
    Dec 26, 2016
    Member:
    #205749
    Messages:
    2,268
    Gender:
    Male
    First Name:
    Conrad
    Lol Yeah, I guess if you factor in how much you value your time at vs how much time you spend on learning. But now you have the skills to do it! I have a buddy at work who uses Raspberry Pi's to do all sorts of home automation stuff. He has a dealio where his garage door opener recognizes his car and opens automatically for him. I'll have to show him this.
     
    twhalm[QUOTED][OP] likes this.
  7. Feb 26, 2018 at 6:49 PM
    #7
    Fullboogie

    Fullboogie Well-Known Member

    Joined:
    May 8, 2017
    Member:
    #218539
    Messages:
    1,124
    Gender:
    Male
    First Name:
    Dave
    Houston
    Vehicle:
    2007 Prerunner & 2008 4Runner
    Hell of a project man - thanks for posting!
     
    twhalm[OP] likes this.
  8. Feb 26, 2018 at 6:51 PM
    #8
    D2.

    D2. Well-Known Member

    Joined:
    Dec 1, 2016
    Member:
    #203759
    Messages:
    1,578
    Gender:
    Male
    First Name:
    Dan
    Nova Scotia, Canada
    Vehicle:
    2009 Tacoma - access cab 4x4 2TR-FE
    Cruise Control install. Intermittent wipers Hood lights Bed Lights Sliders 3" lift 886's on Billy 5100's Icon AAL 285/75 R16 Falken Wildpeak AT3W's
    how long does it take for the PI to boot and give you useful information?
     
  9. Feb 26, 2018 at 7:05 PM
    #9
    twhalm

    twhalm [OP] Well-Known Member

    Joined:
    Aug 19, 2016
    Member:
    #194983
    Messages:
    247
    Denver, CO
    Vehicle:
    2015 TRD/OR Manual, OME , Dual battery
    I actually have the Pi on 24/7 so it "boots" instantly. When it detects the engine is off it goes to "sleep" and waits for ignition from the keys. Luckily I have a dual battery system and the pi running off of the second battery.

    It would probably be fine either way though since the Raspberry pi and OLED use such a small amount of power (max .25 A @ 5V). Even with the Pi running at a super aggressive 100% CPU with bluetooth and wifi on it would still be weeks before my battery died.

    Regardless I do have my pi shutdown if the car is not turned on for two days.

    When that does happen it takes an annoyingly long time to boot - like 45 seconds. Which is why I decided to have it on 24/7
     
    I married my tacoma likes this.
  10. Feb 26, 2018 at 8:16 PM
    #10
    Foxtato

    Foxtato Well-Known Member

    Joined:
    Jan 24, 2014
    Member:
    #121385
    Messages:
    404
    Gender:
    Male
    Puyallup, WA
    Vehicle:
    2011 Tacoma 4x4
    Wow, this is really cool. Any chance at you putting together a step-by-step to get the Pi up and running? Might have a lot of fun with this project!
     
  11. Feb 26, 2018 at 8:26 PM
    #11
    twhalm

    twhalm [OP] Well-Known Member

    Joined:
    Aug 19, 2016
    Member:
    #194983
    Messages:
    247
    Denver, CO
    Vehicle:
    2015 TRD/OR Manual, OME , Dual battery
    I might get around to this at some point. My code is nowhere near polished enough to share at this point, but I could probably put together something about getting the pi powered off of the truck and reading OBD data from from a bluetooth OBD device.
     
    Foxtato[QUOTED] likes this.
  12. Feb 26, 2018 at 8:29 PM
    #12
    twhalm

    twhalm [OP] Well-Known Member

    Joined:
    Aug 19, 2016
    Member:
    #194983
    Messages:
    247
    Denver, CO
    Vehicle:
    2015 TRD/OR Manual, OME , Dual battery
    I forgot to mention in the OP that this also displays throttle position and engine load as the bars on the sides of the screen. Zero bar is 0% and full bar is 100%.

    In the first pic you can see the two bars. Throttle is at idle (like 10%) and engine load is around 50%. I am still not 100% sure what engine load means :notsure:
     
  13. Feb 26, 2018 at 9:19 PM
    #13
    Foxtato

    Foxtato Well-Known Member

    Joined:
    Jan 24, 2014
    Member:
    #121385
    Messages:
    404
    Gender:
    Male
    Puyallup, WA
    Vehicle:
    2011 Tacoma 4x4
    That would be a great start!
     
  14. Feb 27, 2018 at 7:27 AM
    #14
    twhalm

    twhalm [OP] Well-Known Member

    Joined:
    Aug 19, 2016
    Member:
    #194983
    Messages:
    247
    Denver, CO
    Vehicle:
    2015 TRD/OR Manual, OME , Dual battery
    Alright, as Foxtato suggested here is a simple how-to to get other people started if they want to fool around with a Raspberry Pi like I did.

    This is not going to be a super extensive guide, but it should be enough to get off the ground if you are a little tech savvy. YMMV

    Skills required (or to learn on the way):
    • Wiring ranging from automotive to tiny
    • Super basic knowledge of circuits
    • Python
    • Soldering
    • Using linux and using the command line in a terminal
    Tools needed:
    • Wire strippers
    • Soldering iron (most likely)
    • A computer or laptop
    • A computer monitor or TV ( you can use the one you current computer is attached to)
    Parts necessary:
    • Raspberry Pi Zero W or Raspberry Pi 3. I suggest these because they have built in Wifi and bluetooth. You will need both for this project
    • A microSD card
    • OBDII bluetooth device almost any on Amazon should work I use the veepeak one
    • Some thing to power the Pi. They are powered off of a MicroUSB. I don't think the one in some Tacoma's spits out enough power so you will either need a cigarette lighter port or something else. I used this to step down the 12V from the car down to 5V for the pi and it has worked very well.
    • Some sort of screen. (not required during the fool around phase) This is the one I used. Raspberry Pi's do have HDMI out, but I did not use that because I was looking for something small and low power.
    • This switch may be very useful. It acts as a power supply (so you can ignore item number 3) AND it can let you gracefully shut down the raspberry pi when your ignition turns off. I did not used this but it probably would have made my life easier.
    • Fuse taps

    Alright here are the rough steps we will need to take to get this project off of the ground - I will expand on each.

    1. Get your raspberry Pi set up and good to go (wiring to car to required yet)
    2. Install the bluetooh OBDII reader
    3. Connect the Pi to the OBD reader
    4. Wire the PI to the car if you want
    5. Code land - which I will not get into much here
    Step 1: Getting your Raspberry Pi set up

    Part 1: Plugging it in and getting an Operating System

    You can quickly get a Pi up and working by pluging it in with a micro USB and hooking it up to a monitor with an HDMI cable (you may need an adapter)

    Out of the box most pi's don't come with an OS. Luckily they are pretty easy to install. I suggest just installing the basic Rasbian OS. See a good tutorial here: https://www.raspberrypi.org/learning/software-guide/

    Part 2: Turn on VNC and or SSH

    We will need this to connect to the pi remotely when it is in the car and doesn't have a monitor attached:
    https://www.raspberrypi.org/documentation/remote-access/vnc/README.md

    Part 3: Install necessary packeges

    I might missing something here or you might find you need more along the way. From a terminal:

    Make sure everything is up to date:

    sudo apt-get update

    Install PIP (python package manager - probably already have it)

    sudo apt-get -y install python-pip

    Install the main OBD library we will use

    sudo pip install obd

    Install pi serial to handle the bluetooth stuff

    sudo apt-get install python-serial

    At this point I think we are good to go for the most part.

    Step 2: Install the OBD Bluetooth reader:

    Find your OBD connector in your truck. In my 2015 in is under the driver side dash by the door. Plug in your OBD reader. Maybe try to connect to it via bluetooth with your phone to make sure it is working.

    Step 3: Connect the PI and the OBD reader via bluetooth:

    This is where things get difficult. Depending on your reader, your truck can probably be off during this part. However your raspberry pi will need to be close enough to your truck to connect to the reader via bluetooth. This means that you will need to run power to your garage or driveway and have wifi there to connect to your pi via VNC (or bring a monitor into the garage too).

    I had a lot of issues in this step and I still don't understand why it works but you essentially need to pair, trust and connect to the OBD reader with the PI and then assign it a serial port for the software to be able to use it.

    To get bluetooth up and working follow the steps provided in this forum post. It should be the top post on page 2. Once this is done your raspberry pi should be "connected" to your reader and we are ready to use it!

    Note: you will need to run this command every time you boot (this can be done automatically):
    sudo rfcomm connect hci0 XX:XX:XX:XX:XX:XX

    If you know how to use python you can use the attached code to check if you are connected and to see what OBDII commands are available.


    Code:
    import obd
    
    connection = obd.OBD() # auto-connects to USB or RF port
    
    print ("connection Status: " + connection.status())
    
    print ("Protocol Name: " + connection.protocol_name())
    
    # print all of the supported commands.  This will change depending if the engine is on or off
    commands = connection.supported_commands
    print("Supported Commands:" )
    for command in commands:
        print(command.name)
    
    



    I am not going to dive into the code too much, but for great documentation on how to use the python OBD library see here: http://python-obd.readthedocs.io/en/latest/

    You will need to fully dive into python code to learn about writing code to gather the information you want and writing it to a screen.


    STEP 4: Wiring the Pi to your car:

    How you wire your Pi up is really up to you. One thing you should know though is that just cutting the power to your pi to turn it off is bad for it and can corrupt your SD card. You want to use a script to command to pi to shutdown. That switch I mentioned in the parts list can get you going and help with shutting down cleanly.

    The other important part is making sure that you step down the car's 12V power to 5V.

    For my setup I have my pi powered by my second battery via a UBEC that was soldered to a microUSB cord and I have it on 24/7.


    How you wire your screen is also super specific to the type of screen you buy.

    Step 5 Code Land:

    If there is a demand I probably can clean up my code and provide it for reference, but if you want to tackle this project, it is likely your desires are different and as such you should dive in and learn all you can. Once again there is really great documentation on how to use the OBD library here: http://python-obd.readthedocs.io/en/latest/


    Sorry this is not a step-by-step tutorial. This project was pretty exploratory and by no means perfect. My only hope is that this may get someone else started down the same path.
     
    Foxtato likes this.
  15. Feb 27, 2018 at 9:03 AM
    #15
    Foxtato

    Foxtato Well-Known Member

    Joined:
    Jan 24, 2014
    Member:
    #121385
    Messages:
    404
    Gender:
    Male
    Puyallup, WA
    Vehicle:
    2011 Tacoma 4x4
    Weekend project here I come! (as soon as I get some free time :D )

    Thanks for the write-up, looks pretty robust
     
    twhalm[QUOTED][OP] likes this.
  16. Feb 27, 2018 at 2:21 PM
    #16
    twhalm

    twhalm [OP] Well-Known Member

    Joined:
    Aug 19, 2016
    Member:
    #194983
    Messages:
    247
    Denver, CO
    Vehicle:
    2015 TRD/OR Manual, OME , Dual battery
    If you do dive in, let me know if you have questions. There is a small chance I would help haha
     
    Foxtato[QUOTED] likes this.
  17. Feb 27, 2018 at 2:55 PM
    #17
    TacoS805

    TacoS805 Well-Known Member

    Joined:
    Dec 29, 2017
    Member:
    #239721
    Messages:
    76
    Gender:
    Male
    First Name:
    Steve
    So Cal
    Vehicle:
    2004 White 2.7L 4x4 5 speed Xtra Cab
    This is good work man! Awesome! I’m going to dive into this as well with my ‘04.

    Even thinking of combining this project with a PirateBox hosted Factory Service Manual. Then any nearby device could act as FSM should any trouble be encountered :cool:
     
  18. Feb 27, 2018 at 3:25 PM
    #18
    Harry

    Harry Science, Bitches

    Joined:
    Sep 16, 2014
    Member:
    #138415
    Messages:
    1,048
    Gender:
    Male
    Santa Fe NM
    Vehicle:
    15 TRD Off Road DCSB
    Neat. I already have a Scangauge but - Neat.

    I've been thinking about a similar project to actuate the intercooler pump for my supercharger. It would be nice to actuate the pump at start - having the pump run continuously with the ignition on without the engine running is less than ideal.
     
  19. Feb 27, 2018 at 3:36 PM
    #19
    twhalm

    twhalm [OP] Well-Known Member

    Joined:
    Aug 19, 2016
    Member:
    #194983
    Messages:
    247
    Denver, CO
    Vehicle:
    2015 TRD/OR Manual, OME , Dual battery
    I haven't thought if that, but that is a good idea. I could have basically anything I wanted, from service manuals to maps. Hmm....
     
    TacoS805[QUOTED] likes this.
  20. Feb 27, 2018 at 4:56 PM
    #20
    Foxtato

    Foxtato Well-Known Member

    Joined:
    Jan 24, 2014
    Member:
    #121385
    Messages:
    404
    Gender:
    Male
    Puyallup, WA
    Vehicle:
    2011 Tacoma 4x4
    I'm a software engineer, so I can sling some code. Not super familiar with Python, but I can figure it out :D
     
    TacoS805 likes this.

Products Discussed in

To Top