Yes im aware of the hardware serial ports, just got frustrated trying to dechipher what pins and how to use them exactly as the esp dev board pins are not in order and in general a cluster fuck to wade through😅 i plan to work that out and switch to hardware at a later date, but its only 9600 baud so no problems as of now. Yes u understand correct. Ill go copy some code. Im not sure how to post it as I've seen ppl be scolded for copy paste😂
i cant reply for 17 hours cus new member. heres the code i quickly modified to output a triplet. ill have to go back through and add a function to show the other values if i request them.
```
#include "BluetoothSerial.h"
#include "ELMduino.h"
#include <SoftwareSerial.h>
#define ELM_PORT SerialBT
#define DEBUG_PORT Serial
SoftwareSerial cereal(35, 34);
SoftwareSerial wb (18, 19);
BluetoothSerial SerialBT;
ELM327 myELM327;
int set_point=6000;
bool Set=false;
bool DATA_LOGGER = false;
const int TIME_OUT = 2000;
const bool HALT_ON_FAIL = false;
typedef enum
{ ENG_RPM, SPEED, MAP, SPARK, TPS, TEMP, AFR, END}
obd_pid_states;obd_pid_states obd_state = ENG_RPM;
int commands;
float rpm = 0;
float mph = 0;
float mapp = 0;
float spark = 0;
float tps = 0;
float temp = 0;
bool button = false;
void setup()
{
pinMode (35, INPUT);
pinMode (25, INPUT_PULLUP);
pinMode (26, INPUT_PULLUP);
pinMode (27, INPUT_PULLUP);
pinMode (33, INPUT_PULLUP);
pinMode (22, OUTPUT);
cereal_overide(); ///
DEBUG_PORT.begin(115200);
Serial.println("Welcome Back");
cereal.begin(9600);
cereal.println("Welcome Back");
Serial.println("Initiating ELM327");
elm_init();
print_tasks();
}
//ALL TASKS ON TASK LIST WORK!!!(saved as DO_NOT_TOUCH)
void loop()
{
cereal_overide(); /////modified
if (DATA_LOGGER==false)
{
listen_linda();
}
if (DATA_LOGGER==true)
{
data_log();
}
if (button==true)
{
tewZ();
}
}
//DYSFUNCTIONS()
void tewZ() //WORKS IN SKETCH
{
Serial.println("what rpm sir?");
for (Set==false;
{
if (!Serial.available())
{
set_point=6000;
}
if (Serial.available()>0)
{
set_point=Serial.parseInt();
Serial.print("yes Sir");
Serial.println(set_point);
Set=true;
break;
}
}
for (button==true;
{
int button_off=Serial.read();
rpm = myELM327.rpm();
if (myELM327.nb_rx_state == ELM_SUCCESS)
{
Serial.print("RPM: ");
Serial.println(rpm);
if (rpm>set_point)
{
digitalWrite(22, HIGH);
Serial.println("pop pop");
}
if(rpm<set_point)
{
digitalWrite(22, LOW);
}
}
if (button_off=='R')
{
Serial.println("Yes Sir");
Serial.println("no more pop pop");
Set=false;
break;
}
}
}
void data_log() //ON/OFF WORKS FLAWLESSLY, DEBUG MODE OFF
{
switch (obd_state)
{
obd_state=ENG_RPM;
case ENG_RPM:
{
rpm = myELM327.rpm();
if (myELM327.nb_rx_state == ELM_SUCCESS)
{
//Serial.print("RPM: ");
//Serial.println(rpm);
obd_state = SPEED;
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
{
myELM327.printError();
obd_state = SPEED;
}
break;
}
case SPEED:
{
mph = myELM327.mph();
if (myELM327.nb_rx_state == ELM_SUCCESS)
{
// Serial.print("MPH: ");
//Serial.println(mph);
obd_state = MAP;
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
{
myELM327.printError();
obd_state = MAP;
}
break;
}
case MAP:
{
mapp = myELM327.manifoldPressure();
if (myELM327.nb_rx_state == ELM_SUCCESS)
{
// Serial.print("MAP: ");
//Serial.println(mapp);
obd_state = SPARK;
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
{
myELM327.printError();
obd_state = SPARK;
}
break;
}
case SPARK:
{
spark = myELM327.timingAdvance();
if (myELM327.nb_rx_state == ELM_SUCCESS)
{
//Serial.print("SPARK: ");
// Serial.println(spark);
obd_state = TPS;
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
{
myELM327.printError();
obd_state = TPS;
}
break;
}
case TPS:
{
tps = myELM327.throttle();
if (myELM327.nb_rx_state == ELM_SUCCESS)
{
// Serial.print("TPS: ");
// Serial.println(tps);
obd_state = TEMP;
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
{
myELM327.printError();
obd_state = TEMP;
}
break;
}
case TEMP:
{
float tempC = myELM327.engineCoolantTemp();
temp = (tempC*9/5)+ 32;
if (myELM327.nb_rx_state == ELM_SUCCESS)
{
//Serial.print("TEMP: ");
//Serial.println(temp);
obd_state = AFR;
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
{
myELM327.printError();
obd_state = AFR;
}
break;
}
case AFR:
{
if (wb.available()>0)
{
// Serial.print("AFR:");
// Serial.print(wb.parseFloat()/10);
// Serial.println("LAMBDA");
}
log_data();
obd_state=ENG_RPM;
break;
}
}
}
void listen_linda() //ALL COMMANDS WORK
{
switch(commands)
{
case 'U':
{
Serial.println("Yes Sir");
Serial.println("UNLOCKED");
analogWrite (26, 0);
delay(1000);
analogWrite(26, 255);
digitalRead(26);
break;
}
case 'L':
{
Serial.println("Yes Sir");
Serial.println("LOCKED");
analogWrite (25, 0);
delay(1000);
analogWrite (25, 255);
digitalRead(25);
break;
}
case 'P':
{
Serial.println("Yes Sir");
Serial.println("PANIC");
analogWrite (27, 0);
delay(1000);
analogWrite (27, 255);
digitalRead(27);
break;
}
case 'S':
{
Serial.println("Yes Sir");
Serial.println("Starting");
analogWrite (33, 0);
delay(8000);
analogWrite (33, 255);
digitalRead(33);
Serial.println("Running");
break;
}
case 'H': //HOLD
{
Serial.println("Yes Sir");
Serial.println("All functions paused for 2 mins");
delay(120000);
break;
}
case 'E': //END DATALOG
{
DATA_LOGGER=false;
Serial.println("Yes Sir");
Serial.println("Log Ended");
break;
}
case 'D': //DATALOG
{
wb_init();
DATA_LOGGER=true;
break;
}
case 'T': //TASK LIST
{
Serial.println("Yes Sir");
print_tasks();
break;
}
case 'B': //BUTTON
{
Serial.println("Yes Sir");
Serial.println("1TewZ");
tewZ();
break;
}
case 'R': //RELEASE BUTTON
{
Serial.println("Yes Sir");
Serial.println("No more pop pop");
button=false;
break;
}
}
}
void wb_init() //WORKS
{
wb.begin(9600);
if (wb.available()>0)
{
Serial.println("Wideband online");
}
if (!wb.available()>0)
{
Serial.println("wideband INOP");
}
}
void elm_init() //WORKS,BTSERIAL,DEBUG OFF
{
SerialBT.setPin("1234");
ELM_PORT.begin("ArduHUD", true);
if (!ELM_PORT.connect("OBDII"))
{
DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 1");
while(1);
}
if (!myELM327.begin(ELM_PORT, false, 2000))
{
Serial.println("Couldn't connect to OBD scanner - Phase 2");
while (1);
}
Serial.println("Connected to ELM327");
}
void print_tasks() //WORKS
{
Serial.println("What can i do for you?");
Serial.println("'D': DATALOG");
Serial.println("'E': END DATALOG");
Serial.println("'H': HOLD");
Serial.println("'L': LOCK DOORS");
Serial.println("'U': UNLOCK DOORS");
Serial.println("'S': REMOTE START");
Serial.println("'P': PANIC");
Serial.println("'T': TASK LIST");
Serial.println("'B': BUTTON");
Serial.println("'R': RELEASE BUTTON");
}
void cereal_overide() //NEEDS TO BE TESTED
{
if (cereal.available()>0)
{
commands=cereal.read();
}
if (Serial.available()>0)
{
commands=Serial.read();
}
int dat_duh=Serial.read();
cereal.print(dat_duh);
cereal.println();
}
void log_data()
{
Serial.print("AFR:");
Serial.print(wb.parseFloat()/10);
Serial.print("RPM: ");
Serial.print(rpm);
Serial.print("MAP: ");
Serial.println(mapp);
}
type or paste code here