Hi, I recently made a Notes And Volts NaV-1 synthesizer, which has an atmega328p for the brains, and a soundgin synthesizer chip making the noise.
You can find the schematic here:
The midi signal is coming in on the hardware TX/RX pins at 31250, and then a 9600 SoftwareSerial object talks to the soundgin chip on pins 3 and 4.
The guy who invented this design plugged it all in and fired it up and it worked just fine, but I've not been able to get the synth to not drop notes. I believe I have eliminated the possibility of hardware being the problem, so now I'm taking a look at software, but this is by far the most complex thing I've ever built, and I haven't dealt with SoftwareSerial objects on the arduino before.
The software seems to be dropping midi signals most of the time without passing them on to the soundgin... intermittently it will work, though. I've had several EE's with arduino experience looking at this for about 3 weeks now and everybody's stumped.
Could somebody that knows a whole lot about serial on the 328p do a code review to help me figure out why the midi signals are being dropped?
My main loop is just this:
void loop() { // Main Loop
MIDI.read(); // See if there are any new MIDI messages
menu(); // Check state of Rotary Encoder and Buttons - Update LCD
}
And the callback function for the midi library is this:
void MyHandleNote(byte channel, byte pitch, byte velocity) {
if (velocity != 0) {
digitalWrite(LED,HIGH); //Turn LED on
if (currentNote == 0) {
currentNote = pitch;
trigger(pgm_read_byte(&lookup[currentNote]));
}
else {
newNote = pitch;
trigger(pgm_read_byte(&lookup[newNote]));
}
} else {//A NOTE ON message with a velocity = Zero is actualy a NOTE OFF
if (pitch == newNote){
newNote = 0;
trigger(pgm_read_byte(&lookup[currentNote]));
}
else if (pitch == currentNote && newNote != 0){
currentNote = newNote;
newNote = 0;
trigger(pgm_read_byte(&lookup[currentNote]));
}
else if (pitch == currentNote){
digitalWrite(LED,LOW);//Turn LED off
release();
currentNote = 0;
newNote = 0;
}
}
}
If you want to see any other parts of the code, you can find it here:
And here's a video to give you an idea of what the behavior is like:
Thanks.