Go back to home



We have detected that you are using ad blocking software.
The MR2 Australia forum is made possible by ad revenue.
Please disable your ad blocker to ensure that this site lives on.

Android head unit gauges display

Author
tuban
MR2 Aficionado
  • Total Posts : 71
  • Scores: 8
  • Reward points: 3323
  • Joined: 2012/10/27 20:19:29
  • Status: offline
2021/09/21 08:26:42 (permalink)
0

Android head unit gauges display

My SONY car stereo was failing, sometimes refusing to start so I wondered about an “improvement”, a 7” display head unit.  The dash opening on the MR2 looks like a perfect fit.   I presently have three gauges above the SONY and wondered if I could put some software gauges into a head unit.
 
First decision was between an Android head unit and a Raspberry Pi unit.  My 1990 MR2 is pre ODB-II so the head unit would need to take some voltages as gauge inputs.
 
The Raspberry Pi would need a lot of work to assemble as it is a more homebrew solution than an Android unit.  Android units on Ebay were around A$130 including postage and included built-in radio, audio power amp, Bluetooth, GPS, WiFi, able to link with phones, and ability to load lots of Android apps.  Right out of the box.   Much cheaper and mechanically more robust than the Raspberry Pi option.
 
What I would need would be to write an Android App to display gauges and an interface for the analogue input voltages.  The options for the analogue interface would be via Bluetooth, WiFi or USB.   I had a Raspberry PICO that has a USB connection and can read a few analogue voltage inputs, and is powered over USB so no need for further power supplies.  The PICO sell for about A$8.  My PICO came stuck to the cover of a magazine on a newsagent!
 
I wrote a short Python script to read three inputs for voltages and send the values out the USB port every half-second.
 
I’d never written software for Android so this was the main hurdle.  I found a gauges software library and also a USB serial I/O library.  Many thanks to Anas Altair for the great speedviewlib, https://github.com/anastr...blob/master/README.md, and  Felipe Herranz for the USB library, https://github.com/felHR85/UsbSerial/releases.
 
The resulting app gives a display like this:
 
The left gauge is boost, middle gauge is the air/fuel ratio, and the right hand gauge is a turbo temperature value that I generate from the boost signal.  I use this to decide when to shut down the engine for turbo cooldown.   If boost indicates the engine/turbo is working hard the temperature will begin to rise and it will decay if the boost is low.  I worked out a thermal model from some turbo temperature models on the internet (https://liu.diva-portal.org/smash/get/diva2:1149266/FULLTEXT01.pdf etc) and then fitted a thermal mass and thermal resistance to give a cooldown time of 30sec after light duty and 5mins after heavy duty.  The cooldown target was to a turbo temp of 220C which seems to be a typical max temp for synthetic oil.  So I wait until this gauge shows less than 220C and then shut the engine off.  It’s like a turbo timer but a bit more interesting.  Seeing a temperature makes me a bit more careful than seeing a simple turbo timer.
 
The value at the bottom of the screen is the battery voltage.  When I took this pic I was running the head unit on my desk so the PICO didn’t have any input voltage connections giving the odd values in the pic.
 
The PICO has an internal 3.3V supply so input voltages need to be kept in a 0V to 3.3V range.  I added resistor dividers on the three inputs to convert a 0-17V range into a 0-3.3V range.  The dividers are each a 33K resistor together with a 10K trimpot.  The trimpot lets me calibrate the input ratio for better measurement accuracy.  The 17V range is overkill for the boost and AFR sensors however it does still give enough accuracy for those signals and is safer against a wrong connection.  Plus simpler if we can setup all three inputs the same before they get to the Android app.
 
The next fig shows one of the three input circuits.

 
All three PICO voltage measurement inputs have the same 0-17V range and calculations of voltage to battery voltage, boost PSI, and AFR are in the Android app.
 
The sensor voltages are connected to the PICO via the resistor dividers, boost sensor voltage to input #26, battery voltage to input #27, and AFR voltage to input #28.  You can see the 33k resistors and the 10k trimpot resistors in the next picture.  There is also a 47uF tantalum capacitor across the trimpots to give some noise filtering as car environments can be noisy.  Not sure if necessary or not.

My boost sensor has a 12V and 0V connection and an output signal that is 4.14V at +40psi and 0.37V at -11psi.  I measured some voltages while I connected the sensor to a water-filled plastic tube in a “U” (https://instrumentationtools.com/u-tube-manometer-principle/).   My AFR measurement unit is an  “Innovate Motorsports 3918 MTX-L Plus” mounted in the boot of the MR2.   It gives 0V for AFR of 7.35 and 5.0V for AFR of 22.4.   It needs a good 12V connection as it supplies the heater in the O2 sensor so I’ve wired this 12V supply from the engine bay.
 
Do you want to make your own head unit?  Starting with the PICO you would need to load MicroPython, https://magpi.raspberrypi.org/articles/programming-raspberry-pi-pico-with-python-and-micropython.  Then enter the following Python app onto the PICO using Thonny on your PC (https://thonny.org/).    The Python code is:
 
import machine
import utime
import math
 
pinBoost = machine.ADC(26)
pinBatteryVolts = machine.ADC(27)
pinAFR = machine.ADC(28)
 
while True:
    print( "S,"+str(pinBoost.read_u16())+","+str(pinBatteryVolts.read_u16())+","+str(pinAFR.read_u16())+”,”)
    utime.sleep_ms(500)
 
Once you run the program it should print lines like “S,10786,12979,13347,” a couple of times per second.  The numbers will move around depending on what voltage is at the three inputs.
 
When you save this program there are options to save on your PC or save to the PICO.  You should save this to the PICO so that it will run automatically when the PICO is restarted.    You can then unplug the PICO.
 
To load the Android app on the head unit you will need to enable debug mode on the head unit, https://www.carlcare.com/...s-android.   Then put the file app-develop-debug.apk onto a USB stick and plug this into the head unit.  Go to the file manager and the USB drive and then click on the app-develop-debug.apk file.  Android should then install the app.  If the PICO is then plugged into the head unit the app should start and you should see the gauges.
 
Once you see that the app is running OK you should then disable the developer option as per the previous link.  Developer mode is only needed to allow loading of the app as it is not being delivered through Google Play.
My head unit was Android 9.1.  I noticed that there are similar units that come with Android 10.  I haven’t tried that.  Android 10 includes specific changes to do with Android Automotive OS extensions and I don’t know if these might interact.  I initially developed the app on a SAMSUNG tablet and it took me a while before I could run anything on the head unit.  Even with the SAMSUNG being Android version 9 the SAMSUNG did behave differently to the head unit and I had to make changes to get it to work on both.   So I am wary about different Android versions.
 
Before you install the head unit you would need to power it up on the bench and adjust the calibration trim pots by providing expected voltage signals for the three inputs and then adjusting so that the expected values are displayed by the app.
The boost voltage input is normall in the 0-5V range.  If the boost voltage input is above 10V the app will display three voltages in the lower line where it normally only displays battery voltage.   If you have the unit connected to a battery you can connect the three input signals to the battery positive and the app will then show three values that should be the battery voltage.  Put a voltmeter across the battery to measure the voltage and then adjust the three trimpots to get the displayed three voltages close to your voltmeter reading.  The display looks like this when I had adjusted the trimpots for a 12.15V measured battery voltage.

I found that the head unit drew 0.5A when it was on but a hefty 0.3A when it was off.  0.3A would flatten my battery in a week so I’ve wired the power to the head unit so that all power is from the accessory circuit of the MR2, these connections on the head unit were +12V, and ACC.  The headunit has an ILLUM and the MR2 had a similar connection point.  ILLUM gives backlight on the controls and also dims the display a bit.
 
These power connections mean that Android has to boot whenever the car is turned on which takes about 40sec.  This wiring also means that Android can have the power shut off unexpectedly when you turn the ignition off.  The Android filesystem itself is designed to handle such interruption (ETX4 format etc) however, if Android was updating a file just before power-off then the update might not have been completed.  If you do anything like change settings etc it would be a good idea to turn the power off at the head unit power switch before turning the ignition switch off.  This would let Android know to clean up before it is turned off.
 
Here is the new MR2 dash.  Had to file the opening a bit and I gave up on trying to mount it from inside and added a couple of angle strips each side.
 

 
If interested let me know and I'll put the app files up on Google drive or somewhere.
#1


1 Reply Related Threads

    tuban
    MR2 Aficionado
    • Total Posts : 71
    • Scores: 8
    • Reward points: 3323
    • Joined: 2012/10/27 20:19:29
    • Status: offline
    Re: Android head unit gauges display 2021/09/21 14:37:09 (permalink)
    0
    If you want to use the android app with different sensors with different output voltages I’d suggest that you do the voltage scaling in the Python code of the PICO as it is much easier to change this than modify the Android app. 
     
    The gauges library does have lots of other gauge styles.  Here are a few examples.

    Brace yourself if decide to make changes to the app.  The software development environment, Android Studio, is a free download if you do want to play with the app however it’s a monster package with a significant learning time if you haven’t written an Android app before.  At one point I deleted and reinstalled Android Studio together with a few prototype applications and the Windows recycler stated 150,000 files and 15Gb had been deleted!
    #2
    Jump to:

    © 2021 APG vNext Commercial Version 5.5