Bluetooth+DAC+preamp

The board for the DAC and preamp have been designed in Week 10 and Week 13 . Now, it is time to finish this work with the end goal of sending and receiving the realtime audio wirelessly.

Unfinished business: bluetooth communication

In Week 13, I was able to wake up the Bluetooth module, and figured how to set the hardware UART communication with the XMega. Now, let us check that we can actually communicate and attempt to do the following task: send some message from the Android phone to the Xmega (over the bluetooth), and have Xmega responding only when the sent message is "hi". The response message, for instance, is: "Hello, how are you?"

The combination of the Xmega user manual and this tutorial helped me establish all the parameters for the hardware UART communication between the RN4871 bluetooth module and the XMega (with the 115200 baud rate).

Establising pins and Serial code communications

On my board, pins D6 and D7 are the RX and TX connected to the FTDI cable, while C2 and C3 are the RX and TX connected to the bluetooth module. Note that I had to do the remapping for the pins D6 and D7, since by default, XMega puts the UART functionality on pins D2 and D3.

With that, I have written a script, which prints out everything that comes from the Bluetooth module. For printing the messages from the FTDI cable, I'm using the Neil's term.py code.

Communicating with Bluetooth

In this script, I'm also sending the messages to wake up the Bluetooth module (with '$$$'), open the default services (with 'SS, C0') including UART Transparent (which we will need later), and reboot the module ('R, 1').

Following this script, the board becomes active and any device supporting the Bluetooth Low Energy modules (BLE) will recognize it. Note that the module will still be recognizable even in the absence of these initial commands, but one would not be able to talk to the board.

Now it is time to check that the code works. I have installed the 'BLE Scanner' on my Android phone, connected to the board.

Sending a message from phone to the XMega

Xmega is talking

Now, I have spent quite some time trying to find simple ways of sending scripts from the Desktop computers, and in order to be able to progress further (going in spirals as suggested by Neil), I will temporarily focus on sending the audio files via the FTDI cable.

DAC on XMega

To check if my board can generate analog signals, I have programmed my microcontroller with the Jake's code . The result of this test is a nice sinusoid on one of the channels, which indicated to me that the microcontroller was in a great condition.

My board also contains 2 audio op-amps (LM4861), which I use in order to pre-amplify the signal coming from the DAC. I have set up the gain of these opamps to 10, and a brief check with a scope indicated to me that this was indeed the case.

Sending the (midi) audio file over the FTDI cable

To simplify the task, I have decided to send the midi file. The reason for that is that midi is much easier to work with than the audio file. On top of having no need to decode/encode the midi format (unlike the regular audio files), the 8 bit that I'm working with and the limited bandwidth are hard to apply for sending the regular audio files (while one could definitely send the 16 bit signals, but at a lower rate, decoding the compressed files will require a significant amount of Xmega resources, which I prefer not to do). As for the communication means, I for now will do it with the FTDI cable, since at a high level it requires the same push of the midi files, matching the playback rate and processing on the DAC as the Bluetooth would need. So the extension to the Bluetooth will be natural (provided i find appropriate wireless python/c libraries to send the midi files).

The first question is how to send the midi sounds via FTDI. After long hours searching for solutions, I have found a great software Hairless-midi, which connects any of the available midi devices with the serial communication of choice. I then installed vmpk piano as a midi input device and verified that TX pin on my FTDI cable indeed sends the data packages.

I then realized that unlike in the case of midi input devices, the output device should essentially synthesize the sounds. After a long search for optimal solutions (implementing the midi libraries myself will take much more time than I am left with) I have found the 6-voice synthesizer implemented by Ihsan Kehribar. It took me a while to get it working on my microcontroller, but finally, the board woke up!


Midi synthesizer over FTDI is working!

This is the code , after I cleaned it up and tuned it work with my computer/chip.

Sending the (midi) audio file over Bluetooth

In an ideal world, this synthesizer would evolve into a wireless serial communication, but after days of reseach and attempts with Nordic and Blufruit development tools, at the moment I conclude that there exist no MACOS program or coding library that would easily communicate with this BLE module, so for my next pursuits I will look into the NRF family of modules.

Issues that I faced

Files