hairless-midiserial
hairless-midiserial copied to clipboard
Stuck at opening serial port
Hello,
Thank you for the Hairless MIDI software it has been working great the past couple of weeks, but today for some reason it stalls when opening serial port. I am using an arduino with an midi jack to send the notes and the Hairless software to interface it with VDMX. Any idea as to what I can do to fix this issue?
Also just to note... if I enable the serial.print commands then it does show errors, so there is a connection. It just stalls when the code is as it is below, of which has worked perfectly the past few weeks. I just can't figure it out.
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
int pirPin = A1; int val = 0; int pirState = LOW; int ledPin1 = 9; int ledPin2 = 8; int ledPin3 = 10; int ledPin4 = 11;
void setup(){
MIDI.begin(); Serial.begin(115200); pinMode(pirPin, INPUT); pinMode (ledPin1, OUTPUT); pinMode (ledPin2, OUTPUT); pinMode (ledPin3, OUTPUT); pinMode (ledPin4, OUTPUT); }
void loop(){
float a0value = analogRead(0); float inches = 0.496 * a0value; //Serial.print("\nThe value captured from pin a0 is: "); //Serial.println(a0value); //Serial.print("\nThe distance in inches is "); //Serial.println(inches); //delay (2000);
val = digitalRead(pirPin);
if (inches < 590 && val == HIGH){
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin4, LOW);
if(pirState == HIGH){
MIDI.sendNoteOn(42,127,1); // Send a Note (pitch 42, velo 127 on channel 1)
delay(2000);
pirState = LOW;
}
}
else if (inches > 590 && val == LOW){
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin4, HIGH);
if(pirState == LOW){
MIDI.sendNoteOn(62,127,1); // Send a Note (pitch 42, velo 127 on channel 1)
delay(2000);
pirState = HIGH;
}
}
}
Hello,
Did you check the Baud Rate on the preferences of your Hairless MIDI Serial Bridge? It should match your Arduino Sketch. Your sketch is currently at 115200, so your Hairless MIDI Serial Bridge should be the same. If it still doesn't work, try changing the Baud Rates. My projects seem to work best at 38400. As to how this affects sketches, I'm not really sure. Hope this helps.
Try to reinstall the Serial Bridge. This solution also worked for me when I suddenly had interrupted communication between Arduino and Hairless.
Hi,
Apart from @bdumaguina's suggestion to check the baud rate, I can't think of anything else. The Serial.print() statements are unfortunately incompatible with Hairless Midi. There is a "MIDI Debug" command to send messages but it's kind of clunky to use unfortunately.
Looking at your sketch, it looks like as long as the LEDs are blinking then MIDI messages should be sent. You can verify this by looking at the "TX" light on the Arduino.
If you're not sure whether MIDI messages are being sent, try a really simple sketch like
void loop() { MIDI.sendNoteOn(42,127,1); // Send a Note (pitch 42, velo 127 on channel 1) delay(1000); MIDI.sendNoteOff(42); // Send a Note (pitch 42, velo 127 on channel 1) delay(1000); }
For a MIDI equivalent of "Blink" :)
- Angus
PS In your sketch there don't seem to be any Note Off messages. Is that intentional?
Hi,
I have been away from the computer for a few days. Thank you for all of the quick responses. @projectgus I only used the serial print function to read the variables of the proximity sensors in the Arduino serial monitor... turned them on in hairless just to see if there was anything being sent out.
I am pretty new to this - I found that the code I wrote required all 3 sensors to be activated at once or not at all for the midi notes to be sent. One of my sensors had a loose connection and ended being the issue. I found this out after hours of troubleshooting code and ultimately re-writing the code. The new code works best anyway as it separates the 3 sensors so that it no longer needs all 3 to send the note.
I am using the code below to switch videos based on the movement of viewers in the space. Works well and thanks again for your quick responses.
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
int pirPin = A1; int val = 0; int pirState = LOW; int ledPin1 = 9; int ledPin2 = 8; int ledPin3 = 10; int ledPin4 = 11;
void setup(){
MIDI.begin(); Serial.begin(9600); pinMode(pirPin, INPUT); pinMode (ledPin1, OUTPUT); pinMode (ledPin2, OUTPUT); pinMode (ledPin3, OUTPUT); pinMode (ledPin4, OUTPUT);
}
void loop()
{
float a0value = analogRead(A0);
float inches = a0value;
float a2value = analogRead(A2); float inches2 = a2value;
val = digitalRead(pirPin);
if (inches < 800 || inches2 < 100 || val == HIGH)
{
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin4, LOW);
MIDI.sendNoteOn(42,127,1); // Send a Note (pitch 42, velo 127 on channel 1)
delay(1000);
MIDI.sendNoteOff(42,0,1); // Send a Note (pitch 42, velo 127 on channel 1)
delay(1000);
pirState = LOW;
}
else if (inches > 800 || inches2 > 100 || val == LOW)
{
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin4, HIGH);
MIDI.sendNoteOn(82,127,1); // Send a Note (pitch 42, velo 127 on channel 1)
delay(1000);
MIDI.sendNoteOff(82,0,1); // Send a Note (pitch 42, velo 127 on channel 1)
delay(1000);
pirState = LOW;
} }
Hi,
Sorry for the very slow reply here. This sketch looks fine, I think maybe the problem is something on the PC side? Can you explain where all the connections are made (from where to where), I'm a little confused about where you mentioned that there was a MIDI jack on the Arduino.
Angus