Realdash communication with esp32

Is it possible to use the Arduino example code that was created by the author of realdash in esp32, if so in xml instead of Arduino digital example 2, will I have to use esp digital example 2? and so on?

At least the protocol and the principle how to send/receive CAN frames is the same regardless of the device. The actual code probably will not work on esp32.

1 Like

Hi there, at age 66 years young and no programing experience I was wondering if there is a ready made scetch or something out there that I can gobble together that works as gpio on a esp32.
I have a esp32-wroom with built in Bluetooth.
All I want to do is to show things like turn signals, high beams and fuel level on my realdash screen.
The examples that I found online just does not work.
As mentioned I have zero programming experience.
I have some electronic experience so I could get some optocoupler connections going into the esp32 input pins.
Much appreciated if somebody could help me out

This is a long order, as you do need to write a ‘firmware’ to your device that is reading the inputs and passing CAN frames from device to RealDash. I’d recommend trying to find a friend or someone close by to help you with the programming. It probably takes couple of full working days to get running, but could be a fun project.

Thank realdashdev,
Yip a tall order indeed when you live in Africa in a small town with only old farts like me. We were all born BC… Before computers… LOL
I gobbled 2 sketches together and managed to verify and load it into my ESP32.
Also loaded the .XML file that came with it into RealDash, but still RealDash does not connect.
Let me try and upload my 2 files so you can laugh at my feeble attempt.
Do not know how to upload the files.
Put the Sketch in Notepad
Using the .xlm file that came with the 3 input Realdash Examples

realdash_can_example.xml (5.7 KB)

/**

  • ============================================================================
  • Name : RealDash_CAN.ino
  • Part of : RealDash
  • Author : Jani Immonen
  • Created : 15.10.2017
  • Arduino example sketch of how to use RealDash CAN protocol.
  • This example code is free for any use.
  • www.realdash.net
  • ============================================================================
    **/

#include “BluetoothSerial.h”

const char LED= 2;
const char turnON =‘a’;
const char turnOFF =‘b’;

#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);
pinMode(LED, OUTPUT);
SerialBT.begin(“ESP32Kobus”); //Bluetooth device name
Serial.println(“The device started, now you can pair it with bluetooth!”);
Serial.println(“Now You can TURN ON LED by sending ‘a’ and TURN OFF by ‘b’”);
}

void loop() {
char message;

if (SerialBT.available()) {
message=SerialBT.read();
Serial.write(message);

if(message==turnON){
digitalWrite(LED, HIGH); //Turn LED ON
Serial.println(" :LED Turned ON");
SerialBT.println(“LED Turned ON”);
}

else if(message==turnOFF){
digitalWrite(LED, LOW); //Turn LED Off
Serial.println(" :LED Turned OFF");
SerialBT.println(“LED Turned OFF”);
}

else{
Serial.println(" :Invalid Input");
SerialBT.println(“Invalid Input”);
}
}
delay(20);
}

// Arduino digital and analog pins
unsigned int digitalPins = 0;
int analogPins[7] = {0};

unsigned int rpm = 0;
unsigned int kpa = 992; // 99.2
unsigned int tps = 965; // 96.5
unsigned int clt = 80; // 80 - 100
unsigned int textCounter = 0;

void ReadDigitalStatuses()
{
// read status of digital pins (1-13)
digitalPins = 0;

int bitposition = 0;
for (int i=1; i<14; i++)
{
if (digitalRead(i) == HIGH) digitalPins |= (1 << bitposition);
bitposition++;
}
}

void ReadAnalogStatuses()
{
// read analog pins (0-7)
for (int i=0; i<7; i++)
{
analogPins[i] = analogRead(i);
}
}

void SendCANFramesToSerial()
{
byte buf[8];

// build & send CAN frames to RealDash.
// a CAN frame payload is always 8 bytes containing data in a manner
// described by the RealDash custom channel description XML file
// all multibyte values are handled as little endian by default.
// endianess of the values can be specified in XML file if it is required to use big endian values

// build 1st CAN frame, RPM, MAP, CLT, TPS (just example data)
memcpy(buf, &rpm, 2);
memcpy(buf + 2, &kpa, 2);
memcpy(buf + 4, &clt, 2);
memcpy(buf + 6, &tps, 2);

// write first CAN frame to serial
SendCANFrameToSerial(3200, buf);

// build 2nd CAN frame, Arduino digital pins and 2 analog values
memcpy(buf, &digitalPins, 2);
memcpy(buf + 2, &analogPins[0], 2);
memcpy(buf + 4, &analogPins[1], 2);
memcpy(buf + 6, &analogPins[2], 2);

// write 2nd CAN frame to serial
SendCANFrameToSerial(3201, buf);

// build 3rd CAN frame, rest of Arduino analog values
memcpy(buf, &analogPins[3], 2);
memcpy(buf + 2, &analogPins[4], 2);
memcpy(buf + 4, &analogPins[5], 2);
memcpy(buf + 6, &analogPins[6], 2);

// write 3rd CAN frame to serial
SendCANFrameToSerial(3202, buf);

// build 4th frame, this is a text extension frame
// only send once at 1000 loops
if (textCounter == 0)
{
SendTextExtensionFrameToSerial(3203, “Hello RealDash, this is Arduino sending some text data”);
}
else if (textCounter == 1000)
{
SendTextExtensionFrameToSerial(3203, “Tomorrow’s forecast: Lots of sun and 30 degrees centigate”);
}
else if (textCounter == 2000)
{
SendTextExtensionFrameToSerial(3203, “Now Playing: Insert your favorite song info here”);
}
else if (textCounter == 3000)
{
SendTextExtensionFrameToSerial(3203, “Message from Arduino: All systems running at nominal efficiency”);
}
}

void SendCANFrameToSerial(unsigned long canFrameId, const byte* frameData)
{
// the 4 byte identifier at the beginning of each CAN frame
// this is required for RealDash to ‘catch-up’ on ongoing stream of CAN frames
const byte serialBlockTag[4] = { 0x44, 0x33, 0x22, 0x11 };
Serial.write(serialBlockTag, 4);

// the CAN frame id number (as 32bit little endian value)
Serial.write((const byte*)&canFrameId, 4);

// CAN frame payload
Serial.write(frameData, 8);
}

void SendTextExtensionFrameToSerial(unsigned long canFrameId, const char* text)
{
if (text)
{
// the 4 byte identifier at the beginning of each CAN frame
// this is required for RealDash to ‘catch-up’ on ongoing stream of CAN frames
const byte textExtensionBlockTag[4] = { 0x55, 0x33, 0x22, 0x11 };
Serial.write(textExtensionBlockTag, 4);

// the CAN frame id number (as 32bit little endian value)
Serial.write((const byte*)&canFrameId, 4);

// text payload
Serial.write(text, strlen(text) + 1);

}
}

If you want to send the data via Bluetooth

void SendCANFrameToSerial(unsigned long canFrameId, const byte* frameData) {
// the 4 byte identifier at the beginning of each CAN frame
// this is required for RealDash to ‘catch-up’ on ongoing stream of CAN frames
const byte serialBlockTag[4] = { 0x44, 0x33, 0x22, 0x11 };
SerialBT.write(serialBlockTag, 4);

// the CAN frame id number (as 32bit little endian value)
SerialBT.write((const byte*)&canFrameId, 4);

// CAN frame payload
SerialBT.write(frameData, 8);
}

1 Like

Thank you, will check and adjust tomorrow.
Sleeping time now

MMain, where do I put this code in that you send me, and what do I need to remove from the original, because if I just add this to the existing code it does not verify anymore.
Like I said, zero programming experience but willing to learn, might just take some time

Replace subroutine SendCANFrameToSerial

Hi. I’ll give you a working code. I just don’t quite understand where you get the data about the turn signal and low/high beam.

MMain, I replaced what I think is the subroutine.
When I verify it comes with new errors.

sketch_nov15b:13:10: error: extended character “ is not valid in an identifier
13 | #include “BluetoothSerial.h”
| ^
sketch_nov15b:13:10: error: #include expects “FILENAME” or
13 | #include “BluetoothSerial.h”
| ^~~~~~~~~~~~~~~~
sketch_nov15b:13:27: error: extended character ” is not valid in an identifier
13 | #include “BluetoothSerial.h”
| ^
sketch_nov15b:16:20: error: extended character ‘ is not valid in an identifier
16 | const char turnON =‘a’;
| ^
sketch_nov15b:16:20: error: extended character ’ is not valid in an identifier
sketch_nov15b:17:21: error: extended character ‘ is not valid in an identifier
17 | const char turnOFF =‘b’;
| ^
sketch_nov15b:17:21: error: extended character ’ is not valid in an identifier
sketch_nov15b:28:16: error: extended character “ is not valid in an identifier
28 | SerialBT.begin(“ESP32Kobus”); //Bluetooth device name
| ^
sketch_nov15b:28:16: error: extended character ” is not valid in an identifier
sketch_nov15b:29:16: error: extended character “ is not valid in an identifier
29 | Serial.println(“The device started, now you can pair it with bluetooth!”);
| ^
sketch_nov15b:29:72: error: extended character ” is not valid in an identifier
29 | Serial.println(“The device started, now you can pair it with bluetooth!”);
| ^
sketch_nov15b:30:16: error: extended character “ is not valid in an identifier
30 | Serial.println(“Now You can TURN ON LED by sending ‘a’ and TURN OFF by ‘b’”);
| ^
sketch_nov15b:30:52: error: extended character ‘ is not valid in an identifier
30 | Serial.println(“Now You can TURN ON LED by sending ‘a’ and TURN OFF by ‘b’”);
| ^
sketch_nov15b:30:52: error: extended character ’ is not valid in an identifier
sketch_nov15b:30:72: error: extended character ‘ is not valid in an identifier
30 | Serial.println(“Now You can TURN ON LED by sending ‘a’ and TURN OFF by ‘b’”);
| ^
sketch_nov15b:30:72: error: extended character ’ is not valid in an identifier
sketch_nov15b:30:72: error: extended character ” is not valid in an identifier
sketch_nov15b:43:18: error: extended character “ is not valid in an identifier
43 | SerialBT.println(“LED Turned ON”);
| ^
sketch_nov15b:43:30: error: extended character ” is not valid in an identifier
43 | SerialBT.println(“LED Turned ON”);
| ^
sketch_nov15b:49:18: error: extended character “ is not valid in an identifier
49 | SerialBT.println(“LED Turned OFF”);
| ^
sketch_nov15b:49:30: error: extended character ” is not valid in an identifier
49 | SerialBT.println(“LED Turned OFF”);
| ^
sketch_nov15b:54:18: error: extended character “ is not valid in an identifier
54 | SerialBT.println(“Invalid Input”);
| ^
sketch_nov15b:54:27: error: extended character ” is not valid in an identifier
54 | SerialBT.println(“Invalid Input”);
| ^
sketch_nov15b:150:38: error: extended character “ is not valid in an identifier
150 | SendTextExtensionFrameToSerial(3203, “Hello RealDash, this is Arduino sending some text data”);
| ^
sketch_nov15b:150:89: error: extended character ” is not valid in an identifier
150 | SendTextExtensionFrameToSerial(3203, “Hello RealDash, this is Arduino sending some text data”);
| ^
sketch_nov15b:154:38: error: extended character “ is not valid in an identifier
154 | SendTextExtensionFrameToSerial(3203, “Tomorrow’s forecast: Lots of sun and 30 degrees centigate”);
| ^
sketch_nov15b:154:38: error: extended character ’ is not valid in an identifier
sketch_nov15b:154:87: error: extended character ” is not valid in an identifier
154 | SendTextExtensionFrameToSerial(3203, “Tomorrow’s forecast: Lots of sun and 30 degrees centigate”);
| ^
sketch_nov15b:158:38: error: extended character “ is not valid in an identifier
158 | SendTextExtensionFrameToSerial(3203, “Now Playing: Insert your favorite song info here”);
| ^
sketch_nov15b:158:83: error: extended character ” is not valid in an identifier
158 | SendTextExtensionFrameToSerial(3203, “Now Playing: Insert your favorite song info here”);
| ^
sketch_nov15b:162:38: error: extended character “ is not valid in an identifier
162 | SendTextExtensionFrameToSerial(3203, “Message from Arduino: All systems running at nominal efficiency”);
| ^
sketch_nov15b:162:92: error: extended character ” is not valid in an identifier
162 | SendTextExtensionFrameToSerial(3203, “Message from Arduino: All systems running at nominal efficiency”);
| ^
exit status 1
extended character “ is not valid in an identifier

sketch_nov15b:13:10: error: extended character “ is not valid in an identifier

13 | #include “BluetoothSerial.h”

  |          ^

sketch_nov15b:13:10: error: #include expects “FILENAME” or

13 | #include “BluetoothSerial.h”

  |          ^~~~~~~~~~~~~~~~

sketch_nov15b:13:27: error: extended character ” is not valid in an identifier

13 | #include “BluetoothSerial.h”

  |                           ^

sketch_nov15b:16:20: error: extended character ‘ is not valid in an identifier

16 | const char turnON =‘a’;

  |                    ^

sketch_nov15b:16:20: error: extended character ’ is not valid in an identifier

sketch_nov15b:17:21: error: extended character ‘ is not valid in an identifier

17 | const char turnOFF =‘b’;

  |                     ^

sketch_nov15b:17:21: error: extended character ’ is not valid in an identifier

sketch_nov15b:28:16: error: extended character “ is not valid in an identifier

28 | SerialBT.begin(“ESP32Kobus”); //Bluetooth device name

  |                ^

sketch_nov15b:28:16: error: extended character ” is not valid in an identifier

sketch_nov15b:29:16: error: extended character “ is not valid in an identifier

29 | Serial.println(“The device started, now you can pair it with bluetooth!”);

  |                ^

sketch_nov15b:29:72: error: extended character ” is not valid in an identifier

29 | Serial.println(“The device started, now you can pair it with bluetooth!”);

  |                                                                        ^

sketch_nov15b:30:16: error: extended character “ is not valid in an identifier

30 | Serial.println(“Now You can TURN ON LED by sending ‘a’ and TURN OFF by ‘b’”);

  |                ^

sketch_nov15b:30:52: error: extended character ‘ is not valid in an identifier

30 | Serial.println(“Now You can TURN ON LED by sending ‘a’ and TURN OFF by ‘b’”);

  |                                                    ^

sketch_nov15b:30:52: error: extended character ’ is not valid in an identifier

sketch_nov15b:30:72: error: extended character ‘ is not valid in an identifier

30 | Serial.println(“Now You can TURN ON LED by sending ‘a’ and TURN OFF by ‘b’”);

  |                                                                        ^

sketch_nov15b:30:72: error: extended character ’ is not valid in an identifier

sketch_nov15b:30:72: error: extended character ” is not valid in an identifier

sketch_nov15b:43:18: error: extended character “ is not valid in an identifier

43 | SerialBT.println(“LED Turned ON”);

  |                  ^

sketch_nov15b:43:30: error: extended character ” is not valid in an identifier

43 | SerialBT.println(“LED Turned ON”);

  |                              ^

sketch_nov15b:49:18: error: extended character “ is not valid in an identifier

49 | SerialBT.println(“LED Turned OFF”);

  |                  ^

sketch_nov15b:49:30: error: extended character ” is not valid in an identifier

49 | SerialBT.println(“LED Turned OFF”);

  |                              ^

sketch_nov15b:54:18: error: extended character “ is not valid in an identifier

54 | SerialBT.println(“Invalid Input”);

  |                  ^

sketch_nov15b:54:27: error: extended character ” is not valid in an identifier

54 | SerialBT.println(“Invalid Input”);

  |                           ^

sketch_nov15b:150:38: error: extended character “ is not valid in an identifier

150 | SendTextExtensionFrameToSerial(3203, “Hello RealDash, this is Arduino sending some text data”);

  |                                      ^

sketch_nov15b:150:89: error: extended character ” is not valid in an identifier

150 | SendTextExtensionFrameToSerial(3203, “Hello RealDash, this is Arduino sending some text data”);

  |                                                                                         ^

sketch_nov15b:154:38: error: extended character “ is not valid in an identifier

154 | SendTextExtensionFrameToSerial(3203, “Tomorrow’s forecast: Lots of sun and 30 degrees centigate”);

  |                                      ^

sketch_nov15b:154:38: error: extended character ’ is not valid in an identifier

sketch_nov15b:154:87: error: extended character ” is not valid in an identifier

154 | SendTextExtensionFrameToSerial(3203, “Tomorrow’s forecast: Lots of sun and 30 degrees centigate”);

  |                                                                                       ^

sketch_nov15b:158:38: error: extended character “ is not valid in an identifier

158 | SendTextExtensionFrameToSerial(3203, “Now Playing: Insert your favorite song info here”);

  |                                      ^

sketch_nov15b:158:83: error: extended character ” is not valid in an identifier

158 | SendTextExtensionFrameToSerial(3203, “Now Playing: Insert your favorite song info here”);

  |                                                                                   ^

sketch_nov15b:162:38: error: extended character “ is not valid in an identifier

162 | SendTextExtensionFrameToSerial(3203, “Message from Arduino: All systems running at nominal efficiency”);

  |                                      ^

sketch_nov15b:162:92: error: extended character ” is not valid in an identifier

162 | SendTextExtensionFrameToSerial(3203, “Message from Arduino: All systems running at nominal efficiency”);

  |                                                                                            ^

exit status 1

extended character “ is not valid in an identifier

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

Vadzim, the indicator signals and other lights will be from the car lights via an optocoupler circuit into the GPIO pins of the ESP32

and does your Realdash accept data via BT?

Here is the ready code.
Change the pin numbers yourself.
The correct code for Realdash is necessarily executed in different threads.

1 thread - coreReadData - reading data with the frequency you need, which is regulated by functions vTaskDelay(ms), or in more complex cases using timers. I made the simplest functions vTaskDelay for you.
2 thread - coreSendToRD - transferring data to Realdash, also with the frequency you need.

#include <BluetoothSerial.h>

#define R_turn         15
#define L_turn         16
#define Lo_beam        17
#define Hi_beam        18

static byte combuf[8];

TaskHandle_t 
   CoreData = NULL, 
   CoreRD   = NULL;

static byte
   Rturn   = 0,
   Lturn   = 0,
   Lobeam  = 0,
   Hibeam  = 0;

BluetoothSerial SerialBT;

const char *deviceName = "ESP32Kobus";

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  delay(25);

  SerialBT.begin(deviceName);

  pinMode(R_turn, INPUT);
  pinMode(L_turn, INPUT);
  pinMode(Lo_beam, INPUT);
  pinMode(Hi_beam, INPUT);

  xTaskCreate(coreReadData,"coreRead",8096,NULL,1,&CoreData);
  xTaskCreate(coreSendToRD,"coreSend",8096,NULL,2,&CoreRD);

  Serial.println('Setup OK...');

}

void coreReadData( void * pvParameters ) {

  Serial.println('Start core ReadData');

  while (1) {
    Rturn = digitalRead(R_turn);
    vTaskDelay(10);
    Lturn = digitalRead(L_turn);
    vTaskDelay(10);
    Lobeam = digitalRead(Lo_beam);
    vTaskDelay(10);
    Hibeam = digitalRead(Hi_beam);
    vTaskDelay(10);
  }
}

void coreSendToRD( void * pvParameters ) {

  Serial.println('Start core SendToRD');

  while (1) {
    memcpy(combuf, &Rturn, 1);
    memcpy(combuf + 1, &Lturn, 1);
    memcpy(combuf + 2, &Lobeam, 1);
    memcpy(combuf + 3, &Hibeam, 1);
    SendCANFrameToSerial(0x1001, combuf);
    vTaskDelay(100);
  }  
}

void SendCANFrameToSerial(unsigned long canFrameId, const byte* frameData)
{
  const byte SerialBlockTag[4] = { 0x44, 0x33, 0x22, 0x11 };
  SerialBT.write(SerialBlockTag, 4);
  SerialBT.write((const byte*)&canFrameId, 4);
  SerialBT.write(frameData, 8);
}

void loop() {
}

XML for it

RealDashToESP32.xml (687 Bytes)

Thank you very much,
Yes My realdash is on my Samsung phone.
I can see and connect to the ESP32 BT no problem.
I then compiled it and it went into the ESP32 without errors.
I then went into RealDash and after I reset/restart the ESP32 Realdash show Connecting to my BT called ESP32Kobus.
Realdash stay connected to this BT without dropping out.
Then went into the GARAGE and Set Source as
Adapters (CAN/LIN)
Then Selected Realdash CAN
Then Bluetooth
Here I selected my BT ESP32Kobus
Under CAN Description file I selected your supplied XML file
the realdashtoesp32.xml
Then went out to main screen by clicking Done
From what I understand your code I need input for R Turn on input 15
L Turn input 16
Lo Beam 17 and Hi Beam on input 18
Do I need to GND these inputs or supply 3v3 to get it to show on the RealDash ?
I tried GND but nothing happened on Realdash so far.
Thank you for the effort so far, much appreciated.
Also not sure about the coreReadData and coreSendTo RD settings

well of course you need to assign the pins you use. I wrote the numbers just for example.
you should apply >2.5V to them through a 500 Ohm - 1k Ohm resistor and pull them to ground through a >10k Ohm resistor.
this is a standard diagram from any textbook.

I anderstand and assigned the following pins

#define R_turn 15
#define L_turn 2
#define Lo_beam 17
#define Hi_beam 4

I do not have opto coupler and resisters yet. Will order those later.
Is there any other way I can just trigger pins 15, 2,17 and 4 to see the Standard RealDash lights light up for testing now.
|I understand that I cannot connect 12 volts to the I/O pins and will not do it, But I thought I could just apply a GND or a 3.3 Volt to those I/O pins

for testing, you can briefly apply 3.3 V to the pin…
but it is better through a resistor 500-1000 ohm.

Okay, might have some resistor here.
I can get a 4 channel Opto board but it has the
PC817 optcoupler.
I suppose it will be OK