Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Teensy MIDI controller with 2 Guitar expression pedals

  1. #1
    Junior Member
    Join Date
    Sep 2020
    Posts
    4

    Teensy MIDI controller with 2 Guitar expression pedals

    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); Click image for larger version. 

Name:	IMG_4820.jpg 
Views:	9 
Size:	98.6 KB 
ID:	21891
    }

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    477
    Reckon this is the mistake:
    Code:
    if (new_value2 < min_value1) min_value2 = new_value2;

  3. #3
    Junior Member
    Join Date
    Sep 2020
    Posts
    4
    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.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,069
    I wired up 2 pots and ran your program. It seems to work fine. I don't see anything erratic happening.

    Click image for larger version. 

Name:	sc.png 
Views:	12 
Size:	90.6 KB 
ID:	21897

    Click image for larger version. 

Name:	pots.jpg 
Views:	15 
Size:	87.4 KB 
ID:	21898

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,069
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •