I am using this device for my Arduino that connects to the OBD-II port of my car to get various information such as speed, rpm, etc. I am using this for a digital Nixie tube speedometer using the smart Nixie tube from a Kickstarter project.
I pass the information to the Nixie tubes through serial and get information from the OBD-II through serial as well. I am getting speed updates about every 20 seconds and that is incredibly slow when the device can supposedly update up to 100 times per second.
I originally was using an Arduino Uno and using software serial for the tubes, but I figured the slowdown was due to interupts interfering with the hardware serial, so I switched to the Arduino Mega 2560 to use a second hardware serial pin to hopefully fix the problem, yet the same issue is occurring.
Here is my code... There must be something I'm doing wrong. Serial2 is for the Nixie tubes.
#import <Arduino.h>
#include <OBD.h>
int ones = 0;
int tens = 0;
int kphValue = 0;
int mphValue = 0;
int rpmValue = 0;
String onesString;
String tensString;
String payloadString;
String rpmString;
COBD obd;
void setup(){
Serial2.begin(9600);
obd.begin();
//Initiate OBD-II connection until success
while (!obd.init()){
Serial2.print("$0,Y,Y,255,255,000,000$0,Y,Y,255,255,000,000!");
delay(1000);
Serial2.print("$0,Y,Y,000,000,000,000$0,Y,Y,000,000,000,000!");
delay(1000);
}
}
void loop(){
onesString = String(ones);
tensString = String(tens);
payloadString;
rpmString;
if(obd.read(PID_RPM, rpmValue)){
if (rpmValue < 3000){
rpmString =",N,N,255,000,255,000";
}
else if (rpmValue >= 5000){
rpmString = ",N,N,255,255,000,000";
}
else if (rpmValue >= 3000){
rpmString = ",N,N,255,255,030,000";
}
}
if (obd.read(PID_SPEED, kphValue)){
kphToMPH();
payloadString = "$" + onesString + rpmString + "$" + tensString + "rpmString" + "!";
Serial2.print(payloadString);
}
}
void splitDigits(int input_number)
{
ones = (input_number%10);
tens = ((input_number/10)%10);
}
void kphToMPH()
{
mphValue = kphValue * 0.621371;
splitDigits(mphValue);
}
EDIT: I am using the following library: https://github.com/stanleyhuangyc/ArduinoOBD
Serial2.available()
looks suspicious, what happens if you remove it? That calls checks for incoming data, not that it's OK to send data.