Hey,
after testing the OBD-II UART Adapter from Freematics with no results, i tried the CAN-Bus Shield by Sparkfun. I've written the code using the knowdegle i got from the example codes.
Somehow the serial monitor always prints 0 rpm while having 1000rpm showing on the tachometer of my 2008 Nissan Qashqai.
Here's the code:
#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
#include <Wire.h>
int kmh;
int hkmh;
int zkmh;
int ekmh;
int rpm;
int trpm;
int hrpm;
int zrpm;
int erpm;
char buffer[512];
void setup() {
if(Canbus.init(CANSPEED_500)) {
Serial.println("CAN-Bus-Verbindung erfolgreich");
}
else {
Serial.println("CAN-Bus-Verbindung fehlgeschlagen");
}
Serial.begin(9600);
Serial.println("Verbindung zu 7-Seg-Anzeige");
Wire.begin();
Wire.setClock(100000);
Serial.println("Setup abgeschlossen");
}
void loop() {
Serial.println("Updating");
Wire.beginTransmission(0x71);
Wire.write(0x76);
Wire.endTransmission();
/*Canbus.ecu_req(VEHICLE_SPEED,buffer);
kmh = atoi(buffer);
hkmh = kmh/100;
zkmh = (kmh - hkmh*100)/10;
ekmh = (kmh -(hkmh*100) - (zkmh*10)); */
Canbus.ecu_req(ENGINE_RPM, buffer)
Serial.println(buffer);
/*rpm = atoi(buffer);
trpm = rpm/1000;
hrpm = (rpm - (trpm*1000))/100;
zrpm = (rpm - (trpm*1000)-(hrpm*100))/10;
erpm = (rpm - (trpm*1000)-(hrpm*100)-(zrpm*10));*/
delay(500);
}
The calculation stuff is for splitting the value into single numbers to print them on a 7-segment-display. I've excluded them because i tried to print the value in the serial monitor.
I'd love to see some friendly advices,
Sebastian Huber.