serialEvent() disabled w/ arduino on MacOSX
in
Integration and Hardware
•
1 year ago
Hello, all.
I'm just getting into this whole business but it seems pretty straight forward.
Long story short, I'm making a midi controller on an arduino uno and sending the data serially to processing.
Due to a few serial library quirks I found the only way to get around a bug that only affected Mac OSX was to use the 2.0a4 alpha. That's my first concern.
Anyway, I'm using the standard midi example from Arduino to test my Processing app.
Arduino:
- void setup() {
- // Set MIDI baud rate:
- Serial.begin(38400);
- }
- void loop() {
- // play notes from F#-0 (0x1E) to F#-5 (0x5A):
- for (int note = 0x1E; note < 0x5A; note ++) {
- //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
- noteOn(0x90, note, 0x45);
- delay(100);
- //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
- noteOn(0x90, note, 0x00);
- delay(100);
- }
- }
- // plays a MIDI note. Doesn't check to see that
- // cmd is greater than 127, or that data values are less than 127:
- void noteOn(int cmd, int pitch, int velocity) {
- Serial.write(cmd);
- Serial.write(pitch);
- Serial.write(velocity);
- }
- import processing.serial.*; //Import native Serial Library
- import rwmidi.*; //External Midi library
- //Declarations
- MidiOutput output; //Midi output
- Serial port; //Input from Arduino
- MidiOutputDevice device;//Available Device
- int note;
- int channel;
- int velocity;
- int[] dat;
- void setup()
- {
- //stuff for debugging
- println("Serial Devices");
- println(Serial.list()); //Print abvailable Serial Ports
- println("\n");
- println("Midi Devices");
- println(RWMidi.getOutputDevices());//Print available Midi Devices
- //End Debug
- port = new Serial(this, Serial.list()[0], 38400); //Links to arduino on port 0
- device = RWMidi.getOutputDevices()[1];//SHOULD be Apple IAC driver
- output = device.createOutput();//creates output on IAC driver
- println("asdf");
- }
- void draw()
- {
- println(port.read());
- // listen();
- /*
- //This was test code
- output.sendNoteOn(1,63,127);
- println("NoteOn");
- delay(125);
- output.sendNoteOff(1,63,127);
- println("NoteOff");
- delay(125);
- */
- }
- void serialEvent(Serial input)
- {
- for(int i=0;i<3;i++)
- {
- dat[i]=input.read();
- }
- output.sendNoteOn(dat[0],dat[1],dat[2]);
- println("NOTE");
- }
Not really sure what this is, but It doesn't occur until a non '-1' value is received on the port.
Thanks in advance!
1