I have used an arduino to control a turbo.. It's been a while since i looked at the specific code for that section though.. I do know that I was able to sniff the packets sent by the turbo telling me it's current parameters.. I used the standard CAN bus library.
MCP CAN1(10); 'pin 10 is the SPI SS pin
#define VGTaddress 0x0CFFC600UL //CAN bus address of the VGT controller
#define StatusMessageID 0x18FFC502UL //this is the message id of the messages we're concerned with
#define BreakMessageID 0x18FF0A02UL //This is the message id of a 'terminator' string, or something... no relevant information it seems
#define ErrorMessageID 0x18EEFF02UL //Seems to be an error message ID when low voltage is triggered?
void loop(){
ReadCanMessages();
}
void ReadCanMessage() {
//This is from the MCP examples, modified to work for what I need
unsigned long ID; // assign a variable for Message ID
byte length; //assign a variable for length
byte data[8]; //assign an array for data
if (CAN1.msgAvailable()) { // Check to see if a valid message has been received.
CanMessagesReceived++;
CAN1.read(&ID, &length, data); // read Message and assign data through reference operator &
if (ID == StatusMessageID) {
VgtCommandPosition = ((data[6] * 256) + data[5]);
VgtRealPosition = ((data[2] * 256) + data[1]);
VgtMotorCommandSpeed = data[7] - 127;
VgtRawTemp = data[3];
}
else if (ID == BreakMessageID) {
//do nothing.. it's an unimportant message
}
else if (ID == ErrorMessageID) {
PrintCANmessage(ID, length, data);
}
else {
//we got a new message type.. lets figure it out
//PrintCANmessage(ID, length, data);
}
}
}
void PrintCANmessage(unsigned long ID, byte length, byte* data) {
Serial.print("CanMessage = ID");
Serial.print(" | 0x");
Serial.print(ID, HEX); // Displays received ID
Serial.print(" | ");
Serial.print("Data Length DEC");
Serial.print(" | ");
Serial.print(length); // Displays message length
Serial.print(" | ");
Serial.print("Data");
for (byte i = 0; i < length; i++) {
Serial.print(" | ");
if (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(data[i], HEX); // Displays message data
}
Serial.println();
}
Hope this helps a little
Just noticed how darned old this thread is!