back
updated 27 Oct 2023
SimHub Custom serial device for Blue Pill
Background
SimHub directly supports certain Arduino boards;
Arduino IDE also supports (cheaper and more powerful) STM32 boards; Black and Blue Pills are popular
| Device | Name | RAM k | Flash k | US$ ebay |
|—————|:———-:|——:|——–:|———:|
| STM32F103C6 | Blue Pill | 20 | 32 | 2.27 |
| STM32F103C8 | Blue Pill | 20 | 64 | 1.80 |
| STM32F401CCU6 | Black Pill | 64 | 256 | 3.65 |
| STM32F411CEU6 | Black Pill | 128 | 512 | 5.26 |
Blue Pill lacks built-in USB boot loader;
programmed into flash makes (sometimes cheaper) STM32F103C6
a poor choice.
Fake8
plugin works around SimHub Custom serial device limitations…
… then MIDIio plugin enables sending those switches as a virtual joystick and/or MIDI control surface signals.
Foreground
An STM32duino sketch moves either of a pair of servos, selected by least significant bit,
for byte values (masked with 0x7F) received by USB COM port,
as described here
Google magic revealed SimHub Custom serial devices
help:
- SimHub Forum: Outputting sim data to Arduino to use with stepper motor gauges
- SimHub Custom serial device plugin is for “non-SimHub” sketches and USB
COM
devices. - Custom serial device can display USB
COM
device response, but cannot process those responses.
- SimHub Custom serial device plugin is for “non-SimHub” sketches and USB
-
SHWotever/SimHub Custom serial devices walks thru enabling that plugin and defining messages:
This SimHub
Custom serial device
profile for Blue Pill harness servos
has two enabled Update messages:- harness tension settings
- click
Test untensioned positions
to adjustLeft untensioned
andRight untenstioned
sliders
so that harness is most slack - then click
test max tension
to adjustmax tension
slider for most harness tightening;
check power regulator LED current readout to verify that servos are not driven to overload - unclick both
Test untensioned positions
andtest max tension
for normal operation.
- click
- live G-force tensions
- this uses
proxy_G
properties from SimHub for ShakeSeat G-forceCUSTOM EFFECT
decel gain
anddecel yaw gain
sliders affect relative strenghts of braking and cornering.smoothing
sliders modifies responsiveness and “noise’ of servo signals.
- this uses
- harness tension settings
- SHWotever/SimHub Wiki Custom serial devices support
I previously had always failed to scroll to Formulas Engines - Here is the NCalc reference repository to which GitHub points.
Sadly, NCalc seems exactly wrong for what is wanted:
- next to no string operators
- no array indexing
- no byte values
- Integers get written to serial as decimal strings.
Much as I dislike Javascript, it supports byte banging..
This leaves the trick of sending the message for dynamic harness tensioning.
An interesting property exists: GameData.GlobalAccelerationG
Sure would be nice if there was a reference describing it…
In SimHib discord, Wotever wrote (01/18/2021) about deceleration:
“it’s DataCorePlugin.GameData.GlobalAccelerationG
deceleration is just a negative acceleration”
On 01/25/2021, fhoos wrote: “(Deceleration goes about from 0 to -50)”
Other properties: GameData.Sway, GameRawData.Physics.Roll
GameData.OrientationRoll GameData.OrientationYaw
Clicking around in Property Picker
:
In the left margin is “Available properties”;
selecting that exposes an Ncalc tester.
Perhaps, if some game were recorded,
then Replay here would show how data worked…?
round([GameRawData.Physics.AccG01],0)
Rough skeleton for SImHub Custom serial device settings
Need to understand the nature of available SimHub properties for acceleration.
First, record a figure 8 track lap, then play it back and record values.
Here is a SimHub Custom Serial formula for relevant properties:
Here is yaw and speed deltas vs scaled GlobalAccelerationG
, plotted by Gnuplot delta_v() script:
delta_v(SpeedMph)
property basically overlays scaled GlobalAccelerationG
.
OrientationYaw
presumably reports degrees heading; abrupt +/-180 transitions are a clue.
Given figure-8 track telemetry, delta_v(OrientationYaw)
seems a credible proxy for lateral acceleration.
My guess is that delta_v “noise” is an artifact of SimHub sampling data at a rate somewhat slower
than that at which Assetto Corsa updates; deltas occasionally represent differences between 3 game samples,
rather than 2. Artifacts could be fairly easily addressed by a non-linear filter which tests:
if (a current delta value is roughly twice the previous)
then (divide it by 2)...
Normalizing speed and yaw deltas by SystemInfoPlugin.Uptime
deltas is unlikely to work,
since it increments based on SimHub, not the game.
Harness tension, G-force gain and smoothing settings:
Recompiled Blue_ASCII sketch to echo hex, confirming 0 and 1 are received, all over 127 scrogged.
While delta_v filter code in a more legible format would be nice,
my guess is that SimHub live interpreter does not work for JavascriptExtensions.
Updated Javascript exploits acceleration property support added to SimHub 7.3.14.
SimHub has Visible Bindings and Enabled Bindings for Custom serial devices Setting panel;
don’t know what two different bindings imply. Sliders work without forcing settings in their Bindings.
As with ShakeIt .siprofile files, SimHub stores Custom Serial device .shsds files in your Documents\SimHub\
folder.
cp
proxy_G.shsds.txt
proxy_G.shsds
Here is Javascript extracted from that profile.
Since an STM32 Blue Pill is capable of driving more (at least 7) PWM devices,
it becomes interesting to investigate useful device control granularity.
Specifically, 4-bit granularity leaves 3 bits for addressing 7 PWM pins,
leaving address 0x70 to e.g. download LUTs and enable/disable message echo.
This Noticeable.shsds GitHub profile has 4 Javascript messages:
1) Generate LUTs for download to (not yet written) Arduino sketch for equal tension increments
2) Repurpose decel and yaw can sliders to for equal tension increment testing
3) Updated (simplified) untensioned and max tension position slider tests
4) Simulate 4-bit quantized tension LUT in comparison to 7-bit (servo pwm granularity) control.
As with Shakeit Bass Shaker profiles, SimHub Custom serial profiles proliferate.
Also similarly, key differences are in embedded JavaScript, and hard to sort by casual inspection.
Consequently, a dedicated atlas for SimHub Custom serial profiles.