Introduction: How to Use SRIO Library for Arduino
With SRIO Library you can extand your Arduino I/O with shift register 4021 and 74HC595
you can find this tutrorial here : http://www.e-licktronic.com/en/content/19-tutorial-library-sriohttp://www.e-licktronic.com/en/content/19-tutorial-library-srio
In this tutorial we will see how to use the library SRIO with Dilicktal Board
For this tutorial you need:
-1x Midilickuino
-1x Arduino
-1x à 8x Dilicktal
-Arduino software (version 1.0 or newer)
-SRIO Library
-1x USB cable
SRIO Library description:
void Initialize();
//Initialize I / O used with Dilicktal
void Led_SR_Write (byte SR_num, byte data);
//Set a value of 8-bit shift register selected
// number of Dilicktal from 0 to 7 (0 => first Dilicktal connected , 1 => second Dilicktal connected...)
// Value sent from 0 to 255
// Example:
// Led_SR_Write(0,255) turns all LEDs ON of the first Dilicktal in the chain.
void Led_Pin_Write (byte Pin_num, byte flag);
//Set 0 or 1 in the Pin Led selected
// The number of pin ranges from 0 to 63 (0 being the first pin of the first Dilicktal ...)
// value sent 1 => ON or 0 => OFF
// Example:
// Led_Pin_Write (34,1) Turn ON the third LED of the fifth Dilicktal in the chain.
void Led_All_On();
// Turns all ON LEDs connected
// Do not need any parameters
void Led_All_Off();
// Turns all OFF LEDs connected
// Do not need any parameters
byte Led_SR_Read (byte SR_num);
// Returns the value (8 bits) of the state of the LEDs on the Dilicktal board selected
// Number of Dilicktal from 0-7 (0 => first Dilicktal connected, 1 => second Dilicktal connected ...)
byte Button_SR_Read (byte SR_num);
// Returns the value (8 bits) of the state of the buttons of the selected Dilicktal
// Number of Dilicktal from 0-7 (0 => first Dilicktal connected, 1 => second Dilicktal connected ...)
byte Button_Pin_Read (byte Pin_num);
// Returns the state of the button, 0 => released or 1 => pressed
// The number of pin ranges from 0 to 63 (0 being the first pin of the first Dilicktal ...)
Step 1: Install Library SRIO
How to use SRIO Library:
1-You copy the file "wiring_shift.c" located in Zip file library
SRIO and replace the old file in your Arduino environment.
It is located in: X:/ .../arduino-1.0.x/hardware/arduino/cores/arduino
This file has been modified to optimize the speed of communication between Arduino and Dilicktal.
Then open the file "Arduino.h" which is X:/.../ arduino-1.0.2/hardware/arduino/cores/arduino
Go to line 111 and replace lines 111 by "void shiftOut (uint8_t val);"
And line 112 by "uint8_t shiftIn ();"
Warning: The library SRIO only works with Arduino UNO, Pro, Duemilanove,
Diecimila, NG and Extreme.
For other Boards must change the code "wiring_shift.c."
If this is your case, contact us and we will send you the code to your Arduino Board
2-You must copy the folder "SRIO" located in Zip file library
SRIO and paste it into the folder "libraries" of your Arduino environment
It is located in: X:/ .../arduino-1.0.x/libraries
You are now ready to use the library SRIO.
3-We will now create a simple code that uses the library functions SRIO
Launch Arduino and import our library
Go to "Sketch" then "Import Library ..." you should see SRIO, click on it.
Then input the data constructors of the library: SRIO SR;
Followed by "void setup" and "void loop"
In "void setup" entry initialization function library: SR.Initialize ()
Your code should look like the following:
#include <SRIO.h>
SRIO SR;
void setup()
{
SR.Initialize();
}
void loop()
{
}
Step 2: Understanding the Function
4-Let's have fun with this functions.
Connect Midilickuino with Arduino to your computer via USB
Now connect the Dilicktal Board to Midilickuino
The order in which you connect will give you the number of each Dilciktal and that each Pin.
Step 3: First Code With SRIO Library
5-We will create a code that will give us on the serial monitor of arduino
the number of each Dilicktal Board.
Here is the code and the comments so that you can understand how.
Upload the code and open the serial monitor by pressing CTRL + SHIFT + M
You should see a line that says: "The number board X is lit".
////////////////////////////////////////////////////////
//This program shows the number of each Dilicktal Board
// connected to Midilickuino
////////////////////////////////////////////////////////
#include <SRIO.h>
//Library constructor
SRIO SR;
//Variable of number of connected board
int nbr_platine = 8;
void setup()
{
//Initialize serial port
Serial.begin(9600);
//Initialize in and out use by Dilicktal
SR.Initialize();
}
void loop()
{
//Loops as many time as board connected
for(int i=0; i<nbr_platine; i++){
//Light Led of selected Dilicktal
SR.Led_SR_Write(i,255);
//Sent to serial monitor the number of the Dilicktal on
Serial.print("The number board ");
Serial.print(i,DEC);
Serial.println(" is ON");
//delay for readability
delay(2000);
//Off the leds of selected Dilciktal
SR.Led_SR_Write(i,0);
}
}
Step 4: Some Exercice
6-A little exercise, and yes!! do not believe that we will do the job for you.
Try doing the same thing but this time, it is necessary that the serial monitor shows
the number of each LED.
Use the function "Led_Pin_Write" instead of "Led_SR_Write"
Here is the answer:
////////////////////////////////////////////////////////
//This sketch shows the number of each led
////////////////////////////////////////////////////////
#include <SRIO.h>
//Library constructor
SRIO SR;
//Variable of the number of connected led
int nbr_led = 64;
void setup()
{
//Initialize serial port
Serial.begin(9600);
//Initialize in and out use by Dilicktal
SR.Initialize();
}
void loop()
{
//Loops as many time as connected led
for(int i=0; i<nbr_led; i++){
//Turn ON the selected Led
SR.Led_Pin_Write(i,1);
//Sent to the serial monitor the number of the led on
Serial.print("the led number ");
Serial.print(i,DEC);
Serial.println(" is ON");
//delay for readability
delay(2000);
//Off the selected led
SR.Led_Pin_Write(i,0);
}
}
Step 5: Button Function
7-Now that we know how to use the functions of the LED we see that assigned to buttons.
We will create a code that will show us on the serial monitor of Arduino which button is pressed.
Here is the code commented:
//This sketch shows us wich button is pressed
#include <SRIO.h>
//Library constructor
SRIO SR;
//Constant of the number of connected button
#define nbr_button 64
//Variable of the button state
//Array size is the number of button
int button_state[nbr_button];
void setup()
{
//Initialize serial port
Serial.begin(9600);
//Initialize in and out use by Dilciktal
SR.Initialize();
}
void loop()
{
//Loops as many time as connected button
for(int i=0; i<nbr_button; i++){
//Store button state in variable
button_state[i]=SR.Button_Pin_Read(i);
//Is the state ON?
if(button_state[i] == 1){
//Sent to serial monitor the state of the button
Serial.print("The ");
Serial.print(i,DEC);
Serial.println(" button is pressed");
}
}
}
You will notice that in this code as we press the button the serial monitor displays
constantly: "The X button is pressed." You tell me that it poses no problem.
In this case also, but do not forget that we want to send MIDI event
so when the button is pressed all the time we send a MIDI message that will saturate the connection and
you can not send anything else as MIDI data.
Step 6: Button Exercice
8-the following execice will be displayed on the serial monitor the button state: pressed or
released. Courage is not complicated, you must use another
variable to hold the buttons states
Here is the answer:
///This sketch shows wich button is pressed or released
#include <SRIO.h>
//Library constructor
SRIO SR;
//Constant of the number of connected button
#define nbr_button 64
//Variable of the buttons states
//Array size is the number of button
int button_state[nbr_button];
//Variable to hold the button state
int old_button_state[nbr_button];
void setup()
{
//Initialize serial port
Serial.begin(9600);
//Initialize in and out use by Dilicktal
SR.Initialize();
}
void loop()
{
//Loop as many as connected button
for(int i=0; i<nbr_button; i++){
//Hold the button state in the variable
button_state[i]=SR.Button_Pin_Read(i);
//Button state has changed?
if(button_state[i] != old_button_state[i]){
//Button is pressed or released?
switch(button_state[i]){
case 0:
//Sent to serial monitor the number of the released button
Serial.print("The ");
Serial.print(i,DEC);
Serial.println(" button is released");
break;
case 1:
//Sent to serial monitor the number of the pressed button
Serial.print("The ");
Serial.print(i,DEC);
Serial.println(" button is pressed");
break;
}
}
//Don't forget to hold the state of the button
old_button_state[i] = button_state[i];
}
}
Step 7: Midi Code to Make Your Own Controller
9-Now that we have this code it is not very difficult to modify to send
MIDI data with our buttons.
Start by creating a function that sends control change message.
void Send_CC(byte num_CC, byte value)
{
Serial.write (0xB0);//Message "control change" on canal MIDI 1
Serial.write (num_CC);
Serial.write (value);
}
To change the MIDI channel or message type you are referencing the Midilickuino Tutorial
Insert our function in our code and replace previous serial monitor messages to
a MIDI message
Add the "Led_Pin_Write" for the corresponding LED on the button lights up when pressed
Adding also the choice of the speed of serial communication
And here is the code:
//Sent MIDI message when a button is pressed or released
#include <SRIO.h>
//Library constructor
SRIO SR;
//Constant who define serial baud: USB => 2, MIDI => 1 ou SERIE => 0
#define serial_baud 2
//Constant of the number of button
#define nbr_button 64
//Variable of the button state
//Array size is the number of button
int button_state[nbr_button];
//Variable to hold the button state
int old_button_state[nbr_button];
//Function that send MIDI CC message on canal MIDI 1
void Send_CC(byte num_CC, byte value)
{
Serial.write (0xB0);//Message "control change" on canal MIDI 1
Serial.write (num_CC);
Serial.write (value);
}
void setup()
{
//Choice the serial baud
switch (serial_baud){
case 0:
Serial.begin(9600);//Serie communication for debug
break;
case 1:
Serial.begin(31250);//MIDI communication
break;
case 2:
Serial.begin(115200);//USB communication
break;
}
//Initialize in and out use by Dilciktal
SR.Initialize();
//Leds animation to know that program start
SR.Led_All_On();
delay(500);
SR.Led_All_Off();
}
void loop()
{
//Loop as many as number of connected button
for(int i=0; i<nbr_button; i++){
//Hold the button state in the variable
button_state[i]=SR.Button_Pin_Read(i);
//Button state has changed?
if(button_state[i] != old_button_state[i]){
//Button state is pressed or released?
switch(button_state[i]){
case 0:
//Sent MIDI message CC on canal 1
Send_CC(i,0);
//Turn Off the button led
SR.Led_Pin_Write(i,0);
break;
case 1:
//Sent MIDI message CC on canal 1
Send_CC(i,127);
//Turn On the button led
SR.Led_Pin_Write(i,1);
break;
}
}
//Don't forget to hold the button state
old_button_state[i] = button_state[i];
}
}
Here it remains for you that making your own applications.
Other codes will be given as a choice between TOGGLE or MOMENTARY button or
Drum sequencer.... free rein to your imagination.
Comments