Go Down

Topic: Arduino Emerald ECU can bus speedometer (Read 3098 times) previous topic - next topic

trewjohn2001

Sep 09, 2015, 06:04 pm Last Edit: Sep 09, 2015, 06:06 pm by trewjohn2001
Sketch to use an Arduino Mega, Spark-Fun Can Bus shield to read the CAN BUS output from an Emerald K6 ECU.

I´m building an MGB GT V8 and I wanted to keep the look of my original Smiths Speedometer and Tachometer but integrate them with the new ECU. 



 So far it has the following features:



Odometer
Trip
Speed
Oil Temperature
Oil Pressure
Water Temperature
Outside Temperature
Inlet Temperature
ECU Voltage
AFR
RPM
MAP Pressure
Barometer
Throttle Position
Ignition Dwell
Ignition Advance
Injector Duration
Selected ECU MAP
0-60 Timer
CAN BUS failure alert
Service Reminder


I am working on a new version that has a second OLED where the old trip counter used to be.  This will be used for alarm status and a shift light. 

The old Speedometer was mechanically driven. The Smiths  tachometers use the same case but a moving coil meter, I fitted the face from my speedometer to a spare Tachometer and drive the moving coil meter through the PWM outputs.

Its not 100% finished and its probably a bit clumsy in places.

A couple of links - the first video is the earlier version which I used a pot to simulate changing CAN bus values.  The second You Tube link is using live data from an emerald ECU with  simulated crank and speed inputs. 

https://www.youtube.com/watch?v=-dAtya3z_hk

 

trewjohn2001


odometer

#2
Sep 16, 2015, 11:05 pm Last Edit: Sep 17, 2015, 08:51 pm by odometer Reason: fixing a mistake I made
I am trying to understand some of the calculations in your code.

Code: [Select]

   mps = SPEEDReal / (19); //convert to distance meters per second

What units is SPEEDReal here? From looking at the rest of your code, I think it's supposed to be kilometers per second hour. Is that right?

Nineteen kilometers per hour should not convert to one meter per second.

19 kilometers = 19000 meters
1 hour = 3600 seconds
19000 / 3600 = 5.277...
Therefore, 19 km/h = 5.27... m/s  


Also, I see this:
Code: [Select]

 if (meterssubtotal >99){
  
   ++disthundredm;
   ++tripdisthundredm;
  
   meterssubtotal = 0;
  
 }

What if, for example, meterrsubtotal is 105 ? Then you've just thrown away 5 meters. Over the course of many kilometers, this will really add up.

I wish you best of luck with this project.

trewjohn2001

Hi,

Sorry I haven´t checked the forum in a long time.  The project has moved on a little - I think I was using /19 when I was simulating the speed data with a pot.  To use the speed from the CAN bus I need to perform some maths on the raw can bus data to get KPH and MPS.

http://www.emeraldm3d.com/media/software-manuals/Emerald%20K3%20&%20K6%20CAN%20protocol.pdf


Your right on the Meterssubtotal - that needs some more work I should have at least included an >=  not just a great than.  But even so there will be an error.  I don´t think it was much of an error as I set the simulated speed to 60KPH for an hour and timed and recorded the data I dont recall enough of an error to be concerned at the time.  Definitely more accurate than my existing odo!  I will double check that though - thanks for pointing it out.

I´m still welding on the car so the project hasn´t gone live yet.  I am expanding it to include:

Hazards
Wash Wipe
Intermittent wipe (speed sensitive)
Wiper speed
Indicators (automatic self canceling)
Horn
Flash
High Beam
Cooling fan control/cycling

Im using two Ford Focus stereo remotes which I will fit to the binnacle.  I´m using a couple of ULN chips and an LM358 to drive the tacho and speedo needles.

Here is the latest sketch - still not complete and a work in progress.

 


trewjohn2001

#4
Aug 20, 2016, 12:12 pm Last Edit: Aug 20, 2016, 12:43 pm by trewjohn2001 Reason: Forgot Attachments
Here are the Ford Controls I'm using.  To debounce the analogue input I read the state of the buttons at the beginning and end of the sketch and if they are the same then the switch input is valid.   I don't know if that's the right way of doing it but seems to work in practice.  

odometer

Your right on the Meterssubtotal - that needs some more work I should have at least included an >=  not just a great than.  But even so there will be an error.  I don´t think it was much of an error as I set the simulated speed to 60KPH for an hour and timed and recorded the data I dont recall enough of an error to be concerned at the time.  Definitely more accurate than my existing odo!  I will double check that though - thanks for pointing it out.

Instead of setting meterssubtotal to 0, try subtracting 100 from it.

trewjohn2001

Instead of setting meterssubtotal to 0, try subtracting 100 from it.
Hi - thanks - that´s a great idea!  That way the remaining meters won´t get discarded. 

Go Up