Torque

Forums

Forums

Guest  

Show or hide header
Welcome Guest, posting in this forum require registration.




Torque » Torque OBD ECU Scanner » Torque Discussion / Ideas » Torque Pro, ESP32 Ardunio and a EGT sensor

Pages: [1]
Author Topic: Torque Pro, ESP32 Ardunio and a EGT sensor
heist
Member
Posts: 2
Post Torque Pro, ESP32 Ardunio and a EGT sensor
on: October 21, 2022 (GMT)

Hi All,

im trying ot get an ESP32 setup with a thermocouple (MAX31855) and im having no luck at all, below is my code which wont compile, can anyone tell me why?

Ive got other code that i print to serial and can see the thermocouple working fine, just struggling with the connection and readout to Torque.

Im not a programmer at all, but can understand things.

#include "SPI.h"
#include "Adafruit_MAX31855.h"
#include "BluetoothSerial.h"

// ******INPUTS******
   

const String ATE = "ATE";                //Echo off/on
const String ATI = "ATI";                //Version id
const String ATZ = "ATZ";                //Reset
const String ATS = "ATS";                //Set protocol X
const String ATH = "ATH";                //Headers off / on
const String ATL = "ATL";                //Linefeeds off/on
const String ATM = "ATM";                //Memory off/on
const String GETDEFINITIONS = "GETDEFINITIONS"; //Get sensor definitions
const String GETCONFIGURATION = "GETCONFIGURATION"; //Get config of app (hide car sensors, devices sensors, etc)
const String GETSENSORS = "G";           //Get sensor values, one shot.
const String SETSENSOR = "S";            //Set a sensor value
const String PROMPT = ">";
const String CANBUS = "6";               //canbus 500k 11 bit protocol id for elm.
const String ATDPN = "ATDPN";
const String ATDESC = "AT@1";
const String ATAT = "ATAT";
const String LF = "\n";
const String VERSION = "Torque Protocol Interface v0.0.1"; //Don't change this - it's used by Torque so it knows what interface it is connected to
const String VERSION_DESC = "Torque For Android Protocol Interface";
const String ANALOG = "a";
const String DIGITAL = "d";
const String IS_INPUT = "i";
const String IS_OUTPUT = "o";
String fromTorque = "";
int test=75;



/**
 * Array of sensors we will advertise to Torque so it can automatically import them. Using strings
 * Stucture is:
 *  
 *  Arduino Pin, Arduino pin type, Input/Ouput, Default value(if output), ShortName, Long name, units, minimum value, maximum value
 *  
 *  Caveats:  Don't use a '>' in any of the names, 
 *            Update 'sensorsSize' with the number of elements.
 *            Analog outputs are PWM on digital pins.
 *  
 */
const String sensors[] = {
                    "0",  ANALOG, IS_INPUT,  "0",    "EGT",  "Exhaust Gas Temperature",  "C",  "0",  "900",
                    }; 
const int SENSORSSIZE = sizeof(sensors);

// Default connection is using software SPI, but comment and uncomment one of
// the two examples below to switch between software SPI and hardware SPI:

// Example creating a thermocouple instance with software SPI on any three
// digital IO pins.
#define MAXDO   5
#define MAXCS   18
#define MAXCLK  23

// initialize the Thermocouple
Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;

void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32test"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");

  while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc

  SerialBT.println("MAX31855 test");
  // wait for MAX chip to stabilize
  delay(500);



// Init the pins 
    initSensors();
             }

// ******MAIN PROGRAM LOOP - RUNS CONTINUOUSLY******
void loop() {

//This is used for testing the Torque App  
  if (test > 100){
    test = 0;
    delay(300);}
   
  delay(25); 
    if (test <= 100){
  test=test+1;}

//Grab data from the bluetooth module, parse it.
  if (SerialBT.available()) {
     char c = SerialBT.read(); 
     if ((c == '\n' || c == '\r') && fromTorque.length() > 0) {
        fromTorque.toUpperCase();
        processCommand(fromTorque);
        fromTorque = "";
     } else if (c != ' ' && c != '\n' && c !='\r') {
         //Ignore spaces.
         fromTorque += c; 
     }
  }

/**
 * Parse the commands sent from Torque
 */
void processCommand(String command) {

   // Debug - see what torque is sending on your serial monitor
   SerialBT.println(command);

   // Simple command processing from the app to the arduino..
   if (command.equals(ATZ)) {
       initSensors(); // reset the pins
       SerialBT.print(VERSION);
       SerialBT.print(LF); 
       SerialBT.print(OK);
   } else if (command.startsWith(ATE)) {
       SerialBT.print(OK); 
   } else if(command.startsWith(ATI)) {
       SerialBT.print(VERSION);
       SerialBT.print(LF);
       SerialBT.print(OK);
   } else if (command.startsWith(ATDESC)) {
       SerialBT.print(VERSION_DESC); 
       SerialBT.print(LF);
       SerialBT.print(OK);
   } else if (command.startsWith(ATL)) {
       SerialBT.print(OK);
   } else if (command.startsWith(ATAT)) {
       SerialBT.print(OK);
   } else if (command.startsWith(ATH)) {
       SerialBT.print(OK);
   } else if (command.startsWith(ATM)) {
       SerialBT.print(OK);
   } else if (command.startsWith(ATS)) {
       // Set protocol
       SerialBT.print(OK);
   } else if (command.startsWith(ATDPN)) {
       SerialBT.print(CANBUS);
   } else if (command.startsWith(GETDEFINITIONS)) {
       showSensorDefinitions();
   } else if (command.startsWith(GETSENSORS)) {
       getSensorValues();
   } else if (command.startsWith(GETCONFIGURATION)) {
       getConfiguration();
   } else if (command.startsWith(SETSENSOR)) {
       setSensorValue(command);
   }
  SerialBT.print(LF); 
   SerialBT.print(PROMPT);      


/**
 * List all the sensors to the app
 */
void showSensorDefinitions() {
   int id = 0;
   for (int i = 0; i < SENSORSSIZE/9; i++) {
      for (int j = 0; j < 9; j++) {
         id = (i*9)+j;
         SerialBT.print(sensors[id]);

         if (id+1 < SENSORSSIZE) {
            SerialBT.print(',');
         }
      }
      SerialBT.print(LF);
   }
}

/**
 * Dump sensor information for input sensors.
 * 
 * Format to Torque is id:type:value
 */
void getSensorValues() {
   void getSensorValues() {
   for (int i = 0; i < SENSORSSIZE/9; i++) {
      int group = i * 9;
      int id = sensors[group].toInt();
      String type = sensors[group+1];
      boolean isOutput = sensors[group+2].equals(IS_OUTPUT);
  SerialBT.println(SENSORSSIZE);
  SerialBT.println(group);
  SerialBT.println(id);
      if (!isOutput) {
        if (id == 1){
         SerialBT.print(id);
         SerialBT.print(":");
         SerialBT.print(type);
         SerialBT.print(":");
         if (type.equals(ANALOG)) {
           SerialBT.print(thermocouple.readInternal());}
         else if (type.equals(DIGITAL)) {
           SerialBT.print(thermocouple.readInternal());}
      }
   }
}

/**
 * Sets a sensors value
 */
void setSensorValue(String command) {
  int index = command.indexOf(":");
  int id = command.substring(1,index).toInt();
  int value = command.substring(index+1, command.length()).toInt();
 
  for (int i = 0; i < SENSORSSIZE/9; i++) {
     int group = i * 9;
     int sid = sensors[group].toInt();
     boolean isOutput = sensors[group+2].equals(IS_OUTPUT);
     if (isOutput) {

       if (sid == id) {
 
          String type = sensors[group+1];
          if (type.equals(ANALOG)) {
            analogWrite(sid, constrain(value,0,255));
          } else if (type.equals(DIGITAL)) {
            digitalWrite(sid, value > 0 ? HIGH: LOW);
          }
          break;
       }
    }
  }
}

/** 
 *  Init the sensor definitions (input/output, default output states, etc)
 */
void initSensors() {
   for (int i = 0; i < SENSORSSIZE/9; i++) {
      int group = i * 9;
      int id = sensors[group].toInt();
      String type = sensors[group+1];
      boolean isOutput = sensors[group+2].equals(IS_OUTPUT);
      int defaultValue = sensors[group+3].toInt();
    

      if (isOutput) {
         if (type.equals(ANALOG)) {
             pinMode(id, OUTPUT);
             analogWrite(id, constrain(defaultValue, 0, 255));
         } else if (type.equals(DIGITAL)) {
             pinMode(id, OUTPUT);
             digitalWrite(id, defaultValue > 0 ? HIGH : LOW);
         }
      }
   }
}

void getConfiguration() {
  SerialBT.print(CONFIGURATION);
}



   }


        
}
moreause
Member
Posts: 637
Post Re: Torque Pro, ESP32 Ardunio and a EGT sensor
on: October 23, 2022 (GMT)

i haven’t check the code
but when i use the Arduino compiler most of the time
it tell you where the bug is

does it even run ??

do you have in your library the file your trying to include at the beginning ??

heist
Member
Posts: 2
Post Re: Torque Pro, ESP32 Ardunio and a EGT sensor
on: October 26, 2022 (GMT)

<div class=”quote”><p>Quote from moreause on October 23, 2022
i haven’t check the code
but when i use the Arduino compiler most of the time
it tell you where the bug is

does it even run ??

do you have in your library the file your trying to include at the beginning ??
</p></div>

Yep libraries all installed. this is the error list…

Arduino: 1.8.19 (Windows 10), Board: “DOIT ESP32 DEVKIT V1, 80MHz, 921600, None”

In file included from C:\Users\Anthony\AppData\Local\Arduino15\packages\esp32\hardware\esp32.0.6\cores\esp32/esp32-hal.h:53:0,

from C:\Users\Anthony\AppData\Local\Arduino15\packages\esp32\hardware\esp32.0.6\cores\esp32/Arduino.h:35,

from sketch\Patrol_Torque.ino.cpp:1:

C:\Users\Anthony\AppData\Local\Arduino15\packages\esp32\hardware\esp32.0.6\cores\esp32/esp32-hal-gpio.h:48:27: error: expected unqualified-id before numeric constant

#define ANALOG 0xC0

^

C:\Users\Anthony\Documents\Arduino\Patrol_Torque\Patrol_Torque.ino:27:14: note: in expansion of macro ‘ANALOG’

const String ANALOG = “a”;

^

Patrol_Torque:49:21: error: conversion from ‘int’ to ‘String’ is ambiguous

};

^

In file included from C:\Users\Anthony\AppData\Local\Arduino15\packages\esp32\hardware\esp32.0.6\cores\esp32/Arduino.h:146:0,

from sketch\Patrol_Torque.ino.cpp:1:

C:\Users\Anthony\AppData\Local\Arduino15\packages\esp32\hardware\esp32.0.6\cores\esp32/WString.h:59:9: note: candidate: String::String(const __FlashStringHelper*) <near match>

String(const __FlashStringHelper *str);

^

C:\Users\Anthony\AppData\Local\Arduino15\packages\esp32\hardware\esp32.0.6\cores\esp32/WString.h:59:9: note: conversion of argument 1 would be ill-formed:

Patrol_Torque:49:21: error: invalid conversion from ‘int’ to ‘const __FlashStringHelper*’ [-fpermissive]

};

^

In file included from C:\Users\Anthony\AppData\Local\Arduino15\packages\esp32\hardware\esp32.0.6\cores\esp32/Arduino.h:146:0,

from sketch\Patrol_Torque.ino.cpp:1:

C:\Users\Anthony\AppData\Local\Arduino15\packages\esp32\hardware\esp32.0.6\cores\esp32/WString.h:57:9: note: candidate: String::String(const char*) <near match>

String(const char *cstr = “”);

^

C:\Users\Anthony\AppData\Local\Arduino15\packages\esp32\hardware\esp32.0.6\cores\esp32/WString.h:57:9: note: conversion of argument 1 would be ill-formed:

Patrol_Torque:49:21: error: invalid conversion from ‘int’ to ‘const char*’ [-fpermissive]

};

^

C:\Users\Anthony\Documents\Arduino\Patrol_Torque\Patrol_Torque.ino: In function ‘void setup()’:

Patrol_Torque:84:17: error: ‘initSensors’ was not declared in this scope

initSensors();

^

C:\Users\Anthony\Documents\Arduino\Patrol_Torque\Patrol_Torque.ino: In function ‘void loop()’:

Patrol_Torque:104:34: error: ‘processCommand’ was not declared in this scope

processCommand(fromTorque);

^

Patrol_Torque:115:37: error: a function-definition is not allowed here before ‘{‘ token

void processCommand(String command) {

^

Patrol_Torque:271:1: error: expected ‘}’ at end of input

}

^

exit status 1

conversion from ‘int’ to ‘String’ is ambiguous

This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.

moreause
Member
Posts: 637
Post Re: Torque Pro, ESP32 Ardunio and a EGT sensor
on: October 26, 2022 (GMT)

at first glance you seen to have to variable issue

at first you #define ANALOG… in short replace all reference of that variable to the current value and compile the program

but somewhere is you say you say ANALOG is now equal to text

just wondering if it’s you program and some of your library that are using the same name and create a bug

it’S been a while some variable a local but some other are good in all the program ..

and some other error seem to be off the same number variable used for a string

Pages: [1]
WP-Forum by: Fredrik Fahlstad, Version: 2.4
Page loaded in: 0.016 seconds.

  Follow me on twitter