Arduino with Megasquirt and CAN Bus

Hey all, I was wondering if you could help me with the next step of my project. I have added a Megasquirt , which is an aftermarket Engine Control Unit (ECU), to my '73 Volkswagen. The Megasquirt outputs sensor information through a CAN Bus which I would like to output via a LCD screen. I have communication and can receive data. I’m just not sure how to turn what I’m receiving into something I can display.

Here is the sketch;

#include <CAN.h>
#include <SPI.h> // required to resolve #define conflicts

// Define our CAN speed (bitrate).
#define bitrate CAN_BPS_500K

void setup()
{
  Serial.begin(115200);  // Initialize Serial communications with computer to use serial monitor

  //Set CAN speed. Note: Speed is now 500kbit/s so adjust your CAN monitor

  CAN.begin(bitrate);

  delay(4000);  // Delay added just so we can have time to open up Serial Monitor and CAN bus monitor. It can be removed later...

  // Output will be formatted as a CSV file, for capture and analysis
  Serial.println(F("millis(),ID,Length,Data0,Data1,Data2,Data3,Data4,Data5,Data6,Data7"));
}


// Create a function to read message and display it through Serial Monitor
void readMessage()
{
  unsigned long can_ID; // assign a variable for Message ID
  byte can_length; //assign a variable for length
  byte can_data[8] = {0}; //assign an array for data

  if (CAN.available() == true) // Check to see if a valid message has been received.
  {
    CAN.read(&can_ID, &can_length, can_data); // read Message and assign data through reference operator &

    Serial.print(millis());
    Serial.print(F(",0x"));
    Serial.print(can_ID, HEX); // Displays received ID
    Serial.print(',');
    Serial.print(can_length, HEX); // Displays message length
    for (byte i = 0; i < can_length; i++)
    {
      Serial.print(',');
      if (can_data[i] < 0x10) // If the data is less than 10 hex it will assign a zero to the front as leading zeros are ignored...
      {
        Serial.print('0');
      }
      Serial.print(can_data[i], HEX); // Displays message data
    }
    Serial.println(); // adds a line
  }
}


// Finally arduino loop to execute above function with a 50ms delay
void loop()
{
  readMessage();
  delay(50);
}

Here is what I get in the serial monitor;

millis(),ID,Length,Data0,Data1,Data2,Data3,Data4,Data5,Data6,Data7
4802,0x5E8,8,03,D0,08,DC,06,4D,00,7E
5535,0x5EB,8,00,6D,00,00,00,00,00,00
6369,0x329,8,00,9F,00,00,00,00,00,00
6744,0x1EB,8,00,6D,00,00,00,00,00,00
7086,0x5EB,8,00,6D,00,00,00,00,00,00
7177,0x5EA,8,80,93,03,E9,00,02,BF,FF
7418,0x1EB,8,00,6D,00,00,00,00,00,00
7511,0x5EB,8,00,6F,1F,5F,7F,7F,7F,FF
7702,0x1F6,8,00,66,03,DC,03,DC,00,00
7744,0x1F6,8,00,66,03,DC,03,DC,00,00
7986,0x5F1,8,01,5D,09,01,FF,80,01,01[code/]


I understand that I am getting a timestamp, the message ID and then the 8 bytes of data, but how do I make that into coolant degrees or RPM?

I'm totally lost at this point..

Thanks

Provide a link to the documentation that describes the Megasquirt data format.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks… Tom… :slight_smile:

Here is a link to the CAN Bus documentation for Megasquirt.

Also here starting at Section 4.36

http://www.msextra.com/doc/pdf/html/Megasquirt3_Setting_Up-1.5.pdf/Megasquirt3_Setting_Up-1.5-136.html

Have a look on the Megasquirt support forums to see if anyone has created an abstraction layer that turns the memory map into something easier to use.