Welcome to %s forums

BrainModular Users Forum

Login Register

Inputting serial data

Tell us what you'd like Usine to do
Post Reply
antwan
Member
Posts: 164
Contact:

Unread post by antwan » 13 Dec 2007, 15:54

hi Olivier,

I wonder if you would have interest in implementing inputting of raw serial data for use with interfacing boards like Arduino / Wiring? This would cancel the need of using programs like Pure Data or Max/MSP in between, inputting the serial data from the USB port and converting it to OSC.

What do you think?

Antwan

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 16 Dec 2007, 19:39

Unfortunately I don't know the Arduino protocol. But it's not a real problem to implement serial i/o modules.

antwan
Member
Posts: 164
Contact:

Unread post by antwan » 18 Dec 2007, 08:32

Hi,

great. Well the arduino microcontroller is programmed with c++ (or c ?)... anyways. i think it's rather straightforward and simple. one should be able to select the serial port (COM #).
here's a simple code loaded to the arduino for reading the digital and analog input pins and sending them for MAX/MSP to read over serial. maybe this gives an idea:

Code: Select all

 /*  
 *  Arduino2Max
 *  Send pin values from Arduino to MAX/MSP
 *  
 *  Arduino2Max.pde
 *  ------------  
 *  This version: .4, October 2007
 *  ------------
 *  Copyleft: use as you like
 *  by Daniel Jolliffe
 *  Based on a sketch and patch by Thomas Ouellet Fredericks  tof.danslchamp.org
 *  
 */


int x = 0;                              // a place to hold pin values
int ledpin = 13;

void setup()
{
  Serial.begin(115200);               // 115200 is the default Arduino Bluetooth speed
  digitalWrite(13,HIGH);              ///startup blink
  delay(600);
  digitalWrite(13,LOW);
  pinMode(13,INPUT);
}



void loop()
{ 

if (Serial.available() > 0){         // Check serial buffer for characters
        
    if (Serial.read() == 'r') {       // If an 'r' is received then read the pins
    
for &#40;int pin= 0; pin<=5; pin++&#41;&#123;      // Read and send analog pins 0-5
    x = analogRead&#40;pin&#41;;
    sendValue &#40;x&#41;;
    &#125;

for &#40;int pin= 2; pin<=13; pin++&#41;&#123;     // Read and send digital pins 2-13
    x = digitalRead&#40;pin&#41;;
    sendValue &#40;x&#41;;
    &#125;
  
    Serial.println&#40;&#41;;                 // Send a carriage returnt to mark end of pin data. 
    delay &#40;5&#41;;                        // add a delay to prevent crashing/overloading of the serial port
  
  &#125;

 &#125;
&#125;

void sendValue &#40;int x&#41;&#123;              // function to send the pin value followed by a "space". 
 Serial.print&#40;x&#41;;
 Serial.print&#40;32, BYTE&#41;; 
&#125;
let me know if this helps at all. i can dig plenty more of material if needed....

antwan

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 18 Dec 2007, 20:23

thanks.
I will help.
But the I can't do anything without a real arduino!

antwan
Member
Posts: 164
Contact:

Unread post by antwan » 20 Dec 2007, 13:54

Although I'm not an actual programmer, I think you might be able to set this up even without having an arduino handy. I'll gladly be your beta tester. Forgive me if what I'm saying is nothing new to you - just trying to discuss this further. The same principle works for also other boards. Basically:
1) What the Arduino sends along the USB cable is coded into the Arduino microchip
2) For reading what is sent through the port, Usine should have the tools.

So let's say that the Arduino code sends a package sized three bytes, each containing one number (like a simple midi command would be). Usine should have the tools to open/close a certain COM-port. Then receive packages of varying sizes (if this is trouble, one could start with, say, 1-5 bytes in size) and the user should be able to treat those bytes separately. To me it seems to be quite like the way in which you've setup the OSC system. Here's another Arduino code, demonstrating input from a switch (=digital input of Arduino) turned into a "midi command" i.e. a 3 byte serial package:

Code: Select all

int buttonA = 2;  // Pin button is connected to

// Key de-bouncing stuff
int lastKey = 0;
long time = 0;
int debounce = 100;	// minimum allowed time between button presses

void setup&#40;&#41;                    // run once, when the sketch starts
&#123;
  pinMode&#40;buttonA, INPUT&#41;;      // sets the digital pin as input
  digitalWrite&#40;buttonA, HIGH&#41;;  // Pull high
  Serial.begin&#40;9600&#41;;           // Start serial output
&#125;

void loop&#40;&#41;                     // run over and over again
&#123;
  if &#40;&#40;digitalRead&#40;buttonA&#41; == LOW&#41; && &#40;millis&#40;&#41; - time > debounce&#41; && lastKey != 1&#41; &#123;
    noteOn&#40;9,56,120&#41;;  // channel 9 - maps to MIDI channel 10 AKA percussion&#41;
                       // note 56 - Cow Bell!
    		       // velocity 120 &#40;127 = max&#41;
    time = millis&#40;&#41;;	// Reset debounce clock
    lastKey = 1;     // Store last button state
  &#125;
  else if &#40;&#40;digitalRead&#40;buttonA&#41; == HIGH&#41; && lastKey == 1&#41;
    lastKey = 0;
&#125;

// Send a MIDI note-on message
void noteOn&#40;byte channel, byte note, byte velocity&#41; &#123;
  midiMsg&#40;channel+0x90, note, velocity&#41;;
&#125;

// Send a MIDI control change
void controlChange&#40;byte channel, byte controller, byte value&#41; &#123;
   midiMsg&#40;channel+0xB0, controller, value&#41;;
&#125;

// Send a general MIDI message
void midiMsg&#40;byte cmd, byte data1, byte data2&#41; &#123;
  Serial.print&#40;cmd, BYTE&#41;;
  Serial.print&#40;data1, BYTE&#41;;
  Serial.print&#40;data2, BYTE&#41;;
&#125;
Also, I can of course point you to some examples of how this has been implemented in PureData, Processing or Max, etc.

Thanks,

antwan

Clearscreen
Member
Posts: 482
Location: Australia
Contact:

Unread post by Clearscreen » 20 Dec 2007, 22:53

Hi Senso, i've just got a couple of these boards as well so i can test things as well if need be. also, theres some pre-made interface code & protocols here http://www.arduino.cc/playground/Interfacing/Firmata that may help. it appears that the guys over there are pretty happy to help write code to allow the board to interface with any software so it might be worth getting in touch with them if you need any assistance?
regards
C.

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 21 Dec 2007, 08:58

thanks for the proposition.
I know by (small) experience that creating low level hardware interfaces is not so easy...especially if you don't have the hardware itself!
The first thing is to buy one!

antwan
Member
Posts: 164
Contact:

Unread post by antwan » 21 Dec 2007, 09:15

sure, I understand.
you could get an arduino, one simple switch and some connecting wire and you're basically ready to go. maybe one led to test the data the other way...

if you like, you could also check the source code of this simple opensource application called S2MIDI, which basically receives data from a serial port and sends it forward along a virtual midi port.
http://www.memeteam.net/2007/s2midi/
and the code is available at:
http://code.google.com/p/s2midi/source/

I have used this succesfully with Arduino. It works only one way though.

best regards,

antwan

Clearscreen
Member
Posts: 482
Location: Australia
Contact:

Unread post by Clearscreen » 21 Dec 2007, 23:08

fair enough senso. let us know if/when you need testers!

headphoner
Member
Posts: 225
Contact:

Unread post by headphoner » 09 Feb 2009, 19:34

Hi,

I just begin with arduino, so i want to know your experiences with arduino and usine.

I tried S2MIDI but it cost a lot of cpu on my computer...anybody improved other solution to receive serial data from the arduino to usine?

antwan
Member
Posts: 164
Contact:

Unread post by antwan » 09 Feb 2009, 21:45

Hi,

No I'm still stuck using S2MIDI. I'd love to be running only one software though (=Usine!)...

antwan

Clearscreen
Member
Posts: 482
Location: Australia
Contact:

Unread post by Clearscreen » 26 Feb 2009, 01:10

any chance of this being integrated into usine senso? i think i can lend you an arduino board if it helps...

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 26 Feb 2009, 09:13

Not definitively dead but, not easy to implement because I don't have any serial hardware neither a serial port on my development machine...
I have uploaded a test program http://sensomusic.com/forums/uploaded/T ... alPort.zip.
Tel me if it works (you can see incoming data's) and what is the speed of the communication. It's a first step. If it works it means that it's easy to implement.

I concentrate my work on the global ergonomic of Usine and this kind of module is a perfect candidate for a User module (SDK)?

Clearscreen
Member
Posts: 482
Location: Australia
Contact:

Unread post by Clearscreen » 26 Feb 2009, 11:09

senso wrote:I have uploaded a test program http://sensomusic.com/forums/uploaded/T ... alPort.zip
unfortunately the download is coming up '403 Forbidden'? looking forward to trying it! :)


antwan
Member
Posts: 164
Contact:

Unread post by antwan » 26 Feb 2009, 20:04

Hi,

I tried the test program but there was one little problem :) When I selected the COM port and clicked Open the software gives an alert box that states:
"Demo version runs only with Delphi or C++Builder IDE"

antwan

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 26 Feb 2009, 20:41

normal it's just a demo test program.

antwan
Member
Posts: 164
Contact:

Unread post by antwan » 26 Feb 2009, 20:53

yes but I forgot to clarify that after this message the program quits. So apparently it doesn't want to run without Delphi or C++Builder IDE?

a

Clearscreen
Member
Posts: 482
Location: Australia
Contact:

Unread post by Clearscreen » 27 Feb 2009, 00:05

antwan wrote:yes but I forgot to clarify that after this message the program quits. So apparently it doesn't want to run without Delphi or C++Builder IDE?

a
just to confirm, same trouble here senso...

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 27 Feb 2009, 00:18

oups again.
I should sleep a little more....
sorry for the bad file.
Forget the test.

Clearscreen
Member
Posts: 482
Location: Australia
Contact:

Unread post by Clearscreen » 28 Feb 2009, 06:15

No worries - now go get some sleep :)! when you get around to it remember my offer to lend you an arduino board for testing may still stand, i don't have any immediate plans for it. also, i'd be happy if only the firmata protocol (http://www.arduino.cc/playground/Interfacing/Firmata) got implemented as this would at least allow the bords I/O to be available for use in Usine.

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 28 Feb 2009, 09:51

Interesting new protocol.
I'll watch it's future developments.

Clearscreen
Member
Posts: 482
Location: Australia
Contact:

Unread post by Clearscreen » 01 Mar 2009, 01:04

it's been around for a few years, i think their on version 2 now. i'm currently still using an old version that works with vvvv to get my arduino to talk OSC and midi. it does make life a fair bit easier...

headphoner
Member
Posts: 225
Contact:

Unread post by headphoner » 01 Mar 2009, 11:48

Hi,

I finally found the solution for low cost of cpu with S2MIDI.
i have to use a very slow baud.

it seems that arduino vs usine are interesting a lot of people ...1296 views.

Clearscreen
Member
Posts: 482
Location: Australia
Contact:

Unread post by Clearscreen » 01 Mar 2009, 22:11

Interesting - i haven't seen s2midi before. i'll give it a try...

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests