Custom text protocol
Firmata is the easiest way to start, but sometimes you want your own sketch: to read a sensor library, do filtering on the board, or use a microcontroller that can’t run Firmata. The custom text transport handles that. Your sketch prints simple text lines, and Serial Input Bridge turns them into Input System controls.
The line format
Section titled “The line format”Each line is a list of name:value pairs separated by ;, and ends with a newline:
D2:1;D3:0;A0:512;A1:1023;| Part | Rule |
|---|---|
| Digital input | D<pin>:<0 or 1>, for example D2:1 |
| Analog input | A<channel>:<raw value>, for example A0:512. Unity divides by the profile’s Analog Max Value (1023 by default), so 512 becomes about 0.5. |
| Separator | ; between pairs. A trailing ; is fine. Spaces around names and values are ignored. |
| End of line | \n. Use Serial.println(). |
| Baud rate | Must match the profile’s Baud Rate (115200 for generated profiles). |
You don’t need to send every pin on every line. Each pair updates only that control, so you can send A0:300; alone.
Buttons are active-low by default
Section titled “Buttons are active-low by default”The profile’s Digital Active Low setting is on by default. With it on, 0 means pressed. That matches the usual wiring: a button between the pin and GND, with INPUT_PULLUP.
If your sketch sends 1 for pressed (for example a button wired to 5V with a pull-down resistor), turn Digital Active Low off in the profile.
Names that don’t match
Section titled “Names that don’t match”If a line contains a name the profile doesn’t know, for example D7 when D7 isn’t an input in the profile, Unity logs a warning once for that name and ignores it. Pairs that aren’t in name:value form, or values that aren’t numbers, are skipped without a warning.
Generate a sketch and profile
Section titled “Generate a sketch and profile”The package can write a matching sketch and profile for you:
- Open Tools > Serial Input Bridge > Advanced > Generate Custom Sketch + Profile.
- Fill in:
- Device Name, for example
MyController - Digital Inputs: how many buttons. They use pins from D2 upward (D0 and D1 are the USB serial link).
- Analog Inputs: how many knobs or sensors. They use A0 upward.
- Device Name, for example
- Click Generate and Save.
Under Assets/SerialInputBridge/GeneratedDevices/<DeviceName>/ you get:
| File | What it is |
|---|---|
<DeviceName>.ino |
The real sketch. Open it in the Arduino IDE and upload it. |
Tester/<DeviceName>Mock/<DeviceName>Mock.ino |
A test sketch that sends random values once a second, so you can try Unity with no wiring. |
<DeviceName>Profile.asset |
The matching profile, set to the custom text transport. |
Then generate Input Actions from the profile with Tools > Serial Input Bridge > Advanced > Input Actions Wizard, and assign the profile to a SerialManager as usual.
Writing your own sketch
Section titled “Writing your own sketch”The generated sketch is a good starting point. A minimal version with one button and one potentiometer:
void setup() { pinMode(2, INPUT_PULLUP); // button between D2 and GND Serial.begin(115200); // must match the profile's Baud Rate}
void loop() { String line = ""; line += "D2:" + String(digitalRead(2)) + ";"; line += "A0:" + String(analogRead(A0)) + ";"; Serial.println(line); delay(10);}Your profile needs D2 in its Digital Pins list and channel 0 in its Analog Channels list, with Transport set to Custom Text.
Other microcontrollers
Section titled “Other microcontrollers”Any board that can print to a serial port works: ESP32, Raspberry Pi Pico, Teensy and others. Set the profile’s Analog Max Value to the board’s ADC range, for example 4095 for a 12-bit ADC like the ESP32’s, so values still run from 0 to 1 in Unity.
Debugging
Section titled “Debugging”- Open Tools > Serial Input Bridge > Input Monitor to see the raw lines arriving and the resulting control values.
- On the SerialManager, turn on Log Incoming Lines to print each line to the Console.
- Seeing garbled text? The baud rate in the sketch and the profile don’t match.