vendredi 30 mars 2018

A hack of the MIDIPLUS / MIDITECH 4x4 USB to MIDI interface with STMDUINO

Hack of the MIDIPLUS/MIDITECH 4x4 USB MIDI

 

The idea
I currently own 2 MIDI 4X4 from Miditech/Miduplus manufacturer.I thought it was possible to stack the 2 on the same PC to get 8x2 ports IN/Out. But as theses devices have exactly the same product and vendor ID, and no serial, it is in fact impossible to do that without conflicts (it seems however some people installed 2 MIDI 4X4 succefully on the same computer...). So the only alternative was to buy a 8x8 interface to the same manufacturer, for the three times the price of the MIDI 4x4 that I did not.

More, recently, one of my interface started to work incorrectly, invoking to me a corrupted firmware.
I asked to the Miditech and Midiplus support and they were enough kind to provide to me an updated firmware kit, but for the NEW version...Happy to learn that my interface was the "old" one, however still sold on many web sites today...I tested that update package without any success...My version was not updatable at all they said.

I could'nt accept that a device (almost) still in order with USB,  8 ports 4IN - 4 OUT goes directly in the trash bin. Nothing to loose, I opened the box, and inside I discovered that the microcontroller was a STMF103RC, a very common uC on musical gears(the Arturia Minilab and the Novation launchkey and launchpad are using it for example).
Here start the idea of a possible hack :I have a board available with a programmable and powerfull chip,  native USB, plus all the circuitry for 4 MIDI IN / 4OUT.Why not rewriting a new firmware from scratch as I did for other uC like of the AVR family ? I could even extend that firmware to enable merge mode, thru mode, specific routing and filtering modes.So, building an ultimate USB MIDI interface better than the original....

First steps

The STMF103 has an internal bootloader working with the UART Serial 1. The bootloader mode is activated by maintaining the Boot0 pin to HIGH and the Boot1 pin to LOW.  So I desoldered 2 resitors on the board because they were disabling that mode,made a small reset button / "boot1 HIGH" circuit, and soldered the boot 0 to ground. 

I also connected TX and RX of the serial 1 to a small plug. That was easy because some large labelled TXn / RXn pads exist on the MIDI4x4 motherboard.  I connected that plug to an USB Serial TTL, and 2 H later, I was able to upload a new firmware in the thing.

The original Miditech / Midiplus firmware is protected against read. I had to accept the "The chip will be entirely erased if you continue.." warning. Not a problem as hacking the existing firmware was not my goal at all.  

STMDUINO

To preserve and reuse my existing software libraries, I choose to use STMDUINO.
It is port of the Arduino platform to the ARM STM32 chip family from ST Micro. So you can develop "sketches" as usual, with the Arduino IDE, and reuse your existing "Arduino" code.

I  flashed a modified STMDuino generic bootloader2.0 to the board with STMFLASH, and tested the 4x4 board as a generic STMF103RC in the Arduino IDE... my MIDI demo sketch worked at the first compilation...And I could address the 4 serial ports connected to midi jacks.

I have rewritten entirely the firmware from a white page, and I have extended its features to enable routing : "4 merge" mode, thru mode, split mode, etc,  So I can say my modified USB interface 4X4 is now better than the original, very stable, and, the most important stackable with my existing one as I changed, obviously,  the Product ID !

The STM32F103 is really really fast...no lag at all, even at 300 BPM with 4IN/OUT working. At this time, I use the box with the new firmware in my MIDI setup :-) !

The code is easily adaptable to any other multi-jack USB interface.
https://github.com/TheKikGen/USBMidiKliK4x4


Uploading the STDMDuino modified bootloader

You need to modify the board to enable the internal bootloader of the STM32F103.  To do that, start by unscrewing the front plate of the case, and remove the board from the case.



- Remove the R28 resistor because it's disabling the bootloader standard mode.  Connect a 10K resistor between the boot1 pin and the ground as shown.


- Solder a wire to the Boot0 pin, and another to the VCC 3,3V pin.  Connect the wires together. This can be removed after the STMDuino bootloader download

- Plug your TTL to Serial USB  stick
- Plug the Miditech/Midipplus board into the USB
- Launch STM Flash loader demonstrator (if you don't have it , check the ST Micro. web site) and reset the Miditech/Midiplus board by by touching the RST tap point and the ground (for example the USB plug shield).   As the chip is in bootloader mode, you will, or hear nothing...

 - Connect TTL RX 1/TTL TX1  from the Miditech/Midiplus board to the TTL RX/ TTL TX of your serial USB converter. You can solder 2 wires to the pads clearly labelled on the board it self, or just hold the wires with the left hand and do the rest with the right one !


- Choose the right serial port in the list proposed by STMFlash tool the click on "Next"

At this point, it is still time to stop. After that step, not return possible  !!!!!



- You will see a red warning indicating that the firmware is protected, and going further will erase it.  So, if you are really sure, click on "Remove protection".  The existing Miditech/Midiplus firmware will be entirely erased.
- Click next, and choose the "midiplus4x4_boot20.bin". This is the STMDUINO bootloader,especially modified for the Miditech/Midiplus board (notably to activate the USB with a DISC command on PA8). Check "Optimizer", "Global Erase", and "Verify after download", then "Next". The download will start, and if everything is ok, you will have a message confirming that the the update was done correctly.
- Unplug, and plug agin the Miditech/Midiplusboard : that will activate the STM32DUINO perpetual bootloader mode.  If the blue led is flashing, you are ready to use the Arduino IDE with that board !








dimanche 11 mars 2018

BorgTribe : Korg Electribe ES1 Mod to record chromatic notes

I own an Electribe Korg for some time and I have to say that I really like this gear.  First because it is fast to handle, and second because it has a very special sound despite its relative low sampling rate comparing to current standard. I still use it in 2018, in the middle of much more elaborate gears (sometime too much elaborate !).

The Electribe ES1 is however quite limited in functionality, and on one point in particular: its inability to play a sample chromatically with an external midi keyboard.  Close to my other Volkaoss project, I quickly realized a MIDI notes to Electribe ES1 Pitch Control changes with an Arduino Uno board. Everything worked perfectly, and I was able to play a sample chromatically with an external Midi keyboard BUT....

But to my surprise the Electribe recording mode does not take into account a pitch transmitted to the MIDI IN.  Only PITCH potentiometer movements are recorded to change sample pitch in a pattern.  This is when the idea of controlling these movements with a midi keyboard connected to an Arduino came up...graft an Arduino to the ES1 like the Borg do in Startrek !


To do this, I chose to develop on an Arduino nano board, because of its small factor, and to use a Microchip MCP4151 digital potentiometer, with a resolution of 256 steps, which is enough to manage 127 positions on the PITCH potentiometer.
Full source project on my gihub here.

The schematic is really simple :
The MCP4151 uses SPI, an that can be tricky on the Nano : notably the fact that MISO (pin 12) must be pulled up to MOSI (look at the 1K resistor).  That was working perfectly on the Uno proto board without that, so I suppose it is mandatory when using SPI on the Nano (whatever, it is required by SPI usually).

As you can see on the schematic, the analog PITCH pot wiper pad is connected to the Nano Analog2 pin and disconnected from the ES1.  So, the Nano is able to read pot values and to resend them to the MCP 4151 digital potentiometer.  That was the first step of this project : be transparent, as shown on that video :



Next, I had to develop a new Arduino firmware to simulate potentiometers movements, when pressing a note on the MIDI keyboard. That was not so easy as the 256 steps of the MCP4151 seem a bit short to address the only 127 values but from an analog pot with an infinite resolution.  After fine tuning sessions, I finally got a very acceptable result, and I'm now able to record samples pitch on the Electribe from an external midi keyboard.

The Arduino Nano is fully embedd in the Electribe case, and works as the "man in the middle" behind the ES1 MIDI IN jack. It filters and eventually transforms every midi messages sent to the Electribe MIDI IN jack and resends such messages to the ES1 CPU .

I had to tap directly on the ES1 motherboard but hopefully that was easy as there is a lot of space between pads you can tap in. (Hires pictures can be found on the GitHub project site). 

Using BorgTribe

At the boot time, The Nano takes the hand and asks the global parameters of the ES1 via a system exclusive message.  Then it autoconfigures everything, notably MIDI notes part affectation by resending the sysex modified to the Electribe ES1.  So the only thing to really configure is the midi channel. After power on, the Electribe has a standard behaviour ("Classic" mode), as the Nano resend everything coming  from midi IN and/or the analog Pitch potentiometer.

Notes affectations start from C2 (C2 = Part1, C2# = Part2, D2 = Part3, etc...)

The C0 midi keyboard key is the "command key".
When you hold the command key and press a function key, that will send a specific command to BorgTribe, confirmed by parts flashing n times.

Setting modes : C0 + D0

3 Modes are available :

1- Classic mode : the standard Electribe one

2- Midi Pitched notes : Convert notes received on MIDI IN to Pitch control changes.  In that mode, you can't record pitch in the Electribe, but useful when in playing mode, because it acts like a transpose function with the current selected part.

3- Potentiometer Pitched notes : Convert notes received on MIDI IN to potentiometers movement. In that mode you can record pitched notes in the current pattern, in the same way you do by moving manually the pitch potentiometer.

Mode alternate each time you send the command.  The parts will flash a number of time corresponding to the current mode.

Setting full velocity : C0 + E0

This disable the velocity sensitivity and set the value by default to 127 (max).  This reproduce the Electribe pad behaviour.

Clear current pattern : C0 + F0

This command clears the current pattern. It is necessary to confirm the command by sending it a second time when the parts are flashing 5 time.

Auto tune Key  : C0 + F0#

This command attempts an autotuning by comparing default internal note/tune tables with midi CC pitch values. It is necessary to confirm the command by sending it a second time when the parts are flashing.
Still experimental.

Reset BorgTribe : C0 + B0

This command proceed a soft reset of the Arduino Nano. It is necessary to confirm the command by sending it a second time when the parts are flashing.



samedi 10 mars 2018

USBMIDiKlIK : A reliable Arduino USB MIDI interface

Résultat de recherche d'images pour "Arduino"Résultat de recherche d'images pour "midi logo"

As other project, like HIDUINO, or MOCOLUFA (thanks to them for inspiration), USBMIDIKLIK allows your Arduino board to become a very reliable MIDI IN/OUT USB interface. Despite the very good work done on these projects, i was facing some issues... An heavy MIDI traffic was blocking the serial, and some MIDI messages were purely ignored by the parser, like the song pointer position for example... more, these projects rely on a quite old version of the LUFA library.
USBMidiKliK uses interrupts and ring buffers to ensure that (fast) USB to (slow) midi transfers are reliable, plus a "more transparent as possible" midi parser. MIDI product device name is integrated in the makefile, and can also be modified by sysex...so easy to change.
This firmware is uploaded in the ATMEGA8U2 chip managing the USB, and changes the default USB serial descriptors to the MIDI ones. For more convenience when updates are needed, a "dual mode" is embedded, allowing to switch back to the USB serial : when the PB2/MOSI pin of the ATMEGA8U2 is connected to ground, the Arduino is a classical one again, and you can change and upload a new firmware in the ATMEGA328P (UNO) with the standard Arduino IDE.e Arduino.

This is a full open source project.
More detail on my GitHub HERE

Do you need a cheap USB midi /din converter ?

KonverterMidiUSB Host USB to Serial Midi bidrectionnal converter This project based on Arduino Uno allows you to get a very economical USB M...