Welcome to %s forums

BrainModular Users Forum

Login Register

Serial Module (e.g. for the use with an Arduino) is available

Create your own modules in C++
Post Reply
hesspet
Member
Posts: 92
Location: Germany
Contact:

Post by hesspet » 14 Dec 2012, 17:58

I uploaded the new Serial Module for Usine to the Add-Ons (other).

I've pulished this module early as possible.

Please feel free to ask for changes if some things are not good to use in Usine. The current version is beta.003. Hmm, yes, there a some small bugs in the module. I is not production stable. Sometimes, eg. if you change the comport to often, Usine will crash ( or crash on exit)). I'm working on this problem :-)

The communication works stable. I've tested it with an Arduino board for 24 hours without any problem.

For the Arduino freaks: Yes, it supports the Firmata protocol!

During the next weeks, I'll add more samples and fixes to the package.

Have fun

Peter

P.S.: Here you will find the first draft of the documentation: http://sensomusic.com/wiki/doku.php?id=manual:modules:users:serial
+++ journeytounknownsoundscapes.blogspot.de +++
+++ DIY electronics +++ musical experiments +++ light experiments +++

User avatar
nay-seven
Site Admin
Posts: 5684
Location: rennes France
Contact:

Post by nay-seven » 14 Dec 2012, 19:18

cool, i confirm the 2 first example works fine here.
I've a little difference in the way the example 2 don't give regular change , I've some short and some long

hesspet
Member
Posts: 92
Location: Germany
Contact:

Post by hesspet » 14 Dec 2012, 22:47

This could be.

Depends on the rx buffers of you system. There a so many buffers in a system, which must be filled until they are send. Which Arduino type do you use? I've tested it with an Uno which does not use the FTDI drivers (all Arduinos < Uno uses FTDI). The FTDI driver do such things sometimes (known as "latency problem"). They wait a fix time before sending the data to the application. (Little bit similar to the BLOC Frame, but much longer :-)

Serial communication can be magic :-) I'll test it with an older Arduino the next days. But I've similar effects when I use the PD serial in an older installation. Normally the data which is sende is more than 1 byte :-)

http://www.ftdichip.com/Support/Documents/TechnicalNotes/TN_103_FTDI_USB_Data_Transfer_Efficiency%28FT_000097%29.pdf

On page 3 is the solution:

And here ist the solution to control the latency

http://www.instructables.com/id/Lampduino-an-8x8-RGB-Floor-Lamp/step20/Reducing-FTDI-Serial-Latency/

:-)

Hope this helps. I'll add a comment to this very common problem to the description.


P.S.: could also be an other problem
+++ journeytounknownsoundscapes.blogspot.de +++
+++ DIY electronics +++ musical experiments +++ light experiments +++

User avatar
nay-seven
Site Admin
Posts: 5684
Location: rennes France
Contact:

Post by nay-seven » 14 Dec 2012, 23:16

You win boss!
set the latency to 1 has solved the problem

hesspet
Member
Posts: 92
Location: Germany
Contact:

Post by hesspet » 16 Dec 2012, 13:23

This is one of the reason why the arduino development leaves the path of the FTDI :-)
+++ journeytounknownsoundscapes.blogspot.de +++
+++ DIY electronics +++ musical experiments +++ light experiments +++

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Post by martignasse » 17 Dec 2012, 12:23

finally, i had time this WE to test the module (i didn't tested firmata)


seems to work well when the COM number is configured :cool:

but a bad COM setting (like when you load a someone else patch) cause a lot of instability (crash usine or corrupt the patch)
the error handling should be more robust

Code: Select all

What do you think? Should I transfer the source to Github or to an other repository? Maybe when it is finished it can be added to the next Usine version. The code is build with "STL" and "boost", so it should be possible to compile it on a Mac also &#40;I've no access to Mac, so I can't compile it&#41;.
well, yes and no...

yes to put it on github, as it will make easier for maintenance, tracking and correcting bugs and for the future mac conversion

no to add it to usine distrib, because basically, the purpose of modules is to let them the author responsibility
and if we do, we have to assume the stability and maintenance, it's not a trivial task and our resources are not infinite
i think the community is the best place to guaranty a well maintained module like this


but don't make me wrong, this module will be a killer extension to usine for a lot of uses and users

if you put it to github, i'll try to put an eye on it to help about the instability and shut down problem
Martin FLEURENT - Usine Developer - SDK maintainer

headphoner
Member
Posts: 225

Post by headphoner » 17 Dec 2012, 18:37

Hi,

I just tested it with IR range sensor Sharp

The module received the value very well!

No crash

Great

hesspet
Member
Posts: 92
Location: Germany
Contact:

Post by hesspet » 25 Dec 2012, 15:11

Will build transfer the source in the next days. I've found the problem with the crash, but found only a windows dependent solution. It is the way boost handles threads. I'm working on it in January.

Thanks for testing.

and

Merry Christmas and a Happy New Year to all! -> 2012 xmas sandanimation with generative soundscape


Peter

BTW: Uses VVVV and Usine as OSC simple midi router under the hood. In the next step it needs the Serial module to control some switches for live performance :-)
+++ journeytounknownsoundscapes.blogspot.de +++
+++ DIY electronics +++ musical experiments +++ light experiments +++

audion
New member
Posts: 4

Post by audion » 19 Aug 2020, 11:13

Hello hesspet
thank you for this great contribution!
I'm on Mac OS X and I'm desperately trying to communicate with my arduino via firmata with usine.
I tried your script to create firmata protocol but there is a problem at compile time:" Unknown declaration "SendMidiMessageToOut" at line 71 "
What do you think?
Is there another way to send a message to firmata? There's no example in the arduino tutorial.
Thanks to all of you!!!

User avatar
nay-seven
Site Admin
Posts: 5684
Location: rennes France
Contact:

Post by nay-seven » 19 Aug 2020, 11:31

Hello,
It's a really old 8 years post, and long time i don't test arduino in Usine
But have you test the basic help patches?
arduino-examples.zip
You do not have the required permissions to view the files attached to this post.

audion
New member
Posts: 4

Post by audion » 19 Aug 2020, 15:37

Thank you very much Nay-seven for taking an interest in my problem!
Unfortunately none of the attached examples are about firmata :(
The only documentation I found is from hesspet but it doesn't work for me.

User avatar
nay-seven
Site Admin
Posts: 5684
Location: rennes France
Contact:

Post by nay-seven » 19 Aug 2020, 16:23

Ok, sorry for that,
Don't know if we can find a solution, cause Martignasse (who create the module) is not anymore a part of the team
And we really don't have a lot of users using arduino. Maybe OliLab can help, will ask him

User avatar
nay-seven
Site Admin
Posts: 5684
Location: rennes France
Contact:

Post by nay-seven » 19 Aug 2020, 18:54

i have also found this workspace in my archive about firmdata,
but not sure it can help you cause it basically send classic midi message note ?
SerialPort send firmata to Arduino.wkp
You do not have the required permissions to view the files attached to this post.

oli_lab
Member
Posts: 1016
Location: Brittany, France
Contact:

Post by oli_lab » 19 Aug 2020, 21:14

firmata is imho a bit outdated, you could look into arduino osc librairy for fast response and reliability or Teensy with MIDI USB
http://oli-lab.org

Win10 I7/16GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Facebook
http://www.facebook.com/pages/OLI_LAB/3 ... 506?v=wall

audion
New member
Posts: 4

Post by audion » 20 Aug 2020, 10:31

Good morning everyone,
just to let you know that we found the problem compiling the pseudo-MIDI generation module for firmata.
The SendMidiMessageToOut procedure is defined after its first declaration. You have to cut/paste the procedure before the callback in the script.
And it works!
Cheers!

User avatar
nay-seven
Site Admin
Posts: 5684
Location: rennes France
Contact:

Post by nay-seven » 20 Aug 2020, 11:17

Great news !
And if you can can share an example of your work/ workspace/ino, could be cool for the community ;-)

oli_lab
Member
Posts: 1016
Location: Brittany, France
Contact:

Post by oli_lab » 21 Aug 2020, 11:45

anyone interested in an USB-MIDI example, Teensy based ?
http://oli-lab.org

Win10 I7/16GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Facebook
http://www.facebook.com/pages/OLI_LAB/3 ... 506?v=wall

oli_lab
Member
Posts: 1016
Location: Brittany, France
Contact:

Post by oli_lab » 21 Aug 2020, 18:09

USB-MIDI example with a teensy 2.0

augmented bass clarinet
clarinet basse augmentee.JPG
list of components : ////////////////////////////////////////////////////////////////
1 x Teensy 2
1 x accelerometer GY61 (analog outputs)
9 x buttons
1 x Joystick with 1 momentary switch
schema boutons.png

documentation : //////////////////////////////////////////////////////////////
Teensy pinout : https://www.pjrc.com/teensy/pinout.html
Teensy programming as an Arduino : https://www.pjrc.com/teensy/teensyduino.html
including libraries : https://www.arduino.cc/en/guide/libraries (for bounce.h and statistics.h)
GY61 : https://5.imimg.com/data5/SC/UG/MY-1833 ... module.pdf
Joystick : https://www.gotronic.fr/art-module-adaf ... -25358.htm

Arduino code : //////////////////////////////////////////////////////////////

// for TEENSY 2
#include <Bounce.h>
#include <Statistic.h> // auto-calibration of joysticks
byte midiChannel = 1;
byte reception_midi_channel = 16;
byte CTRL_num = 1; // number of the first midi controller message to be sent for the 10 buttons
byte CTRL_Joy = 22; // number of the first midi controller message to be sent joystick et acceleration sensor
byte CTRL_Accl_OnOff = 100; // inbound controller number to switch on/off midi controller for acceleration sensor
byte CTRL_channel_select = 101; // inbound controller number to choose outbound midi channel
/*
A0 : joystick 1
A1 : joystick 2
A2 : acceleration Y

D4/BP4 : D0/BP0
D5/BP5 : D1/BP1
D6/BP6 : D2/BP2
D7/BP7 : D3/BP3

*/
//analog inputs
#define X1 0
#define Y1 1
#define Accl 2
//joystick
Statistic myStatsX1;
Statistic myStatsY1;
int valX1 = 0;
int valY1 = 0;
int valX1_1 = 0;
int valY1_1 = 0;
int valX1_2 = 0;
int valY1_2 = 0;
int minX1 = 0;
int maxX1 = 1023;
int minY1 = 0;
int maxY1 = 1023;
int valX1_1_prev = 127;
int valY1_1_prev = 127;
int valX1_2_prev = 127;
int valY1_2_prev = 127;
int zero_X = 0;
int zero_Y = 0;
long timeX1_1 = 0;
long timeY1_1 = 0;
long timeX1_2 = 0;
long timeY1_2 = 0;
// capteur d'acceleration
Statistic myStatsAccl;
int valAccl = 0;
int minAccl = 0;
int maxAccl = 1023;
int valAccl_prev = 127;
long timeAccl = 0;
byte AcclOnOff = 0;
//

//entrées logiques
#define BP_Joy 0
#define BP0 1
#define BP1 2
#define BP2 3
#define BP3 4
#define BP4 5
#define BP5 6
#define BP6 7
#define BP7 8
#define PouceGauche 9


// BP_JOY, BP0, BP1, BP2, BP3, BP4, BP5, BP6, BP7, BP_pouce_gauche
int valBP[] = {0,0,0,0,0,0,0,0,0,0};
int valBP_prev[] = {1,1,1,1,1,1,1,1,1,1};

Bounce bouncerBP_Joy = Bounce(BP_Joy,25);
Bounce bouncerBP0 = Bounce(BP0,25);
Bounce bouncerBP1 = Bounce(BP1,25);
Bounce bouncerBP2 = Bounce(BP2,25);
Bounce bouncerBP3 = Bounce(BP3,25);
Bounce bouncerBP4 = Bounce(BP4,25);
Bounce bouncerBP5 = Bounce(BP5,25);
Bounce bouncerBP6 = Bounce(BP6,25);
Bounce bouncerBP7 = Bounce(BP7,25);
Bounce bouncerPouceGauche = Bounce(PouceGauche,25);



void setup()
{
//setup des entrées TOR
for(byte i = 0; i < 10; i++)
{
pinMode(i, INPUT);
digitalWrite(i, HIGH);
}
myStatsX1.clear(); //explicitly start clean
myStatsY1.clear(); //explicitly start clean
myStatsAccl.clear(); //explicitly start clean
//automatic joystick zero calibration
zero_X = analogRead(X1);
zero_Y = analogRead(Y1);

}// end setup

void loop()
{
// midi in et out
if (usbMIDI.read())
{

if(usbMIDI.getChannel() == reception_midi_channel)
{
if (usbMIDI.getType() == 3) //0 = Note Off, 1 = Note On, 2 = Velocity Change, 3 = Control Change, 4 = Program Change, 5 = After Touch, 6 = Pitch Bend, 7 = System Exclusive
{
byte data1 = usbMIDI.getData1();
byte data2 = usbMIDI.getData2();

if(data1 == CTRL_Accl_OnOff)
{
if(data2 == 0)
{
AcclOnOff = 0;
}
else if(data2 == 127)
{
AcclOnOff = 1;
}
else{}
}
else if(data1 == CTRL_channel_select)
{
midiChannel = data2;
if(midiChannel ==0)
{
midiChannel = 1;
}
else if(midiChannel > 16)
{
midiChannel = 16;
}
else{}
}
else{}
}
else{}
}
else{}
}
else{}
//end read usb midi

// Update the debouncer
bouncerBP0.update ( );
bouncerBP1.update ( );
bouncerBP2.update ( );
bouncerBP3.update ( );
bouncerBP4.update ( );
bouncerBP5.update ( );
bouncerBP6.update ( );
bouncerBP7.update ( );
bouncerBP_Joy.update ( );
bouncerPouceGauche.update ( );
// Get the update value
valBP[0] = bouncerBP_Joy.read();
valBP[1] = bouncerBP0.read();
valBP[2] = bouncerBP1.read();
valBP[3] = bouncerBP2.read();
valBP[4] = bouncerBP3.read();
valBP[5] = bouncerBP4.read();
valBP[6] = bouncerBP5.read();
valBP[7] = bouncerBP6.read();
valBP[8] = bouncerBP7.read();
valBP[9] = bouncerPouceGauche.read();

// send MIDI according to Buttons state
// version momentary switch
/*
for(byte i = 0; i<10; i++)
{
if (valBP != valBP_prev)
{
if(valBP == 1)
{
usbMIDI.sendControlChange(CTRL_num +i, 127, midiChannel);
}
else
{
usbMIDI.sendControlChange(CTRL_num +i, 0, midiChannel);
}
valBP_prev = valBP;
}
}
*/
// version togle switch
for(byte i = 0; i<10; i++)
{
if (valBP < valBP_prev)
{
usbMIDI.sendControlChange(CTRL_num +i, 127, midiChannel);
valBP_prev = valBP;
}
else if (valBP > valBP_prev[i])
{
usbMIDI.sendControlChange(CTRL_num +i, 0, midiChannel);
valBP_prev[i] = valBP[i];
}

}
//
//analog joysticks
valX1 = analogRead(X1);
valY1 = analogRead(Y1);
myStatsX1.add(valX1);
myStatsY1.add(valY1);
valX1_1 = map(valX1,(long)myStatsX1.minimum(), zero_X, 127, 0);
valX1_2 = map(valX1,zero_X,(long)myStatsX1.maximum(), 0, 127);
valY1_1 = map(valY1,(long)myStatsY1.minimum(), zero_Y, 127, 0);
valY1_2 = map(valY1,zero_Y,(long)myStatsY1.maximum(), 0, 127);
if(valX1_1 < 5)
{
valX1_1 = 0;
}
if(valX1_2 < 5)
{
valX1_2 = 0;
}
if(valY1_1 < 5)
{
valY1_1 = 0;
}
if(valY1_2 < 5)
{
valY1_2 = 0;
}
valX1_1 = constrain(valX1_1, 0 , 127);
valX1_2 = constrain(valX1_2, 0 , 127);
valY1_1 = constrain(valY1_1, 0 , 127);
valY1_2 = constrain(valY1_2, 0 , 127);

long time = millis();

if(valX1_1 != valX1_1_prev && time - timeX1_1 > 15){
usbMIDI.sendControlChange(CTRL_Joy, valX1_1, midiChannel);
valX1_1_prev = valX1_1;
timeX1_1 = millis();
}
else{}
if(valX1_2 != valX1_2_prev && time - timeX1_2 > 15){
usbMIDI.sendControlChange(CTRL_Joy+1, valX1_2, midiChannel);
valX1_2_prev = valX1_2;
timeX1_2 = millis();
}
else{}
if(valY1_1 != valY1_1_prev && time - timeY1_1 > 15){
usbMIDI.sendControlChange(CTRL_Joy+2, valY1_1, midiChannel);
valY1_1_prev = valY1_1;
timeY1_1 = millis();
}
else{}
if(valY1_2 != valY1_2_prev && time - timeY1_2 > 15){
usbMIDI.sendControlChange(CTRL_Joy+3, valY1_2, midiChannel);
valY1_2_prev = valY1_2;
timeY1_2 = millis();
}
else{}

//accelerometre
valAccl = analogRead(Accl);
//usbMIDI.sendPitchBend(valAccl,midiChannel);
//myStatsAccl.add(valAccl);
//valAccl = map(valAccl,(long)myStatsAccl.minimum(), (long)myStatsAccl.maximum(), 0, 127);
valAccl = map(valAccl,0, 1023, 0, 127);
valAccl = constrain(valAccl, 0, 127);
if(AcclOnOff == 1)
{
if(valAccl != valAccl_prev && time - timeAccl > 15){
usbMIDI.sendControlChange(CTRL_Joy+4, valAccl, midiChannel);
valAccl_prev = valAccl;
timeAccl = millis();
}
else{}
}
else{}
} //end of loop
You do not have the required permissions to view the files attached to this post.
http://oli-lab.org

Win10 I7/16GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Facebook
http://www.facebook.com/pages/OLI_LAB/3 ... 506?v=wall

oli_lab
Member
Posts: 1016
Location: Brittany, France
Contact:

Post by oli_lab » 21 Aug 2020, 21:24

to control a LED in MIDI :

//pour Teensy
#define channel_Led 16
#define controllerLed1 1
#define LED1 3 //Digital output with PWM
void setup() {
// put your setup code here, to run once:
pinMode(LED1, OUTPUT);
analogWrite(LED1,0);

usbMIDI.setHandleControlChange(OnControlChange);
}

void OnControlChange(byte channel, byte control, byte value) {

if (channel == channel_Led) {
if (control == controllerLed1) {
analogWrite(LED1,value*2);
}
}
else {}
}

void loop() {
// put your main code here, to run repeatedly:

}
http://oli-lab.org

Win10 I7/16GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Facebook
http://www.facebook.com/pages/OLI_LAB/3 ... 506?v=wall

Post Reply