This is a guide to creating sim racing displays that work over Bluetooth, using SimHub's Custom Serial Device plugin and an ESP32. Note that to follow this you'll need to have some experience with coding on Arduino-like boards. And to use it as a base to create your own device, you'll need to have some experience of electronics.
You'll also need:
- An ESP32 device, ideally a Lolin D32
- Windows
- Bluetooth support in your PC
- SimHub
- Arduino IDE
SimHub is an awesome piece of software for Sim Racing on PC - kudos to SHWotever for creating and updating it.
I made these displays for the Thrustmaster Open Wheel, named Tow, that use the telemetry exposed by SimHub:
SimHub does not directly support Bluetooth, but using the Custom Serial Device plugin you can connect to bluetooth serial ports just like you do a standard COM port. You then make your ESP32 read the data coming over the COM port from SimHub, and control your displays, LEDs etc.
Here we'll walk through making an ESP32 (Lolin D32 in this case) connect to SimHub over bluetooth and receive telemetry data - Speed and Rpm.
First enable the Custom serial devices plugin as described in the SimHub Wiki - https://github.com/SHWotever/SimHub/wiki/Custom-serial-devices#enabling-the-plugin, stop at the Configuration step for this guide.
Upload this code to your ESP32 - I use Arduino IDE - so that it reads data from the BT COM port, the data will come from SimHub and we'll configure that in a bit:
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
#define BUF_SIZE 64
char simHubMessageBuf[BUF_SIZE];
BluetoothSerial btSerial;
int spd;
int revs;
void setup() {
Serial.begin(115200);
Serial.println("setup");
memset(simHubMessageBuf, 0x0, BUF_SIZE);
btSerial.begin("BT-DASH");
}
void loop() {
if (btSerial.available() > 0) {
btSerial.readBytesUntil('{', simHubMessageBuf, BUF_SIZE);
int readCount = btSerial.readBytesUntil('}', simHubMessageBuf, BUF_SIZE);
simHubMessageBuf[min(readCount, BUF_SIZE - 1)] = 0x0;
processMessage();
memset(simHubMessageBuf, 0x0, BUF_SIZE);
}
}
void processMessage() {
char msgType = simHubMessageBuf[0];
switch (msgType) {
case 'R':
sscanf(&simHubMessageBuf[1], "%d", &revs);
break;
case 'S':
sscanf(&simHubMessageBuf[1], "%d", &spd);
break;
}
Serial.print("Revs: ");
Serial.print(revs);
Serial.print(", Speed: ");
Serial.println(spd);
}
The code looks for two pieces of data, the Revs percent and the Speed in KMH. It reads both as integers, so we'll end up with whole numbers.
Once this code is uploaded to your ESP32 you can pair it over Bluetooth with Windows. But first, open Windows Device Manager and expand the Ports (COM & LPT) section. Make a quick note of the port numbers of any existing entries named Standard Serial over Bluetooth link - there may not be any, that's fine.
Now pair the device in Windows' Bluetooth settings, it'll appear as BT-DASH, you can change this in the above code if you want a different name.
Once paired go back to Device Manager and you should have two new Standard Serial over Bluetooth link entries in the Ports (COM & LPT) section. Make a note of the port number of the higher numbered one.
In SimHub, go to the Custom serial devices section, click Add new serial device, and then expand the entry that appears.
In the Serial port drop down, choose the serial port you noted above. Tick the Automatic reconnect box.
Now we need to add the Speed and Revs messages in the Update messages section, click Add new message so that you have two empty Update messages and then edit them with these:
'{R'+isnull([CarSettings_CurrentDisplayedRPMPercent], '0')+'}'
'{S'+isnull([SpeedKmh], '0')+'}'
Change the frequency to Changes only for both - using the dropdown next to the EDIT button. This optimizes the data that's sent over the port a little.
You should end up with this:
Connect your ESP32 to your PC so that is has power, and click the toggle button to enable the custom serial device entry, and it should connect to your ESP32.
Now should be able to monitor the ESP32's serial port (the USB one, not the Bluetooth one) in the Arduino IDE and see the messages coming from SimHub when racing or playing a replay - there's buttons at the top to record and playback SimHub telemetry:
Ensure you have the correct baud rate selected - 115200 - in the serial monitor, and you should see data being logged to the USB serial port when the revs and speed change:
You can now use the code above as a base to control displays, LEDs etc. To see what other data you can read in SimHub, click EDIT on an Update message and click Insert Property. You'll see a list that can be searched:
Please leave any questions in the comments below. I'll either answer them or update the article to include the answer or clarification.
Thanks for reading.
Top comments (6)
Hi Dualin2,
Yes! That is possible, i already did it. But it is a lot of coding needed and you need to use the second processor of the esp32. Additionally a voltage step-up from 3.3 to 5V to power the Nextion via esp32. The max sitze you can use is the 3.5 because of the current limit of the esp32 pins.
But yes, as i said, IT IS possible and in simhub you need to define a lot of serial Data points. It is still working over BL-classic, but i also did a Version using esp-now (WiFi), so that is also possible
At the moment im using all of this in a custom wheel powered by the wheelbase itself (3.3V)
Hi Shane877F3Ng, can share your latest version of ESP32 using WiFi with nextion screen.
Hi, great job. Do you know if we can use a nextion screen with an esp32 and without wires??
Thanks in advance
how to add current last lap sir?
it doesn't showing with isnull.
hello would you like to help me to add gamepad button to your sketch? like Keypad.h or something that could recognized as a gamepad
Hi, how are you! exellent work, I have a doubt, where do you define the pin for the led data?, and a neopixel led bar 8 leds works with just 3.5 volts?, thanks