Hello everyone, like many people I'm relatively new to arduino - done several tutorials a couple of my own projects (fan controller for my car, an alarm clock, servo control stuff - just random stuff like that ) but I'm having some issues with my current project and hoping maybe someone can offer some insight to why things aren't working like I think they should. I'm not sure if my problem is software library stuff (which I admit I don't totally understand).
Basically, there's a consult library out there provided by a user named Crim - he claims it works with his arduino and an LCD screen (at least it did at one point). He's been off here for a couple of years and I'm working on something similar and trying to use his (slightly modified) library. There's also some info on the Nissan Consult interface provided by PLMS Development about address requests that return certain values.
The link to his library is: GitHub - Crim/Arduino-Nissan-Consult-Library
The link(s) to the PLMS info is: http://www.plmsdevelopments.com/diy_consult.htm <<-- there they have listed the protocol, a generic ECU data register lookup table, and an interface schematic for the cable.
On the library files, I did go through and modify all of the WProgram.h references in the files to Arduino.h to support the new 1.0+ IDE. I have been trying to simply get a modified version of his program to run (modified to use a serial LCD in place of the liquid crystal library). My code is below. My serial LCD will display the stuff correctly, and it will say "ECU iniitallized" (the first booleen returning true) but after that will not read any further info from the ECU. The code is currently set up to display just the coolant temp and RPM.
My hardware setup is a nano running the serial LCD on pin 11, and the hardware serial is used to connect to an RS232-TTL adapter from NKC Electronics ( this one - http://www.nkcelectronics.com/RS232-to-TTL-converter-board-DTE-with-Male-DB9-33V-to-5V_p_369.html ). This is connected to a consult to serial cable that I purchased from amazon a while ago.
The consult cable works when used with a Serial-USB adapter and a computer to access the information. I have tried numerous programs with the consult cable + serial-usb adapter and it works fine when connected this way. My issue seems to be when the arduino tries to connect to the ecu via the consult cable. The program will work fine up to the point it tries to get the part num, and it fails. It also fails on the coolant temp and RPM.
Here is my code (really just modified code from crim's example) - note that it calls the library files listed above:
#include <Consult.h>
#include <ConsultConversionFunctions.h>
#include <ConsultErrorCode.h>
#include <ConsultRegister.h>
#include <SoftwareSerial.h>
//sets up the LCD using softwareSerial and connected to pin 11.
SoftwareSerial lcd=SoftwareSerial(10, 11); // RX, TX for LCD
Consult myConsult = Consult(); //sets up myConsult var.
char ESC = 0xFE; //lcd hex command for entering other screen commands
char line = 0x45; //lcd hex command for cursor position - used to select where to print.
char clr=0x51; //lcd hex command for clear screenclear
void setup() {
// Tell Consult which Serial object to use to talk to the ECU
myConsult.setSerial(&Serial);
// We want MPH and Farenheit, so pass in false
// If you want KPH or Celcius, pass in true
myConsult.setMetric(false);
//start LCD
lcd.begin(9600);
// Set LCD Contrast
lcd.write(ESC);
lcd.write(0x52); //LCD hex command for contrast
lcd.write(40); // writing the value for contrast (0-40)
// Set Backlight
lcd.write(ESC);
lcd.write(0x53); //LCD hex command for brightness
lcd.write(7); // writing value for backlight brightness (0-8)
//clear Screen
lcd.write(ESC);
lcd.write(clr); //LCD command to clear screen and return to position 0
// Some output on the LCD
lcd.print("Consult");
lcd.write(ESC);
lcd.write(line);
lcd.write(0x14); //hex location for line 3
lcd.print("Starting...");
}
void loop() {
// Attempt to initialize consult <---> ecu conversation
// Keep re-trying until it initializes
while (myConsult.initEcu() == false) {
// Failed to connect
delay(1000);
// Output to LCD
lcd.write(ESC); //clear screen
lcd.write(clr);
lcd.write(ESC);
lcd.write(line);
lcd.write(0x28); //line2
lcd.print("Failed to connect!!!"); //print on line 2
}
// Output to LCD once connected (initEcu returns true)
lcd.write(ESC);//clear screen
lcd.write(clr);
lcd.print("Connected to ECU!");
// Try to pull ECU Part Number, 11 chars + 1 null terminator
char partNumber[12];
if (myConsult.getEcuPartNumber(partNumber)) {
// Pulled ECU PartNumber, it is now stored
// in partNumber variable!
// Output to LCD
lcd.print(partNumber);
}
else {
// Failed to retrieve ECU Part Number
// Output to LCD
lcd.print("Failed to get partnum");
}
// Small Pause
delay(2000);
// Clear our LCD
lcd.write(ESC);
lcd.write(clr);
// Attempt to read Coolant Temp,
// Coolant temp only spans a single register, pass in ECU_REGISTER_NULL for the LSB register address
int coolantTemp;
if (myConsult.getRegisterValue(ECU_REGISTER_COOLANT_TEMP, ECU_REGISTER_NULL, &coolantTemp)) {
// coolantTemp now contains the temp, but we need to convert it to something human readable
coolantTemp = ConsultConversionFunctions::convertCoolantTemp(coolantTemp);
// Output to lcd - line 1
lcd.print("Coolant:");
lcd.print(coolantTemp);
}
else {
// Failed to read coolant temp
// output to LCD
lcd.print("Failed read coolant");
}
// Attempt to read Tachometer,
// This register spans two registers, first pass in MSB, then LSB
int tach;
if (myConsult.getRegisterValue(ECU_REGISTER_TACH_MSB, ECU_REGISTER_TACH_LSB, &tach)) {
// tach now contains the tach value, but we need to convert it to something human readable
tach = ConsultConversionFunctions::convertTachometer(tach);
// Output to LCD - line 2
lcd.write(ESC);
lcd.write(0x45);
lcd.write(0x40);
lcd.print("Tach:");
lcd.print(tach);
}
else {
// Failed to read tach
// Output to LCD - line 2
lcd.write(ESC);
lcd.write(0x45);
lcd.write(0x40);
lcd.print("Failed read tach");
}
// Small pause
delay(2000);
//clear screen
lcd.write(ESC);
lcd.write(clr);