Bourns Encoder for my project help to choice

mickael

Member
Hi,

I need encoder for my midi board.

Can I use Bourns EAW0J-C24-AE0128L with teensy 3.5 ?

If anyone can help me on choice of endless encoder I really appreciate.

If you have tips to connect and use encoder I really enjoy for.

Thanks
 
Electrically, this absolute endless encoder [datasheet] can be connected to a Teensy 3.5. Just use pinMode(pin, INPUT_PULLUP) for pins P1-P8 and then digitalRead each pin.
However, be aware that this endless encoder has 128 unique states but it outputs decimal values from 1 to 254 on those 8 pins.
I rearranged the table on page 2 to show the decimal values incrementing from 1 to 254. You will that decimal values 5, 10, 11, 13, 17, etc are missing.
That may or may not be cumbersome for your application.
Ofcourse you can add a look-up table to your code to get position and decimal value re-alligned.

Code:
Pos									Dec
56	0	0	0	0	0	0	0	1	1
40	0	0	0	0	0	0	1	0	2
55	0	0	0	0	0	0	1	1	3
24	0	0	0	0	0	1	0	0	4
39	0	0	0	0	0	1	1	0	6
52	0	0	0	0	0	1	1	1	7
8	0	0	0	0	1	0	0	0	8
57	0	0	0	0	1	0	0	1	9
23	0	0	0	0	1	1	0	0	12
36	0	0	0	0	1	1	1	0	14
13	0	0	0	0	1	1	1	1	15
120	0	0	0	1	0	0	0	0	16
41	0	0	0	1	0	0	1	0	18
54	0	0	0	1	0	0	1	1	19
53	0	0	0	1	0	1	1	1	23
7	0	0	0	1	1	0	0	0	24
20	0	0	0	1	1	1	0	0	28
19	0	0	0	1	1	1	0	1	29
125	0	0	0	1	1	1	1	0	30
18	0	0	0	1	1	1	1	1	31
104	0	0	1	0	0	0	0	0	32
105	0	0	1	0	0	0	0	1	33
25	0	0	1	0	0	1	0	0	36
106	0	0	1	0	0	1	0	1	37
38	0	0	1	0	0	1	1	0	38
58	0	0	1	0	1	0	0	1	41
37	0	0	1	0	1	1	1	0	46
14	0	0	1	0	1	1	1	1	47
119	0	0	1	1	0	0	0	0	48
118	0	0	1	1	0	0	0	1	49
107	0	0	1	1	0	1	0	1	53
4	0	0	1	1	1	0	0	0	56
3	0	0	1	1	1	0	1	0	58
109	0	0	1	1	1	1	0	0	60
108	0	0	1	1	1	1	0	1	61
2	0	0	1	1	1	1	1	0	62
1	0	0	1	1	1	1	1	1	63
88	0	1	0	0	0	0	0	0	64
89	0	1	0	0	0	0	1	0	66
51	0	1	0	0	0	1	1	1	71
9	0	1	0	0	1	0	0	0	72
10	0	1	0	0	1	0	0	1	73
90	0	1	0	0	1	0	1	0	74
22	0	1	0	0	1	1	0	0	76
11	0	1	0	0	1	1	0	1	77
12	0	1	0	0	1	1	1	1	79
42	0	1	0	1	0	0	1	0	82
43	0	1	0	1	0	0	1	1	83
21	0	1	0	1	1	1	0	0	92
126	0	1	0	1	1	1	1	0	94
127	0	1	0	1	1	1	1	1	95
103	0	1	1	0	0	0	0	0	96
102	0	1	1	0	0	0	1	0	98
91	0	1	1	0	1	0	1	0	106
116	0	1	1	1	0	0	0	0	112
117	0	1	1	1	0	0	0	1	113
115	0	1	1	1	0	1	0	0	116
93	0	1	1	1	1	0	0	0	120
94	0	1	1	1	1	0	0	1	121
92	0	1	1	1	1	0	1	0	122
114	0	1	1	1	1	1	0	0	124
95	0	1	1	1	1	1	0	1	125
113	0	1	1	1	1	1	1	0	126
0	0	1	1	1	1	1	1	1	127
72	1	0	0	0	0	0	0	0	128
71	1	0	0	0	0	0	0	1	129
68	1	0	0	0	0	0	1	1	131
73	1	0	0	0	0	1	0	0	132
29	1	0	0	0	0	1	1	1	135
70	1	0	0	0	1	0	0	1	137
69	1	0	0	0	1	0	1	1	139
35	1	0	0	0	1	1	1	0	142
34	1	0	0	0	1	1	1	1	143
121	1	0	0	1	0	0	0	0	144
122	1	0	0	1	0	0	1	0	146
74	1	0	0	1	0	1	0	0	148
30	1	0	0	1	0	1	1	1	151
6	1	0	0	1	1	0	0	0	152
123	1	0	0	1	1	0	1	0	154
124	1	0	0	1	1	1	1	0	158
17	1	0	0	1	1	1	1	1	159
67	1	0	1	0	0	0	1	1	163
26	1	0	1	0	0	1	0	0	164
27	1	0	1	0	0	1	1	0	166
28	1	0	1	0	0	1	1	1	167
59	1	0	1	0	1	0	0	1	169
15	1	0	1	0	1	1	1	1	175
5	1	0	1	1	1	0	0	0	184
110	1	0	1	1	1	1	0	0	188
111	1	0	1	1	1	1	1	0	190
16	1	0	1	1	1	1	1	1	191
87	1	1	0	0	0	0	0	0	192
84	1	1	0	0	0	0	0	1	193
45	1	1	0	0	0	0	1	1	195
86	1	1	0	0	0	1	0	0	196
85	1	1	0	0	0	1	0	1	197
50	1	1	0	0	0	1	1	1	199
46	1	1	0	0	1	0	1	1	203
33	1	1	0	0	1	1	1	1	207
83	1	1	0	1	0	0	0	1	209
44	1	1	0	1	0	0	1	1	211
75	1	1	0	1	0	1	0	0	212
31	1	1	0	1	0	1	1	1	215
32	1	1	0	1	1	1	1	1	223
100	1	1	1	0	0	0	0	0	224
61	1	1	1	0	0	0	0	1	225
101	1	1	1	0	0	0	1	0	226
66	1	1	1	0	0	0	1	1	227
62	1	1	1	0	0	1	0	1	229
49	1	1	1	0	0	1	1	1	231
99	1	1	1	0	1	0	0	0	232
60	1	1	1	0	1	0	0	1	233
47	1	1	1	0	1	0	1	1	235
48	1	1	1	0	1	1	1	1	239
77	1	1	1	1	0	0	0	0	240
82	1	1	1	1	0	0	0	1	241
78	1	1	1	1	0	0	1	0	242
65	1	1	1	1	0	0	1	1	243
76	1	1	1	1	0	1	0	0	244
63	1	1	1	1	0	1	0	1	245
64	1	1	1	1	0	1	1	1	247
98	1	1	1	1	1	0	0	0	248
81	1	1	1	1	1	0	0	1	249
79	1	1	1	1	1	0	1	0	250
80	1	1	1	1	1	0	1	1	251
97	1	1	1	1	1	1	0	0	252
96	1	1	1	1	1	1	0	1	253
112	1	1	1	1	1	1	1	0	254

Do you really need an absolute encoder?
If not, than you're better off with standard non-absolute encoders. See this page for more info on how to use them.

Paul
 
Thanks for your advise, I think you are right, I just need a 24 pulse relative encoder. It s to change the FX Time between multiple FX with MIDI messages (Pioneer Rekordbox) and I don't want fx time change abruptly for each fx when I switch between differents fx.

Thanks for your help
 
Another question: the Teensy only have 3.3v pin power supply. Majority of encoder are 5v to work. With only 3.3v it is ok ?. What is the solution if it not work properly ?

Can I get the 5v from teensy 3.5 vOut to power the encoder (or another components require 5v ) and put 220ohm resitor before each teensy Digital pins ?

thanks
 
With only 3.3v it is ok ?
Yes, no problem. Better not use 5V as not all Teensy's are 5V tolerant.

But for those simple rotary encoders, you hook them up differently. No need to use 3V3 or 5V.

444.jpg

Connect encoder pin Out A to Teensy pin 5, encoder pin Out B to Teensy pin 6 and encoder pin GND to Teensy GND.
Then run the following code and check the serial monitor output:

Code:
/* Encoder Library - Basic Example
 * http://www.pjrc.com/teensy/td_libs_Encoder.html
 *
 * This example code is in the public domain.
 */

#include <Encoder.h>

// Change these two numbers to the pins connected to your encoder.
//   Best Performance: both pins have interrupt capability
//   Good Performance: only the first pin has interrupt capability
//   Low Performance:  neither pin has interrupt capability
Encoder myEnc(5, 6);
//   avoid using pins with LEDs attached

void setup() {
  Serial.begin(9600);
  Serial.println("Basic Encoder Test:");
}

long oldPosition  = -999;

void loop() {
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    Serial.println(newPosition);
  }
}

Paul
 
Thanks Paul,

The test work great with my low cost encoder ec11.

I have a problem, when I want to send midi message.

After "oldPosition = newPosition;" I had usbMIDI.sendControlChange(35, 64, 1); to send Control change 35 value 64 on chanel 1.

After I turn the encodeur few time, midi message is not send anymore and serial console doesn't display value. It seem the teensy crash.
 
Is it possible to post your complete code so that we can reproduce the issue? [or, preferably, the smallest code that shows the error].

Paul
 
Is it possible to post your complete code so that we can reproduce the issue? [or, preferably, the smallest code that shows the error].

Paul

for information the code used:


Code:
#include <Encoder.h>

Encoder myEnc(5, 6);

void setup() {
}

long oldPosition  = -999;

void loop() {
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    usbMIDI.sendControlChange(1, 64, 1);
    Serial.println(newPosition);
  }
  delay(10);
}


midiox capture messages:

0000199D 4 -- B0 23 48 1 --- Control Change
00001A0C 4 -- B0 23 48 1 --- Control Change
00001A16 4 -- B0 23 48 1 --- Control Change
00002F11 4 -- B0 23 48 1 --- Control Change
00002F43 4 -- B0 23 48 1 --- Control Change
00002F4D 4 -- B0 23 48 1 --- Control Change
000037DB 4 -- B0 23 48 1 --- Control Change
00003835 4 -- B0 23 48 1 --- Control Change
00003849 4 -- B0 23 48 1 --- Control Change
00004203 4 -- B0 23 48 1 --- Control Change
0000424E 4 -- B0 23 48 1 --- Control Change
00004259 4 -- B0 23 48 1 --- Control Change
000049BA 4 -- B0 23 48 1 --- Control Change
00004A50 4 -- B0 23 48 1 --- Control Change
000050F6 4 -- B0 23 48 1 --- Control Change
0000511E 4 -- B0 23 48 1 --- Control Change --> after this teensy doesn't respond.....
 
Made a quick setup using a Teensy 3.2 [don't have a Teensy 3.5] and ran your code.
Here is the setup:

IMG_20220629_202527.jpg

Set USB type to "Serial+MIDI". Could not get it to fail...both serial monitor and MIDI-OX keep outputting data:

MIDI-OX.png

Using Windows 10, Arduino 1.8.19, Teensyduino 1.56, MIDI-OX 7.0.2.372,

By the way, your MIDI-OX captured messages are not sent by the code you posted...

Paul
 
thank you for the test.

It is very strange, I have same configuration, only teensy model change.

When I comment "usbMIDI.sendControlChange(1, 64, 1);" serial display the position of encoder and it work properly (no crash of teensy).

I will try with another encoder but I doubt that s the cause (encoders are new)

thanks
 
If the serial monitor shows correct counting of the encoder, than the encoder is fine. I see 4 counts per detent of the rotary encoder.
Is it possible for you to make a photo that shows your wiring of Teensy and encoder? Just for making sure the wiring is OK.
Do you happen to have another Teensy, like a 3.2?

Just thinking out loud, could it be that the internal pullups are weaker on a Teensy 3.5 than on a 3.2 and therefor introduce more noise on the encoder outputs [in combination with long wires from the encoder]?

Paul
 
I have not much experience with MIDI. Just wondering if it is OK to send those messages every 10ms? The encoder library will generate a lot of fast up/down counts if the encoder bounces (which is very likely). So, your if (newPosition != oldPosition) might be true much more often as you expect. A quick check would be to increase the delay to 100ms.
 
Replacing the Teensy 3.2 by a Teensy 4.1 and running your exact code gave the same flawless results as in my post #9.

Paul
 
Hi Paul,

my apologizes for my misstake in midi I accidentaly activate the midi output on teensy port after disable output to teensy midi port all work OK.

For info I write this code to send midi only when +4 or -4 value difference between new and old value.

Code:
/* Encoder Library - Basic Example
 * http://www.pjrc.com/teensy/td_libs_Encoder.html
 *
 * This example code is in the public domain.
 */

#include <Encoder.h>

Encoder myEnc(6, 5);

void setup()
{
}

long oldPosition = -999;

void loop()
{
  long newPosition = myEnc.read();
  if (oldPosition != newPosition)
  {

    // Serial.println(newPosition);
    int fourStep;
    fourStep = (newPosition - oldPosition) % 4;

    if (fourStep == 0 && newPosition - oldPosition >= 0)
    {
      // Serial.println(newPosition);
      usbMIDI.sendControlChange(40, 63, 1);
    }
    else if (fourStep == 0 && newPosition - oldPosition <= 0)
    {
      usbMIDI.sendControlChange(40, 65, 1);
    }
      oldPosition = newPosition;
    
  }
  // delay(1);
}

thanks and excuse me for this misstake.
 
Your code above did not work for me. I had to add delay(10) to the loop.
But your code can be simpler. Just divide the myEnc.read() by 4. And then check for the difference being positive or negative.
Code:
#include <Encoder.h>
Encoder myEnc(6, 5);
long oldPosition = -999;

void setup() {
}

void loop() {
  long newPosition = (myEnc.read() / 4);
  if (newPosition != oldPosition) {
    Serial.println(newPosition);
    if (newPosition - oldPosition > 0) {
      usbMIDI.sendControlChange(40, 63, 1);
    }
    else if (newPosition - oldPosition < 0) {
      usbMIDI.sendControlChange(40, 65, 1);
    }
    oldPosition = newPosition;
  }
  delay(10);
}

The program is now much more responsive to a 1 detent rotation.

Paul
 
Back
Top