Teensy MIDI controller with 2 Guitar expression pedals

Status
Not open for further replies.

bsandipk

Member
I have a teensy3.2 from prjc.com. I have connected a 25k pot (DOD Expression pedal) on AGND, 3.3 and A0. It works fine. The moment I connect second 25k pot with A1, it starts behaving erratic. . My use case is to build a MIDI controller with 2 exp pedals. The momentary switches are working perfect - using USB+Serial.

here is the code

#include <ResponsiveAnalogRead.h>

const int ANALOG_PIN1 = A0;
const int ANALOG_PIN2= A1;
int val1 = 0;
int val2 = 0;
int min_value1,min_value2 = 0x0ffff ;
int max_value1,max_value2 = 0;
int last_value1,last_value2= 0;
// make a ResponsiveAnalogRead object, pass in the pin, and either true or false depending on if you want sleep enabled
// enabling sleep will cause values to take less time to stop changing and potentially stop changing more abruptly,
// where as disabling sleep will cause values to ease into their correct position smoothly and more accurately
ResponsiveAnalogRead analog1(ANALOG_PIN1, true,.01);
ResponsiveAnalogRead analog2(ANALOG_PIN2, true,.01);
// the next optional argument is snapMultiplier, which is set to 0.01 by default
// you can pass it a value from 0 to 1 that controls the amount of easing
// increase this to lessen the amount of easing (such as 0.1) and make the responsive values more responsive
// but doing so may cause more noise to seep through if sleep is not enabled

void setup() {
// begin serial so we can see analog read values through the serial monitor
//Serial.begin(115200);
// while (!Serial);
// analogReadResolution(16);
analogReadResolution(7);
analogReadAveraging(8);

}

void loop() {
// update the ResponsiveAnalogRead object every loop
int new_value1 = map(analogRead(ANALOG_PIN1),0,127,0,127);
if (new_value1 != last_value1) {
last_value1 = new_value1;
if (new_value1 > max_value1) max_value1 = new_value1;
if (new_value1 < min_value1) min_value1 = new_value1;
Serial.printf("new1 val %d : min val %d max val %d\n", new_value1, min_value1, max_value1);
}
delay(50);
int new_value2 = map(analogRead(ANALOG_PIN2),0,127,0,127);
if (new_value2 != last_value2) {
last_value2 = new_value2;
if (new_value2 > max_value2) max_value2 = new_value2;
if (new_value2 < min_value1) min_value2 = new_value2;
Serial.printf("new2 val %d : min val %d max val %d\n", new_value2, min_value2, max_value2);
}
delay(50); IMG_4820.jpg
}
 
Thank you for your response. The issue is when I connect second pot, teensy starts behaving erratic, reading random values from both and eventually hangs. Works fine with 1 pot.
 
My best guess is you probably have some sort of wiring or other hardware problem, since the code seems to run well here.

Do you have a voltmeter? Best to connect it to A1 and GND to watch the actual voltage Teensy is receiving while you're getting the erratic readings.
 
Status
Not open for further replies.
Back
Top