Arduino Touchscreen MIDI Controller – Part 2

Here is another format for my newly found cheap touchscreen MIDI controller.  This time, presenting twelve virtual “slider pots” for use as MIDI controllers.

Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damage to expensive instruments!

These are the key Arduino tutorials for the main concepts used in this project:

If you are new to Arduino, see the Getting Started pages.

Parts list

The Circuit

This is using the same setup as the Arduino Touchscreen MIDI Controller.  Nothing has changed hardware wise.

IMG_5388

The Code

The main idea is to create a set of virtual “slider potentiometers” on screen that can be used to send MIDI control change messages to an attached device.  I’m going for having 12 on screen, as shown below.

IMG_5400

I thought this would be a relatively trivial update to my previous project – just replace the circles with a few rectangles!  Unfortunately it appears getting this cheap touchscreen to act as a slider with any accuracy is quite a challenge!

The biggest headache for me was keep having to remember that the Y coordinates go from zero at the top to “max” at the bottom. In the case of the display, max is 320 pixels.  For the touchscreen, it is a resolution of 4095 (in theory).  For the potentiometers it is, of course, 1023 if I am to simulate real analog pots.

In the end, I opted to keep all internal handling as “high is at the bottom” and just treat the pots as if they were “wired back to front”.

Once again there are a number of internal translating functions to switch between these different coordinate systems. I opted to keep the “work out a pot value from its Y coordinate” function (y2pot) working in touch-screen coordinates, otherwise it would be getting a bit silly, converting a 0-4095 scale down to a 0-319 scale to then expand back to a 0-1023 scale.  Then, of course, later on in the actual MIDI handling I’ll have to drop it back down to 0-127 anyway!  This kind of issue is symptomatic of some of the difficulties of trying to work this all out.

Another issue I found is that the touchscreen readings, whilst in theory ought to be between 0 and 4095, in reality appear to come in at around 180 up to 3850, so I adjusted the theoretical scaling a little more to try to support “touching close to the edge”.

Still, even with all the tweaking, I still sometimes get an erroneous trigger of the touchscreen.  I don’t know if there is still something odd in the maths, or if it is a genuine hardware feature of these cheap screens.  I guess in principle there ought to be some kind of calibration function, but that is getting a little out of scope really.  Suffice to say, I’ve tried to comment everything that is going on and encapsulate the different aspects as much as I can.

As before I’ve left in extensive debug printing to help!

Find it on GitHub here.

Closing Thoughts

As I say, once again this turned out to be quite complicated, but I think I got there in the end.  I’m not sure quite how practical this would be as a genuine MIDI controller though. It would definitely need a bit more tweaking I think.

I the video I’ve plugged it into my MT-32 again, but only two of the CC functions really work there – expression control drives some kind of “channel volume” and modulation wheel does what you’d expect.

Kevin

 

Leave a comment