Torque

Forums

Forums

Guest  

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




Torque » Torque OBD ECU Scanner » Torque Discussion / Ideas » Arduino internal variables

Pages: 1 [2] 3
Author Topic: Arduino internal variables
hugovw1976
Member
Posts: 19
Post Re: Arduino internal variables
on: August 17, 2016 (GMT)

Thanks, I can compile and upload to mi arduino but still can´t see any data on Torque pro app.
Silly question: in torque app I need special configuration to see the arduino sensors?

1989Marathon
Member
Posts: 18
Post Re: Arduino internal variables
on: August 17, 2016 (GMT)

The code I posted is for use with an Arduino Mega2560.
It uses pins 10,11 for serial to the Bluetooth.
Other boards use 2,3 as the code suggests.

You will need the HC-05 or HC-06 Bluetooth adapter paired to your phone/tablet. Set the OBD2 adapter in Torque to HC-05 or HC-06, whichever is paired. Connection Type should be set to Bluetooth. Then Add Display in Torque. Find the variable in the list in Torque.

hugovw1976
Member
Posts: 19
Post Re: Arduino internal variables
on: August 18, 2016 (GMT)

Quote from 1989Marathon on August 17, 2016
The code I posted is for use with an Arduino Mega2560.
It uses pins 10,11 for serial to the Bluetooth.
Other boards use 2,3 as the code suggests.

You will need the HC-05 or HC-06 Bluetooth adapter paired to your phone/tablet. Set the OBD2 adapter in Torque to HC-05 or HC-06, whichever is paired. Connection Type should be set to Bluetooth. Then Add Display in Torque. Find the variable in the list in Torque.

All ready connected to HC-05 Bluetooth and Torque it’s connected but I can’t see any data.

Update: This part it’s why can’t see sensors.

Thanks rigth now it’s working.

1989Marathon
Member
Posts: 18
Post Re: Arduino internal variables
on: August 18, 2016 (GMT)

What Arduino board are you using?
When it is working, you should be able to “Add Display” and see “Arduino1” – “Arduino8” in the list of available sensors.

hugovw1976
Member
Posts: 19
Post Re: Arduino internal variables
on: August 18, 2016 (GMT)

Quote from 1989Marathon on August 18, 2016
What Arduino board are you using?

Arduino Mega 2560, Rigth now it’s working, I fail to add Display and slect the sensor. But now it’s working.

Thanks for all.

1989Marathon
Member
Posts: 18
Post Re: Arduino internal variables
on: August 18, 2016 (GMT)

No problem. It’s an awesome App!!!

1kzte
Member
Posts: 12
Post Re: Arduino internal variables
on: March 4, 2017 (GMT)

I am having this same problem – where I cannot see the “Arduino 1-8” in the new device list.

This is my first time playing with an Arduino, so I am probably missing something simple.

I have a UNO R3 board
HC-06 Bluetooth
I changed softwareserial to pins 2,3:
SoftwareSerial mySerial(2,3); // Most other boards can use pins 2 and 3
I have Digital 2 connected to HC-06 TX
Digital 3 connected to HC-06 RX

My HC-06 is communicating (solid red light), and I can connect on my tablet, however, there is no option to select the new sensors…

Just to make sure I’m doing this right, I am:
Main screen => select “Realtime Information”
Press down on the screen, then select “add display”
Pick “Dial (Needle)”
Then I see the list of “add sensor”
But I don’t see “Arduino 1-8” anywhere in the list??

Anyone help a newbie out!!!??? I really want to make this work!

1kzte
Member
Posts: 12
Post Re: Arduino internal variables
on: March 7, 2017 (GMT)

Anyone??? Please!!

hamed-pc
Member
Posts: 19
Post Re: Arduino internal variables
on: March 21, 2017 (GMT)

Hi Good day
i need know how to connect to the K line on the diagnostic connector? I mean With Pin on the Arduino connect to the K line on my Care?
I have Arduino Uno R3 And Bluetooth Module HC-05

Can i Connect to my Care and See live data of sensor?

1kzte
Member
Posts: 12
Post Re: Arduino internal variables
on: March 25, 2017 (GMT)

I am trying to connect sensors, through an Arduino Uno and HC-06 bluetooth, to an android based head unit.

I am having no luck. The manufacturer of the head unit says that it does not communicate with SPP.

If I were to get a different bluetooth, such as HC-05 and use in master mode, or some other bluetooth sender, would that work?

The head unit does have USB ports. How do I connect Torque to the Arduino via USB? What needs to be changed in the basic code provided on the Torque/Arduino site? Right now its establishing pins 2,3 as the output pins to the HC-06.

When I plug the Arduino into the USB of the head unit, it doesn’t pick up the sensors. Is there anything I need to modify in the code so that Torque picks up the sensors?

Below is my code currently:

Thanks!

———————————

#include
#include

/**
* Torque for Android Arduino sample program by Ian Hawkins http://torque-bhp.com/
* You will require Torque Pro 1.8.82 or newer
*
* Setup the bluetooth device as an OBD2 adapter in Torque. Torque will automatically recognise the Arduino and will
* import sensors automatically based on the configuration settings below.
*
* This code is released under the LGPL v2
*
* This has been tested on the Arduino UNO board
*
* Connect pins 2 and 3 to your bluetooth device’s rx and tx pins (2 to txd on bluetooth device, 3 to rxd)
*
* This code allows you to gather sensors from the arduino to display in the app. It can be extended to whatever you want.
*/

// Various constants.
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 OK = “OK”;
const String ANALOG = “a”;
const String DIGITAL = “d”;
const String IS_INPUT = “i”;
const String IS_OUTPUT = “o”;

String fromTorque = “”;

/**
* 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 int SENSORSSIZE = 9 * 3; // each line is 9 attributes, and we have 3 lines.
const String sensors[SENSORSSIZE] = {
“0”, ANALOG, IS_INPUT, “-“, “Boost”, “Boost”, “PSI”, “0”, “5”,
“1”, ANALOG, IS_INPUT, “-“, “EGT”, “Temp”, “F”, “0”, “5”,
“4”, DIGITAL,IS_OUTPUT, “0”, “Dout1”, “Digital Out 1”, “bit”, “0”, “1”
};
/**
* Configuration directives for the app to hide various things. Comma separated. Remove to enable visibility in Torque
* – handy if your project isn’t car related or you want to make sensor selections relatively easy.
*
* Supported types:
* NO_CAR_SENSORS – hide any car related sensors
* NO_DEVICE_SENSORS – hide any device (phone) sensors
*
*/
const String CONFIGURATION = “NO_CAR_SENSORS,NO_DEVICE_SENSORS”;

// Setup bluetooth module on pins 2 and 3 (you can’t use these digial pins in the sensor list or it’ll break comms)
SoftwareSerial mySerial(2,3); // Most other boards can use pins 2 and 3
//SoftwareSerial mySerial(8,9); // Use pins 8,9 on Arduino Micro

void setup() {
// Init the pins
initSensors();
Serial.begin(9600); // the GPRS baud rate
delay(600);
mySerial.begin(9600);
}

void loop() {

/**
* Grab data from the bluetooth module, parse it.
*/
if (mySerial.available()) {
char c = mySerial.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
Serial.println(command);

// Simple command processing from the app to the arduino..
if (command.equals(ATZ)) {
initSensors(); // reset the pins
mySerial.print(VERSION);
mySerial.print(LF);
mySerial.print(OK);
} else if (command.startsWith(ATE)) {
mySerial.print(OK);
} else if(command.startsWith(ATI)) {
mySerial.print(VERSION);
mySerial.print(LF);
mySerial.print(OK);
} else if (command.startsWith(ATDESC)) {
mySerial.print(VERSION_DESC);
mySerial.print(LF);
mySerial.print(OK);
} else if (command.startsWith(ATL)) {
mySerial.print(OK);
} else if (command.startsWith(ATAT)) {
mySerial.print(OK);
} else if (command.startsWith(ATH)) {
mySerial.print(OK);
} else if (command.startsWith(ATM)) {
mySerial.print(OK);
} else if (command.startsWith(ATS)) {
// Set protocol
mySerial.print(OK);
} else if (command.startsWith(ATDPN)) {
mySerial.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);
}

mySerial.print(LF);
mySerial.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; mySerial.print(sensors[id]); if (id+1 < SENSORSSIZE) { mySerial.print(','); } } mySerial.print(LF); } } /** * Dump sensor information for input sensors. * * Format to Torque is id:type:value */ 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); if (!isOutput) { mySerial.print(id); mySerial.print(":"); mySerial.print(type); mySerial.print(":"); if (type.equals(ANALOG)) { if (i==0) { mySerial.print((((analogRead(id)*5.1/1024)/(5.1)-0.04)/0.009)*0.145); } else if (i==1) { mySerial.print (2); } } else if (type.equals(DIGITAL)) { mySerial.print(digitalRead(id)); } mySerial.print('\n'); } } } /** * 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() {
mySerial.print(CONFIGURATION);
}

hugovw1976
Member
Posts: 19
Post Re: Arduino internal variables
on: April 6, 2017 (GMT)

1kzte do you all ready have connected the bluetooth module to your head unit? I know many android head units (chinise) have trouble to pairing with bluetooth modules not named OBDII.
I change the name of my board to OBDII and paired with my head unit and I can send information from my arduino to the head unit.

hugovw1976
Member
Posts: 19
Post Re: Arduino internal variables
on: April 6, 2017 (GMT)

This is the code I use for testing, ( not my code I modify from some code I found I really don’t remember where I copy this code) the 3 first PIDS I send on mode 21 are custom pids and have to be set on the TORQUE app custom pids. (I made speed2 because stock speed pid don’t support speeds over 250 km/h). in this code I don’t read any real sensor just write the values on varables and send, but you just have to replace the values with the data you read from your sensors.

#include

SoftwareSerial mySerial(10, 11); // RX, TX

String OBDRequest,ATCommand,OBDCommand, OBDReturn;
float COOLANT, SPEED1, SPEED2, FUEL, BOOST, FUEL_PERCENTAGE, a5;
int RPM, Fuel_int, OutTemp, OilTemp, OilPress;

void setup()
{
Serial.begin(9600); // Open serial communications and wait for port to open:
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println(“Goodnight moon!”);
mySerial.begin(9600); // set the data rate for the SoftwareSerial port
}

void loop() // run over and over
{
//delay(1000); //Debug purposes
COOLANT = 93+40;
RPM = 8192*4; //RPM value 8192 rpm just replace this value
SPEED1 = 250;
SPEED2 = 312;
BOOST = 200;
OutTemp = 22+40; //Outside temperature 22 celcius degrees
OilTemp = 109+40; // OIL temp. 109 celcius degrees
FUEL_PERCENTAGE = 89.0;
FUEL = (FUEL_PERCENTAGE/100.0)*255.0;
Fuel_int= (int)FUEL;
String FuelHex = String(Fuel_int, HEX);
String OutTempHex = String(OutTemp, HEX);
String OilTempHex = String(OilTemp, HEX);
OilPress = 65;
a5 = analogRead(5);
while (mySerial.available()){ //Get data from BT serial port
delay(3); //wait for buffer to fill up
if(mySerial.available() >0){ //Serial port ready?
char c = mySerial.read(); //write character to c
OBDRequest += c; //write c to OBDRequest variable
}
OBDRequest.trim(); //get rid of line feeds
}
if (OBDRequest.length() > 0){ //OBDRequest came in?
if(OBDRequest.substring(0,2) == “AT”){ //Is it an AT request? used to setup connection between Torque and Arduino
ATCommand = OBDRequest.substring(2); //Get AT request from String
Serial.println(ATCommand); //used for debugging to see what the Torque app is asking
if (ATCommand == “@1”){ //Torque askes for device description
mySerial.println(“OBDII Arduino Simulator”); //Give it a suitable name
}
if (ATCommand == “I”){ //Torque askes for version ID
mySerial.println(“VPEE v1.0”); //
}
if (ATCommand == “SP0”){ //Torque says to go to auto protocol
mySerial.println(“OK”); //Ok
}
if (ATCommand == “DPN”){ //Torque askes for device protocol by number
mySerial.println(“1”); //just say it is number 1.
}
if (ATCommand == “RV”){ //Torque askes for adapter voltage
mySerial.println(“12.5”);
}
}

if(OBDRequest.substring(0,2) == “21”){ //Mode 21 is used for custom values.
OBDCommand = OBDRequest.substring(2); //Get PID request from Mode 21
if (OBDCommand == “13”){ //This can be any value. Make your own table with PID’s, names, length and formulas
OBDReturn = “61” + OBDCommand + converttohex(SPEED2,4); //61 means return Mode 21 value + 40hex. Make sure length return conforms with formula in Torque
}
if (OBDCommand == “14”){ //This can be any value. Make your own table with PID’s, names, length and formulas
OBDReturn = “61” + OBDCommand + converttohex(OilPress,2); //61 means return Mode 21 value + 40hex. Make sure length return conforms with formula in Torque
}
if (OBDCommand == “15”){ //This can be any value. Make your own table with PID’s, names, length and formulas
OBDReturn = “61” + OBDCommand + converttohex(a5,4); //61 means return Mode 21 value + 40hex. Make sure length return conforms with formula in Torque
}
mySerial.println(OBDReturn); //Return value to Torque

}
//This if statement is only used to prevent Torque mentioning no PID’s are available at startup.
if(OBDRequest.substring(0,2) == “01”){ //Mode 1 request
OBDCommand = OBDRequest.substring(2); //Get PID request from Mode 1
if (OBDCommand == “00”){ //Torque requests available PID’s from Arduino
OBDReturn = “41” + OBDCommand + “087A9000”;
}
if (OBDCommand == “05”){
OBDReturn = “41” + OBDCommand + converttohex(COOLANT,2);
}
if (OBDCommand == “0C”){ //Torque requests available PID’s from Arduino
OBDReturn = “41” + OBDCommand + converttohex(RPM,4);
}
if (OBDCommand == “0D”){
OBDReturn = “41” + OBDCommand + converttohex(SPEED1,2);
}
if (OBDCommand == “0B”){
OBDReturn = “41” + OBDCommand + converttohex(BOOST,2);
}
if (OBDCommand == “2F”){
OBDReturn = “41” + OBDCommand + (FuelHex);
}
if (OBDCommand == “46”){
OBDReturn = “41” + OBDCommand + (OutTempHex);
}
if (OBDCommand == “5C”){
OBDReturn = “41” + OBDCommand + (OilTempHex);
}
mySerial.println(OBDReturn);
}

mySerial.println(“>”); //Let Torque know Arduino is ready.

}
OBDRequest = “”; //clear String when ready.
}

//Torque needs leading zero’s in its values. This function takes care of this.
String converttohex (int a, int decimals){
String temp;
if (a < (pow(16,decimals) – 1)){ temp = String(a, HEX); if (temp.length() < decimals){ int nrzeroes = decimals – temp.length(); for (int a = 0; a < nrzeroes; a++){ temp = “0” + temp; } } } else { temp = “0”; } return temp; }

1kzte
Member
Posts: 12
Post Re: Arduino internal variables
on: April 13, 2017 (GMT)

hugovw1976 Thanks for the idea of changing the name from HC-06 to OBDII. I will give it a try (unfortunately traveling at the moment, so will have to wait until I get back home).

You mentioned changing the name of your board. What board were you using?

Have you (or anyone else) ever seen a a situation where the head unit cannot communicate over Bluetooth with Serial Port Protocol, SPP?

Thanks – I appreciate the help!

Quote from hugovw1976 on April 6, 2017
1kzte do you all ready have connected the bluetooth module to your head unit? I know many android head units (chinise) have trouble to pairing with bluetooth modules not named OBDII.
I change the name of my board to OBDII and paired with my head unit and I can send information from my arduino to the head unit.

hugovw1976
Member
Posts: 19
Post Re: Arduino internal variables
on: April 14, 2017 (GMT)

Quote from 1kzte on April 13, 2017
hugovw1976 Thanks for the idea of changing the name from HC-06 to OBDII. I will give it a try (unfortunately traveling at the moment, so will have to wait until I get back home).

You mentioned changing the name of your board. What board were you using?

Have you (or anyone else) ever seen a a situation where the head unit cannot communicate over Bluetooth with Serial Port Protocol, SPP?

Thanks – I appreciate the help!

Quote from hugovw1976 on April 6, 2017
1kzte do you all ready have connected the bluetooth module to your head unit? I know many android head units (chinise) have trouble to pairing with bluetooth modules not named OBDII.
I change the name of my board to OBDII and paired with my head unit and I can send information from my arduino to the head unit.

Sorry I refer to my bluetooth module HC-05

1kzte
Member
Posts: 12
Post Re: Arduino internal variables
on: April 15, 2017 (GMT)

Ok, so just to confirm:

You used a HC-05 bluetooth, but changed the default “HC-05” name to “OBDII” and the head unit was able to connect?

Did you have to put the HC-05 into master mode, and send a pairing code, or anything along those lines?

Thanks!

hugovw1976
Member
Posts: 19
Post Re: Arduino internal variables
on: April 16, 2017 (GMT)

Quote from 1kzte on April 15, 2017
Ok, so just to confirm:

You used a HC-05 bluetooth, but changed the default “HC-05” name to “OBDII” and the head unit was able to connect?

Did you have to put the HC-05 into master mode, and send a pairing code, or anything along those lines?

Thanks!

Just change the name to OBDII.

Just in case a tutorial to modify bluetootth:
http://www.instructables.com/id/Modify-The-HC-05-Bluetooth-Module-Defaults-Using-A/

1kzte
Member
Posts: 12
Post Re: Arduino internal variables
on: April 22, 2017 (GMT)

Ok, so changed the HC-06 name to OBDII (also tried OBD2). I can see it on the head unit but still the same problem:
Shows up on the head unit as available device.
When I click on it, a screen pops up and says “Pair and connect”, “No Yes”.
I click on Yes, but nothing happens. No screen comes up to enter the pairing code.
I set the pairing code of the HC-06 to 0000. The head unit pairing code is also 0000. But there is no screen pop up to enter the code, and then the HC-06 never pairs, so Torque app never gets any sensor info.

Questions:
1. I have an HC-05. If I use it in master mode, will it cause a pop up screen to appear on the head unit to enter the pin?

2. Since I will want to connect my phone to the head unit, would it be better to connect the Arduino via USB, and use the Torque app via USB connection (I see the option of USB in the Torque settings). If so, what do I need to change in the code for it to communicate over USB? Can most head units connect to more than one Bluetooth device at a time?

3. Can I get a Bluetooth dongle that can communicate with SPP, and plug it into one of the USB ports of the headunit? Then I would still use the HC-05 or HC-06 to talk to the head unit?

Sorry, I’m new to this stuff, but really want to make this work to read boost and EGT on my old land cruiser!

Thanks for the suggestions so far, and look forward to some more!

cintakc
Member
Posts: 1661
Post Re: Arduino internal variables
on: April 22, 2017 (GMT)

Look at this information, may be helpful to you
http://bsvi.ru/pereproshivka-hc-06-v-hc-05/
http://zelectro.cc/HC-06_bluetooth_module
http://robocraft.ru/blog/electronics/587.html
http://we.easyelectronics.ru/part/rabota-s-bluetooth-modulem-hc05.html

1kzte
Member
Posts: 12
Post Re: Arduino internal variables
on: April 22, 2017 (GMT)

I’m not sure if it’s something with my phone, but words in all of those web-links are in another language??

cintakc
Member
Posts: 1661
Post Re: Arduino internal variables
on: April 22, 2017 (GMT)

Use google translate

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

  Follow me on twitter