Cabbage Logo
Back to Cabbage Site

Cabbage and Arduino

Hi all!

I was wondering if someone of you had already try to use the OSC to communicate with Arduino.

I found some informations in the FLOSS manual that suggest to make them transmitting using Processing or PD. Is it necessary to pass from another software?

I am using it to connect some DIY controllers such as a piezoelectric and a gyroscope sensors.

Thanks in advance! :wink:

You shouldn’t have to use OSC at all. Look at the bottom section of the floss manual here. It describes how you can interface directly with the Arduino using the serial opcodes. If I was you I would do it this way and bypass all other software.

Ahhh…in this way doesn’t seem too difficult!

Thanks

I know people have run Cabbage on a RPI. With a touch screen it would make a nice sound toy. But I probably do prefer the tactile nature of switches and faders.

You could always pick up an Arduino shield for the RPI and have the best of both worlds :wink:

1 Like

Hi all,

I am still trying to communicate from Cabbage to Arduino.
As you suggested I used the serial opcodes, but it seems to have some trouble finding the communication port, sometimes it reports this error on the Csound output: INIT ERROR in instr1:/COM7 not available.

So, I ran the same .csd on CsoudnQt using the same port COM7 and it worked. :confused:
When I play it, Arduino start blinking, but on Cabbage it doesn’t.

Does anyone had already tried to communicate using the serial opcodes on Cabbage?

thanks!

If it works with CsoundQT then it looks like the fault of Cabbage. I’m not sure what though. Even the simplest examples fail with Cabbage?

I used a .csd based on that one that I found in the floss manual by Sigurd Saue, even simpler, because I am just printing one potentiometer value.

Prova_serial.csd (1.3 KB)

I will ask Sigurd if he ever tried it with Cabbage. Hopefully yes, and hopefully it worked :wink:

1 Like

What OS are you using?

I am using Windows 10 Home x64…my MacBook Pro is died after a short circuit with Arduino :sweat_smile:

No way, you killed it with an Arduino? Wow :joy: I asked Sigurd, but he can’t think of anything that might causing the problem. I’ll take a look once I am back.

Yes, with an Arduino and a 9V battery…Do not worry, in the meantime I will try on other OS and computer!

Ah, I took a shot on the new cabbage release but I get this message:

error: syntax error, unexpected T_IDENT  (token "serialBegin") 
from file C:\Csound\Csoundino_04.csd (1)
 line 23:
>>>iPort	serialBegin <<<
Unexpected untyped word iPort when expecting a variable

It seems that it is not recognizing the serialBegin opcode

That’s strange as the latest Cabbage use the latest version of Csound. Can you try the CsoundQT that comes with the latest version of Csound and see if that works?

I tried it on the CsoundQt Version 0.9.5 that comes with Csound 6.10 and it works, but I noticed that if I stop and run again the csd It gives the same error that I found in Cabbage:

INIT ERROR in instr1:/COM7 not available

After that I need to close CsoundQt and open it again if I want to get it work.

Maybe the port is being opened ok but is not closing properly, thus preventing it from being opened again. That would explain the Cabbage error. Can you confirm that the same thing happens if you run the .csd from the command line?

I ran ten times the same csd from the command line and it worked properly, printing values from a potentiometer and controlling the amplitude of a sound.
On csoundQt it works for the first time, after that it says that the port is not available or it crashes. :disappointed_relieved:

Thanks for checking. It would appear that recompiling an instrument that uses these opcodes is causing the problem. I will prepare a simplified example in C for the Csound devs, but it won’t be till later next week at the earliest. I’m afraid until then you’ll have to down tools and work on something else. :frowning:

Do not worry, I got lots to do and meantine I will continue to work from the terminal to test the external controllers. :slight_smile:

1 Like

Hi there,

I’m trying to create another protocol to communicate between Arduino and Csound. The difference with the already existing serial opcodes is that I would like to store a 10 bit arduino’s value in two bytes.

I wrote the arduino sketch to convert an int value in two bytes, but now I was wondering how can I reconvert the function in Csound. Can I make it as a UDO? Could be an idea or it would be to complicated? :confused:

`void TrasformaDueByteInInt( byte byteA, byte byteB, int &valore )
  {
  bool brA0;
  bool brA1;
  bool brA2;
  bool brA3;
  bool brA4;
  bool brA5;
  bool brA6;
  bool brA7;
  
  bool brB0;
  bool brB1;
  bool brB2;
  bool brB3;
  bool brB4;
  bool brB5;
  bool brB6;
  bool brB7;

  int val_ricostruitoA = 0;
  int val_ricostruitoB = 0;

  brA0 = byteA & 1; 
  brA1 = byteA & 2; 
  brA2 = byteA & 4; 
  brA3 = byteA & 8; 
  brA4 = byteA & 16; 
  brA5 = byteA & 32; 
  brA6 = byteA & 64; 
  brA7 = byteA & 128;

  brB0 = byteB & 1; 
  brB1 = byteB & 2; 
  brB2 = byteB & 4; 
  brB3 = byteB & 8; 
  brB4 = byteB & 16; 
  brB5 = byteB & 32; 
  brB6 = byteB & 64; 
  brB7 = byteB & 128;

Serial.print ( "Byte READ A = " );
Serial.print ( brA0 );
Serial.print ( brA1 );
Serial.print ( brA2 );
Serial.print ( brA3 );
Serial.print ( brA4 );
Serial.print ( brA5 );
Serial.print ( brA6 );
Serial.print ( brA7 );
Serial.println ( "" );

Serial.print ( "Byte READ B = " );
Serial.print ( brB0 );
Serial.print ( brB1 );
Serial.print ( brB2 );
Serial.print ( brB3 );
Serial.print ( brB4 );
Serial.print ( brB5 );
Serial.print ( brB6 );
Serial.print ( brB7 );
Serial.println ( "" );

// Use the free bits to check that you have not lost data

if( brA0 != 1 ) { Serial.println( "ERRORE SU CODICE A0" ); }
if( brA1 != 1 ) { Serial.println( "ERRORE SU CODICE A1" ); }
if( brA7 != 1 ) { Serial.println( "ERRORE SU CODICE A7" ); }
if( brB0 != 0 ) { Serial.println( "ERRORE SU CODICE B0" ); }
if( brB1 != 0 ) { Serial.println( "ERRORE SU CODICE B1" ); }
if( brB7 != 0 ) { Serial.println( "ERRORE SU CODICE B7" ); }

  val_ricostruitoA |= ( brA0 ?   1 : 0 );
  val_ricostruitoA |= ( brA1 ?   2 : 0 );
  val_ricostruitoA |= ( brA2 ?   4 : 0 );
  val_ricostruitoA |= ( brA3 ?   8 : 0 );
  val_ricostruitoA |= ( brA4 ?  16 : 0 );
  val_ricostruitoA |= ( brA5 ?  32 : 0 );
  val_ricostruitoA |= ( brA6 ?  64 : 0 );
  val_ricostruitoA |= ( brA7 ? 128 : 0 );
Serial.print( "Valore INTERMEDIO A ricostruito = " );
Serial.println( val_ricostruitoA );

  val_ricostruitoB |= ( brB0 ?   1 : 0 );
  val_ricostruitoB |= ( brB1 ?   2 : 0 );
  val_ricostruitoB |= ( brB2 ?   4 : 0 );
  val_ricostruitoB |= ( brB3 ?   8 : 0 );
  val_ricostruitoB |= ( brB4 ?  16 : 0 );
  val_ricostruitoB |= ( brB5 ?  32 : 0 );
  val_ricostruitoB |= ( brB6 ?  64 : 0 );
  val_ricostruitoB |= ( brB7 ? 128 : 0 );
Serial.print( "Valore INTERMEDIO B ricostruito = " );
Serial.println( val_ricostruitoB );

  valore = 0;
  valore |= ( brA2 ?   1 : 0 );
  valore |= ( brA3 ?   2 : 0 );
  valore |= ( brA4 ?   4 : 0 );
  valore |= ( brA5 ?   8 : 0 );
  valore |= ( brA6 ?  16 : 0 );

  valore |= ( brB2 ?  32 : 0 );
  valore |= ( brB3 ?  64 : 0 );
  valore |= ( brB4 ? 128 : 0 );
  valore |= ( brB5 ? 256 : 0 );
  valore |= ( brB6 ? 512 : 0 );

Serial.print( "Valore TOTALE ricostruito = " );
Serial.println( valore );

  }//TrasformaDueByteInInt`

You want to combine two incoming bytes of data, combine and represent them as a single value? I guess you could considering you have bit-wise operators in Csound? But I’m no expert on this serial stuff.