Go Down

Topic: Arduino ProMicro MIDI interface - newbie question (Read 1 time) previous topic - next topic

ingo69

Hi everybody!

I'm new here and completely new to C programming.
(I.e. I have absolutely no idea as of now!)

I'm trying to use a ProMicro as a MIDI interface and got it working already.
Now I'd like to send an ID for using more than one interface.

I was trying to add a while loop (during start up of Pd) to send an ID at the beginning and then go into the normal MIDI interface function.

Unfortunately I'm getting this error when I try to compile:

MIDI_serial_USBv2.ino:23:1: error: expected unqualified-id before 'while'


Another two questions:

1) will the second, normal loop start automatically or do I have to add something that the code won't stop after the while loop.

2) How do I activate the pullup resistor (on digitalIn Pin 5)


Here is the code:


#define HWSERIAL Serial1


int counter = 0;

/* define Midi Port identifier*/
int midi_id_SelectorPin = 5;       // digital pin number to check midi_id number
const int midiport_id0 = 244;     // unused midi status byte
const int midiport_id1 = 245;     // unused midi status byte


void setup() {
 
  Serial.begin(115200);
  HWSERIAL.begin(31250);
  pinMode(midi_id_SelectorPin, INPUT);  // add "set pull up to HIGH" ?
}

/*==============================================================
 * 1st LOOP()
 *==============================================================*/

while (counter < 20)  // count 20 sec ans send ID before starting main loop
  {
    int midi_id_SelectorState = digitalRead(midi_id_SelectorPin);
    if (midi_id_SelectorState = LOW()) Serial.write(midiport_id0);
    if (midi_id_SelectorState = HIGH()) Serial.write(midiport_id1);
   
    counter = counter + 1;
    delay (1000);
    end while;
  }

/*==============================================================
 * 2nd LOOP()
 *==============================================================*/

  void loop()  //  Send USB to Serial and Serial to USB
  {
  if (Serial.available()) Serial1.write(Serial.read());
  if (Serial1.available()) Serial.write(Serial1.read());

  }



Any help would be greately appreciated!

Thanks!
Ingo

tmd3

The Arduino IDE runs sets things up so that setup() runs once, and then loop() executes repeatedly forever.  The code that you call "1st LOOP()" lies in a no man's land between them.  I presume that you want that code to run only one time.  Perhaps it belongs in setup()?

After that, you'll find a couple of other errors:
  • HIGH and LOW are constants.  When you follow them with parentheses, as in, "LOW()," the compiler tries to interpret it as a function, and throws an error.
  • "end while;" doesn't make sense in C.  It looks like reasonable BASIC, but it doesn't work here. The end of a while loop is the closing "}" that matches the opening "{".

Fix those, and it will compile.  I can't tell whether it will work.

Finally, please read the sticky post, "How to use this forum," linked near the top of the list of topics for each section of the forum.  In particular, read about code tags.  Posting code inside code tags will avoid unexpected misinterpretations of symbols in the code by the forum's software.

ingo69

Thanks a lot!!!
It's compiling perfectly now!

Now I just need to figure out how to set digitalIn pin5 to HIGH so I can get it to default to HIGH and switch when connecting to ground.
I've done that using firmata in Pd but I still have to figure out how to set this up directly ...

(and yes, I'll take a closer look at the board rules before posting the next time)

Ingo

tmd3

You'll be happier if you figure it out for yourself.  Check the reference page, here, and look at functions pinMode() and digitalWrite().  I don't fully understand what you hope to accomplish, but, intuitively, I believe that these two functions will help.

ingo69

Yep, that's exactly what I need.

Setting up pin 5 with the pull up resistor will make pin 5 report as HIGH by default.
By connecting a jumper or not to ground I can make one of the two Arduinos report as LOW on pin 5.

During startup the Arduino will then send either 244 or 245 repeatedly which will allow me identifying each of them and routing the MIDI data to either the first or second MIDI software input.

After the while loop the normal MIDI data will be sent to either the first ot second MIDI input in Pd.
I can either treat the incoming MIDI my own way or by using e.g. [send #ctlin], etc. to make it show up as a normal standard MIDI input data inside of Pd.

Before I had an identifier (244 or 245) in front of each byte which unnecessarily doubled the amount of data to be transmitted ...

The other option would have been adding 16 to each status byte on the second interface so that the Arduino sends MIDI like Pd handels different MIDI interfaces. That would require much more code, though.


Ingo

Grumpy_Mike

Why not just use different MIDI channels on the two Arduinos? It is built into MIDI, you have 16 channels.

ingo69

The MIDI Ins need to be set up for different controllers like wind controllers (e.g. EWI), keyboards, MIDI guitars, etc. at the same time. All inputs need to be multi timbral (i.e. use all channels) and need different dynamic controller numbers, curves, and so on.

Go Up