tttapa / Control-Surface

Arduino library for creating MIDI controllers and other MIDI devices.
GNU General Public License v3.0
1.24k stars 139 forks source link

Encoder not working properly on pins 19 and 18 Teensy LC #266

Open SwooshMihu opened 4 years ago

SwooshMihu commented 4 years ago

I have a little problem with the implementation of 1 encoder. The encoder connected to pins 19 and 18 gives the same signal when rotated either way. This is the code i am using:

include // Include the Encoder library.

// This must be done before the Control Surface library.

include // Include the Control Surface library

USBMIDI_Interface midi;

///////////////////Defining Bank/////////////////////// Bank<4> bank1(2); IncrementDecrementSelector<4> selector = { bank1, // Bank to manage {8, 13}, // push button pins (increment, decrement) Wrap::Wrap, // Wrap around };

/////////////////////////////////////Banking encoders////////////////////// Bankable::CCRotaryEncoder enc1 = { {bank1, BankType::CHANGE_CHANNEL}, {21, 20}, // pins //{MIDI_CC::Channel_Volume, CHANNEL_1}, {MCU::V_POT_1, CHANNEL_1}, //MCU::V_POT_1, // MIDI address (CC number + optional channel) 1, // optional multiplier if the control isn't fast enough }; Bankable::CCRotaryEncoder enc2 = { {bank1, BankType::CHANGE_CHANNEL}, {19, 18}, // pins //{MIDI_CC::Channel_Volume, CHANNEL_1}, {MCU::V_POT_2, CHANNEL_1}, //MCU::V_POT_1, // MIDI address (CC number + optional channel) 1, // optional multiplier if the control isn't fast enough }; Bankable::CCRotaryEncoder enc3 = { {bank1, BankType::CHANGE_CHANNEL}, {17, 16}, // pins //{MIDI_CC::Channel_Volume, CHANNEL_1}, {MCU::V_POT_3, CHANNEL_1}, //MCU::V_POT_1, // MIDI address (CC number + optional channel) 1, // optional multiplier if the control isn't fast enough }; Bankable::CCRotaryEncoder enc4 = { {bank1, BankType::CHANGE_CHANNEL}, {15, 14}, // pins //{MIDI_CC::Channel_Volume, CHANNEL_1}, {MCU::V_POT_4, CHANNEL_1}, //MCU::V_POT_1, // MIDI address (CC number + optional channel) 1, // optional multiplier if the control isn't fast enough }; Bankable::CCRotaryEncoder enc5 = { {bank1, BankType::CHANGE_CHANNEL}, {12, 11}, // pins //{MIDI_CC::Channel_Volume, CHANNEL_1}, {MCU::V_POT_5, CHANNEL_1}, //MCU::V_POT_1, // MIDI address (CC number + optional channel) 1, // optional multiplier if the control isn't fast enough }; Bankable::CCRotaryEncoder enc6 = { {bank1, BankType::CHANGE_CHANNEL}, {10, 9}, // pins //{MIDI_CC::Channel_Volume, CHANNEL_1}, {MCU::V_POT_6, CHANNEL_1}, //MCU::V_POT_1, // MIDI address (CC number + optional channel) 1, // optional multiplier if the control isn't fast enough }; //////////////////////////

void setup() { RelativeCCSender::setMode(relativeCCmode::TWOS_COMPLEMENT); Control_Surface.begin(); }

void loop() { Control_Surface.loop(); // Update the Control Surface }

Check out the output on MIDI-ox, while testing the encoders you can clearly see this one is problematic: image

As far as the wiring goes, all encoders are wired properly and i have also tried using an already tested encoder on those two pins with the same result.

SwooshMihu commented 4 years ago

Even when using the following code, you can notice that it increments in the same direction, no matter in which way i twist the encoder.

include // Include the Encoder library.

include // Include the Control Surface library

// Instantiate a MIDI over USB interface. USBMIDI_Interface midi; // Instantiate a CCAbsoluteEncoder object CCAbsoluteEncoder enc = { {19, 18}, // pins MIDI_CC::Pan, // MIDI address (CC number + optional channel) 1, // optional multiplier if the control isn't fast enough };

void setup() { Control_Surface.begin(); // Initialize Control Surface }

void loop() { Control_Surface.loop(); // Update the Control Surface }

image

tttapa commented 4 years ago

Pins 18 and 19 are not interrupt pins. Please see the link I posted in your previous issue.

Control Surface uses the PJRC Encoder library to read the encoders, so I'd recommend trying the Encoder library examples first to debug this.

SwooshMihu commented 4 years ago

Thing is, i have an encoder connected to pins 16 and 17 which according to this schematic do not have the intrrerupt functionality image and it works fine

tttapa commented 4 years ago

Do the Encoder library examples work?

SwooshMihu commented 4 years ago

it does work on 16 and 17, does not work on 18 and 19

tttapa commented 4 years ago

Then this is a problem with the Encoder library, not Control Surface. If this is a known issue, you can probably find it on the PJRC forums.

SwooshMihu commented 4 years ago

i shall check it out, meanwhile the fix i found was connecting the encoders to 16-18 and 17-19 respectively and it fixed the problem.