Arduino Touchscreen Auduino

Continuing my experimentation with my touchscreen Arduino, this project adds five touchscreen slider potentiometer inputs to my Auduino granular synthesizer.

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

Once again this is once again largely plugging together previous modules, so there is no “circuit” to describe as such.  I’ve continued to make use of my Arduino PWM Output Filter Circuit shield. Auduino by default outputs on pin 3, so that is fine for use with the shield.

I am aiming for the following.

IMG_5437

The Code

The basic idea is to take the original Auduino code and add the virtual potentiometers and touch screen handling from Arduino Touchscreen MIDI Controller – Part 2.

I’ve set up the configuration to provide five virtual potentiometers with the following parameters:

#define POT_W 80
#define POT_X_MIN 10
#define POT_X_GAP 10
#define POT_Y_MIN 5
#define POT_H 300
#define POT_BAR 6

In order to keep the changes to the original Auduino code as minimal as possible, I’ve created a touchscreen equivalent analogRead function to return the last “touched” value, suitably scaled and inverted, to reflect the “Y=0 at the top” coordinate system of the screen, as follows.

int gfxAnalogRead(int pot) {
if (pot < NUMPOTS) {
return 1023-potval[pot];
}
}

Then it is really just a case of calling the gfxSetup() and gfxLoop() functions from the Arduino’s setup() and loop() functions and it should work.

And it did, sort of, but the output was quite noisy.  So I decided to update the Auduino’s PWM handling slightly to double the PWM frequency, whilst keeping the output sample frequency the same.  To do this, I changed the Timer mode from Phase Correct PWM (the default for Auduino) to FastPWM, which will instantly double the frequency, and introduced a small piece of code to ensure the sampling rate stays the same.

Here is the new Timer 2 initialisation code the the updated interrupt routine.

void audioOn() {
// Configure for FastPWM mode:
// FastPWM
// No prescalar
// Clear OC2B on match; Set on BOTTOM
// Match at TOP
// WGM2[2:0] = 011
// COM2B[1:0] = 10
// CS2[2:0] = 001
// TOIE2 = 1
TCCR2A = _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(CS20);
TIMSK2 = _BV(TOIE2);
return;
}
int irqtoggle;
SIGNAL(PWM_INTERRUPT)
{
if (irqtoggle) {
irqtoggle = 0;
return;
} else {
irqtoggle = 1;
}
// Rest of original interrupt code...

This leaves me with a PWM base frequency of 62.5kHz and a sample range of 31.25kHz.  This seems to give a much cleaner signal for me.

Find it on GitHub here.

Closing Thoughts

I now have to tell myself not to go back and re-do all my projects involving potentiometers with touchscreen replacements!  But I did want to do a simple synth and as the Auduino already using pin 3 as the audio output by default, and has five pots for control, it was an obvious one.

I’m not sure I’ll go much further though, as whilst this is a bit of fun, I’m not entirely sure on the practicalities if I’m honest!

Kevin

 

One thought on “Arduino Touchscreen Auduino

Leave a comment