music maker featherwing strange behavior
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- ElbyM
- Posts: 24
- Joined: Sun Sep 08, 2019 8:53 am
music maker featherwing strange behavior
I have a Feather/music-maker Featherwing combination that I've converted to MIDI (by soldering the jumper). When I load the "feather midi" example program, I get no sound out of the headphone jack. HOWEVER, if I separate the Feather from the Featherwing (with Feather plugged into USB), and then reconnect them, I head ascending tones in the headphones. Hit the "reset" button, or unplug / reconnect to USB -> no sound. Remove / reconnect the shield -> sound. Completely repeatable. And makes the combination unusable. What's going on here, and how do I fix this? Thanks.
- mikeysklar
- Posts: 14194
- Joined: Mon Aug 01, 2016 8:10 pm
Re: music maker featherwing strange behavior
Can you post the code that you are running or link if unmodified?
It is not clear to me if you are using Arduino or CircuitPython and which MIDI example code you are running.
It is not clear to me if you are using Arduino or CircuitPython and which MIDI example code you are running.
- ElbyM
- Posts: 24
- Joined: Sun Sep 08, 2019 8:53 am
Re: music maker featherwing strange behavior
Ah, I should have been clearer. It comes from the arduino Adafruit VS1053 Library examples, and is called "feather_midi". I'm using the code unmodified, as listed below
Code: Select all
// Solder closed jumper on bottom!
// See http://www.vlsi.fi/fileadmin/datasheets/vs1053.pdf Pg 31
#define VS1053_BANK_DEFAULT 0x00
#define VS1053_BANK_DRUMS1 0x78
#define VS1053_BANK_DRUMS2 0x7F
#define VS1053_BANK_MELODY 0x79
// See http://www.vlsi.fi/fileadmin/datasheets/vs1053.pdf Pg 32 for more!
#define VS1053_GM1_OCARINA 80
#define MIDI_NOTE_ON 0x90
#define MIDI_NOTE_OFF 0x80
#define MIDI_CHAN_MSG 0xB0
#define MIDI_CHAN_BANK 0x00
#define MIDI_CHAN_VOLUME 0x07
#define MIDI_CHAN_PROGRAM 0xC0
#if defined(ESP8266) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
#define VS1053_MIDI Serial
#else
// anything else? use the hardware serial1 port
#define VS1053_MIDI Serial1
#endif
void setup() {
delay(1000);
Serial.begin(115200);
Serial.println("VS1053 MIDI test");
VS1053_MIDI.begin(31250); // MIDI uses a 'strange baud rate'
midiSetChannelBank(0, VS1053_BANK_MELODY);
midiSetChannelVolume(0, 127);
midiSetInstrument(0, VS1053_GM1_OCARINA);
}
void loop() {
for (uint8_t i=60; i<69; i++) {
midiNoteOn(0, i, 127);
delay(100);
midiNoteOff(0, i, 127);
}
delay(1000);
}
void midiSetInstrument(uint8_t chan, uint8_t inst) {
if (chan > 15) return;
inst --; // page 32 has instruments starting with 1 not 0 :(
if (inst > 127) return;
VS1053_MIDI.write(MIDI_CHAN_PROGRAM | chan);
delay(10);
VS1053_MIDI.write(inst);
delay(10);
}
void midiSetChannelVolume(uint8_t chan, uint8_t vol) {
if (chan > 15) return;
if (vol > 127) return;
VS1053_MIDI.write(MIDI_CHAN_MSG | chan);
VS1053_MIDI.write(MIDI_CHAN_VOLUME);
VS1053_MIDI.write(vol);
}
void midiSetChannelBank(uint8_t chan, uint8_t bank) {
if (chan > 15) return;
if (bank > 127) return;
VS1053_MIDI.write(MIDI_CHAN_MSG | chan);
VS1053_MIDI.write((uint8_t)MIDI_CHAN_BANK);
VS1053_MIDI.write(bank);
}
void midiNoteOn(uint8_t chan, uint8_t n, uint8_t vel) {
if (chan > 15) return;
if (n > 127) return;
if (vel > 127) return;
VS1053_MIDI.write(MIDI_NOTE_ON | chan);
VS1053_MIDI.write(n);
VS1053_MIDI.write(vel);
}
void midiNoteOff(uint8_t chan, uint8_t n, uint8_t vel) {
if (chan > 15) return;
if (n > 127) return;
if (vel > 127) return;
VS1053_MIDI.write(MIDI_NOTE_OFF | chan);
VS1053_MIDI.write(n);
VS1053_MIDI.write(vel);
}
- mikeysklar
- Posts: 14194
- Joined: Mon Aug 01, 2016 8:10 pm
Re: music maker featherwing strange behavior
If you have a serial console open with the Feather + FeatherWing connected are you able to see where the code is getting stuck? Some additional print lines might be necessary.
- ElbyM
- Posts: 24
- Joined: Sun Sep 08, 2019 8:53 am
Re: music maker featherwing strange behavior
That was exactly the hint I needed, Mike; thanks! Turns out the #if at the top of the code is causing VS1053_MIDI to be set to Serial, which is resulting in the setup code first setting Serial to 115200 baud and writing a print message, and then immediately setting it to 31250 baud and writing MIDI messages. Removing the initialization/print OR putting a delay after it fixes the problem. If anyone from Adafruit reads this, please fix this bug in the example code!
- mikeysklar
- Posts: 14194
- Joined: Mon Aug 01, 2016 8:10 pm
Re: music maker featherwing strange behavior
@ElbyM,
Nice job finding the offending line.
Which model of Feather board were you using with the music maker featherwing?
I ask because the example code is trying to figure out which serial port to use based on the processor model. Maybe your Feather boards needs to be added to the list to use Serial instead of Serial1?
Nice job finding the offending line.
Which model of Feather board were you using with the music maker featherwing?
I ask because the example code is trying to figure out which serial port to use based on the processor model. Maybe your Feather boards needs to be added to the list to use Serial instead of Serial1?
Code: Select all
#if defined(ESP8266) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
#define VS1053_MIDI Serial
#else
// anything else? use the hardware serial1 port
#define VS1053_MIDI Serial1
#endif
Please be positive and constructive with your questions and comments.