Go Down

Topic: CAN BUS J1708 (Read 510 times) previous topic - next topic

starinthe

Good Evening my friends,
   few days ago I have bought a CAN BUS Shield from Elecfreaks because I would try to read my boat engine values... One question is flying inside my head: how to know every sensor address?!? Because from serial i can read only HEX values!

Some of you got the same issue? :)

Thank you all!!!!
Cheers

TomGeorge

Hi,

Can you post a copy of your serial output?
Can you post a copy of your code?

Thanks.. Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

starinthe

Hi Tom,
   thank you for your reply. When I connect two wires (CAN L and CAN H) from engine to CAN-BUS Sparkfun shield the serial monitor returns me:

Code: [Select]

CAN-Bus Demo
[b]Can't init CAN[/b]
Please choose a menu option.
1.Speed
2.RPM
3.Throttle
4.Coolant Temperature
5.O2 Voltage
6.MAF Sensor


I've just tried different sketches but all give me "Can't init CAN"... :smiley-confuse:

TomGeorge

Hi,
Can you post the code you are using please?

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

starinthe

Followeing the code... Just changed the CANSPEED from 500 to 250 and 125... nothing changed.

Code: [Select]
#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
#include <Canbus.h>
char UserInput;
int data;
char buffer[456];  //Data will be temporarily stored to this buffer before being written to the file

//********************************Setup Loop*********************************//

void setup(){
Serial.begin(9600);
while(!Serial);
Serial.println("CAN-Bus Demo");

if(Canbus.init(CANSPEED_500))  /* Initialise MCP2515 CAN controller at the  specified speed */
  {
Serial.println("CAN Init ok");
  } else
  {
    Serial.println("Can't init CAN");
  }

  delay(1000);

Serial.println("Please choose a menu option.");
Serial.println("1.Speed");
Serial.println("2.RPM");
Serial.println("3.Throttle");
Serial.println("4.Coolant Temperature");
Serial.println("5.O2 Voltage");
Serial.println("6.MAF Sensor");

}



//********************************Main Loop*********************************//

void loop(){

while(Serial.available()){
   UserInput = Serial.read();

if (UserInput=='1'){
 data=Canbus.ecu_req(VEHICLE_SPEED, buffer);
 Serial.print("Vehicle Speed: ");
 Serial.print(data);
 Serial.println(" km/hr ");
 delay(1000);
}
else if (UserInput=='2'){
 data= Canbus.ecu_req(ENGINE_RPM, buffer);
 Serial.print("Engine RPM: ");
 Serial.print(data);
 Serial.println(" rpm ");
 delay(1000);

}
else if (UserInput=='3'){
 data= Canbus.ecu_req(THROTTLE, buffer);
 Serial.print("Throttle: ");
  Serial.print(data);
 Serial.println(" %% ");
 delay(1000);

}
else if (UserInput=='4'){
 data =Canbus.ecu_req(ENGINE_COOLANT_TEMP, buffer);
 Serial.print("Engine Coolant Temp: ");
 Serial.print(data);
 Serial.println(" degC");
 delay(1000);

}
else if (UserInput=='5'){
 data=Canbus.ecu_req(O2_VOLTAGE, buffer);
 Serial.print("O2 Voltage: ");
 Serial.print(data);
 Serial.println(" V");
 delay(1000);

}
else if (UserInput=='6'){
 data=Canbus.ecu_req(MAF_SENSOR, buffer);
 Serial.print("MAF Sensor: ");
 Serial.print(data);
 Serial.println(" g/s");
 delay(1000);

}
else
{
  Serial.println(UserInput);
  Serial.println("Not a valid input.");
  Serial.println("Please enter a valid option.");
}

}
}

Go Up