I'm building a little vehicle computer based on a Teensy 3.2 board and am wondering how I might be able to work out average MPG and then a "miles to empty" figure.
I have a link into the CAN-BUS so I can pull any PIDs necessary (2019 GM engine so should be latest CAN version). I also will have fuel level analogue in and have a trip and odometer already built in.
I'm thinking that the best way would probably be to look at the injector times and work out the amount of fuel injected over a given sample time, stored with the distance traveled by the car in that time. The data should then be averaged over a given time or distance (maybe the previous 10 minutes or 10 miles?) then an average mpg calculated, then compared with the remaining fuel level to achieve a distance to empty.
First question - are there any better suggestions? I have searched for a while and can't really find any examples of this...
Second question - what would be the best approach to do this with arduino? Perhaps a large array? I'm not really sure how to approach this being quite new to arduino. Does anyone have any suggestions or sample code to take a look at?