Bluetooth MIDI with HC-05 bluetooth modules

I am currently working on triggering a MIDI note-on message from a master device to a slave device, however I have been having some particularly odd issues on interfacing the two modules. I have been able to successfully pair them 100% of the time. The problem is that the transaction of data is only successful in certain instances. When using the hardware serial ports on Arduino nano, I am able to successfully send and receive a character, however there is an issue with latency between button press on the MASTER and LED indication of the message being received on the SLAVE. I was able to fix this latency issue by using a software serial port for each device.

This led me to another issue, however. The modules successfully made a transaction ONLY when connected to the Arduino IDE and latency greatly decreased while the serial monitor was opened on the master device's USB port. This means I could not get the messages to correctly be received when powering the two Arduinos with the IDE closed or from a wall outlet.

I looked at the UART signals with an analyzer and noticed that when the button was not being pressed on the master, it was sending an 0x82, and when pressed it was sending an 0x8A. The hex values it should be sending however are 0x30 and 0x31 since I am sending the characters '0' and '1'. Even with changing the if statements on the slave to accept these messages, it still was only making a successful transaction under the same conditions.

Any solutions to these odd problems would be greatly appreciated. Thank you. I have attached my code for each module below.

MASTER.ino (547 Bytes)

SLAVE.ino (1.17 KB)