Tutorial : Arduino

This is an introduction to the serial-port module to communicate with an Arduino interface.

In this turorial 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 learn you Arduino code, you'll find many tutorials, books for this.

How to use these examples

What you need

Download the files arduino-examples.zip.

All the examples contains a patch or a workspace and the associated arduino code file (.pde or .ino).

First upload the program to your Arduino, once done, open Usine and run the corresponding patch/workspace.

Before starting

Now check you are using the good serial port and the same baudrate than your Arduino program.

void setup() {
  Serial.begin(57600);
}

If you need to know your device serial port number, see the serial-port page.

Receive Sinewave from Arduino

This first example we use the arduino to create a sinus wave based on time with this rule:

// send a sinewave based on time on the serial line
void loop() 
{
  // calculate a sinus based on time
  time = millis();
  floatResult = 1000*sin(time/500.0);

  // put the result on the serial line
  Serial.print(floatResult, 0);
  // put our delimiter on the serial line
  Serial.print("\n");

  // wait a little
  delay(50);
}

Once connected, you 'll see a signal in the oscilloscope similar to this:

Here we use the delimiter mode and a value of 10 for this one. In the Arduino code we have indicated this value in ASCII format with this line :

Now, we get and convert this value from the inlet RX DATA with a string-to-integer module. We finally divide this value by 1000 (remember the 1000 value in our initial rule) to fit the Oscilloscope inlet.

Send tempo led to arduino

You can use the example (send tempo led to Arduino), on a led (ground and pin 13) to create a visual metronome for Usine:

You can of course change the 13 value by any other available digital pin.

Arduino source

#define HELLO_USINE_LED 13
void setup() {
  pinMode( HELLO_USINE_LED, OUTPUT );
  digitalWrite( HELLO_USINE_LED, LOW );
  Serial.begin(57600);
}

// wait for reveiving data from the serial line
// if we receive an 'A' we turn on the led
// if we receive an 'a' we turn off the led
void loop() {
  if (Serial.available() == 0) {
    return; 
  }
  char readValue = Serial.read();
  switch( readValue )
  {  
  case 'A': 
    digitalWrite( HELLO_USINE_LED, HIGH ); 
    break;
  case 'a': 
    digitalWrite( HELLO_USINE_LED, LOW ); 
    break;
  }
}

And connect a master-synchro module this way:

Knob to oscillator

This one is really basic, use the example arduino-knob-to-oscillator.ino. This one read the analog in 0.

Arduino source

int sensorpin = 0;                 // analog pin used to connect the value knob
int val = 0;                 // variable to store the values from knob(initially zero)

void setup()
{
  Serial.begin(57600);               // starts the serial monitor
}

void loop()
{
  val = analogRead(sensorpin);       // reads the value of the knob
  Serial.println(val);            // prints the value of the knob to the serial monitor
  // put our delimiter on the serial line
  Serial.print("\n");

  // wait a little
  delay(50);
}

We receive it the same way than the sinewave example and transform the values to suit our audio-oscillator-simple:

See also

Usine Tutorial

version 5.2.221206

Edit All Pages