This is an introduction to the serial-port module to communicate with an Arduino interface.
In this tutorial we will show you the specification of the serial-port module, understand the way it works and how to communicate with your Arduino or other serial devices.
Our purpose here is not to teach you Arduino code, you'll find many tutorials, books for this.
Download the files arduino-examples.zip.
It holds the three patches of this tutorial (receive sinewave, knob to oscillator and send tempo led, as .usine-patch files)
and the Arduino sketch of each one (an .ino file in a folder of the same name, as the Arduino IDE expects).
First upload the sketch to your Arduino, once done, open Usine and load the corresponding patch.
In each patch, choose the serial port of your board in the ports list of the Serial Port module (or type its name in port), then turn connect ON in the control panel of the patch: the connected led lights up when the port is open.
The baudrate of the module (57600 in the three patches) must be the speed given to Serial.begin in the sketch:
void setup() {
Serial.begin(57600);
}
If you need to know your device serial port name, see the serial-port page.
In this first example, the Arduino (sketch arduino-send-sinewave.ino) computes a sine wave from the time and sends one value per line, as text:
// Usine tutorial "Arduino": receive sinewave
// Sends a sine wave computed from the time, one value per line (text, then a line feed).
// In Usine: Serial Port module at 57600 bauds, rx buffer size 0, rx byte delimiter 10.
float sineValue;
void setup() {
Serial.begin(57600);
}
void loop()
{
// a sine between -1000 and 1000, about one period every 3 seconds
sineValue = 1000 * sin(millis() / 500.0);
// the value as text, without decimals
Serial.print(sineValue, 0);
// the delimiter: a line feed (byte 10)
Serial.print('\n');
// wait a little
delay(50);
}
Here we use the delimiter mode of the Serial Port module: rx buffer size at 0 and rx byte delimiter at 10,
the line feed that Serial.print('\n') sends after each value. Each message comes out on rx data without its delimiter,
as the bytes of its text: the ASCII codes of its characters, for example [45, 56, 52, 49] for -841.
The script module bytes to number turns these bytes back into the text (outlet text) and its number (outlet value). A carriage return or spaces around the number are ignored, and a message that is not a number leaves value as it was. Its source is in the patch: open the script editor of the module to read it. We finally divide this value by 1000 (remember the 1000 value in our initial rule) to fit the oscilloscope, from -1 to 1.

Once connected, the control panel shows the text received and the sine wave:

You can use the example send tempo led with a led between the pin 13 and the ground (most boards already have a led on the pin 13) to create a visual metronome for Usine:

You can of course change the 13 value by any other available digital pin.
// Usine tutorial "Arduino": send tempo led to Arduino
// Turns the led on when it receives the character 'A', off when it receives 'a'.
// Wire a led between the pin 13 and the ground (most boards already have a led on the pin 13).
// In Usine: Serial Port module at 57600 bauds, the text sent on 'tx data (string)'.
const int LED_PIN = 13;
void setup() {
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
Serial.begin(57600);
}
void loop() {
if (Serial.available() == 0) {
return;
}
char received = Serial.read();
switch (received)
{
case 'A':
digitalWrite(LED_PIN, HIGH);
break;
case 'a':
digitalWrite(LED_PIN, LOW);
break;
}
}
At each beat, the beat trigger of a master-synchro module switches a flow-toggle module.
The toggle chooses in a string-mix-selector module the text a (toggle at 0) or A (toggle at 1),
sent to the board on tx data (string), which sends a text each time it changes:
the led changes at each beat, so it is ON one beat out of two.
The master synchro must be ON, see the master-synchro-panel.

The arduino led of the control panel shows what is sent:

This one is really basic, use the example arduino-knob-to-oscillator.ino. It reads a knob (potentiometer) wired to the analog input A0 and sends its value, from 0 to 1023, one value per line.

// Usine tutorial "Arduino": knob to oscillator
// Sends the value of a knob (potentiometer) wired to the analog input 0, from 0 to 1023,
// one value per line (text, then a line feed).
// In Usine: Serial Port module at 57600 bauds, rx buffer size 0, rx byte delimiter 10.
const int KNOB_PIN = A0; // analog input of the knob
int knobValue = 0;
void setup()
{
Serial.begin(57600);
}
void loop()
{
knobValue = analogRead(KNOB_PIN);
// the value as text
Serial.print(knobValue);
// the delimiter: a line feed (byte 10). Serial.println would send a carriage
// return (13) before it
Serial.print('\n');
// wait a little
delay(50);
}
We receive it the same way than the sinewave example, with the script bytes to number.
A data-scaling-change-scale module turns the value, from 0 to 1023,
into a frequency from 100 to 1000 Hz for an audio-oscillator-simple module,
followed by an audio-mix-volume module at -12 dB and the two audio outputs of the patch.

The oscilloscope of the control panel shows the frequency:

version 7.0.250921
Edit All Pages