07 Advanced
Lua scripting
Custom CAN, extra logic, and why F7 RAM matters.
8 min readUpdated 2026-08
Race Core F7 runs Lua on the MCU. F7’s extra SRAM (versus an F4) is what makes this practical: real CAN parsers, a custom launch state machine, or extra PWM logic without running out of memory.
Lua is for things that are not a table: CAN translate, a special pump strategy, a dash button that arms a second boost target. It is not for rewriting VE. Race functions that already exist (anti-lag, rotational idle, boost-by-gear, traction) should be used as firmware features, not re-implemented in a script.
What a script can do
- Read sensors, RPM, gear, button digital inputs
- Set spare outputs (low-sides, high-sides) and poke some fuel/spark modifiers the firmware exposes
- txCan / rxCan on CAN 1 (and CAN 2 where present)
- Print to the rusEFI console for debug
Example — CAN heartbeat and a spare output
-- Race Core Lua sketch (Proteus F7 API)
function onTick()
local rpm = getSensor("RPM") or 0
if rpm > 400 and rpm < 9000 then
-- 11-bit id 0x600, 8 bytes, RPM in bytes 0-1
txCan(1, 0x600, 0, { rpm & 0xFF, (rpm >> 8) & 0xFF, 0, 0, 0, 0, 0, 0 })
end
end
Style
- Keep onTick cheap. Do not build strings, do not parse JSON, do not block.
- IDs, scales and endianness belong in named locals at the top of the file.
- Use Lua to glue — CAN translate, a button, a spare pump. Do not re-implement anti-lag or boost-by-gear in a script when the firmware already has the feature.