Receive midi data over bluetooth


Hi. I am new to this and could do with some advice. The answer is probably very simple.
I have a MIDI file in an Arduino DUE and I want to send the data (the whole file may be only a few tens of bytes long) in it to my Android device via Bluetooth. The api above works as long as the byte value is less than 127 (0x7F). Once it gets bigger than that the data byte is discarded and replaced by ‘EF BF BD’. As a lot of data in MIDI files are greater than 0x7F this is a problem. If I try using signed or signed bytes the information is stored as comma delimited file (or something).
The Arduino sketch sends the data using a bluetooth.write(byte) command to a standard 05 unit. The file delimiter is 126 (0x7e).

Can anybody help me here.
Many thanks.
Nigel

Hi @nigel,

Rather than using ReceiveText, you probably want to use ReceiveUnsignedBytes, which will return a list of the values from 0-255. By trying to interpret the values as text, anything above 0x7F will be interpreter as a UTF-8 continuation byte, and will fail to parse due to the data not being UTF-8.

Hi EW
Thanks for your swift reply and help.
I did try using ReceiveUnsignedBytes (and SignedBytes) and got some sort of comma separated list complete with square brackets at the beginning and end. This would be fine if I could then (or better on-the-fly) remove those unwanted bytes (ie spaces, commas and brackets) and compress the plain numbers back into single bytes. I hope that the attached screen shot gives a better idea of what I received in the file. Any help on how to strip out and reinterpret would be greatly appreciated.
Both the Arduino sketch shown and the App are cut-down versions of the original so that I can test just the file transfer bits.
Really what I am looking for is a ‘black box’ that I send bytes into at the Arduino end and get exaclty the same bytes out at the Android end. A simple ‘file transfer’ system.
All the best
Nigel

In this topic there are two examples about sending file from Arduino to the App by Bluetooth

Hi Juan
Thanks for your reply and the tip.
I do not have any problems connecting the Due to the Android or sending information form the Due to the Adroid. The problem is that a file transfer from the Due to the Android does not seem to be easily possible. Using ReceiveText as your example shows is OK for text but sending data bytes seems to be a problem. Up to a value of 0x7f the data bytes are passed to the Android with no problem. Over that value the information is garbled as Evan pointed out.
Using ReceiveUnsignedBytes receives the data but delivers a file that has human readable numbers separated by commas etc (so each data byte in the original file now becomes up to 5 data bytes in the received file). This is not what I need but if it is the only method of passing a file form a Due to an Android device I am going to need some help in getting the received data back to the original byte format. Have you any tips as to how I could approach that problem?
Thanks again and have a great weekend
Nigel

You can try sending the information as text in Base64, in a similar way to what I have put in example 16 of the previous message.

Hi Juan
Thanks for that. We have a holiday this weekend so I am going off line for a bit. I will look into your suggestion later (I am not sure that I understand it - I am a real beginner in this stuff).
Thanks again
Nigel

Hi Juan
WOW! Many thanks for your tip. It is just what was needed. I had no idea that such a thing as base64 coding existed, but now I see why.
I have encoded my files in the Arduino Due using Base64.h. I can then pass them to the 05 Bluetooth module and then receive them in the Android, there your system decodes it to the original. Brilliant!
There was one problem that took some time to sort out and I am not entirely happy with my solution so perhaps you can help here too. I can only get your ‘StringToFile’ block to save to a file if I save to a normal file just before. Even then the App will not save the file refered to in your block on the first run after installation but only the subsequent runs - have you any idea why this is?
But, nevertheless, I am delighted with your help and your ideas. Now I hope that I can proceed with the rest of my project.
All the best and thanks again
Nigel

I can only get your ‘StringToFile’ block to save to a file if I save to a normal file just before

Try set Block
Screen1.Initialize
AskForPermission = WRITE_EXTERNAL_STORAGE

Hi Juan
Thanks again. Your suggestion worked first time. Everything is now working fine.

All the best
Nigel