This time, I'm trying to build a usb knob that emulates a couple of keyboard keys when turned and noticed later that the part for the rotary encoder the person used is a board with filtering but I just ordered the rotary encoder alone.
I tried the rotary encoder alone at first(hadn't realized they used a board version yet) and was getting weird results.
The Dfrobot encoder board doesn’t have filtering. It has pull-up resistors on the encoder phases. The push button switch has a pull- resistor and a debouncing capacitor.
The button would switch on its own, possibly because I was using my fingers directly on the metal to turn it and the keys weren't getting pressed at all.
Touching the bare metal of the encoder has nothing to do with the problem.
The reason touching it made things happen before is because, without the pull-up resistors, the inputs were floating and thus their states easily affected by touch.
After a bit of research, realized they had filtering for it and I didn't so I found the diagram for the board used in the project and tried to recreate it on a breadboard for testing but I don't seem to be getting any input from the rotary encoder at all and I'm stumped for what could be the issue.
The “schematic” on the hackaday page is of little help, since the pinout of the encoder module is different from that shown in the “schematic”. If you connect the bare encoder as shown in the schematic, it will not and cannot work.
It’s hard to tell with certainty what you’ve done since you haven’t provided a schematic of what you actually built (the schematics of the projects you linked aren’t what you actually built) and your photo is blurry and has wires obscuring where they connect, but it looks like you’ve connected the wires from the MCU to the bare encoder as if it were the encoder board, and then added resistors according to the encoder board’s schematic, but without accounting for the board’s external connections.
Assuming I deciphered it correctly, the result is that the encoder inputs (phases and button) are permanently pulled high, and the actual button isn’t ever connected to an input.
I'm using 47k resistors and a 10uF 63v(local shop didn't have 100v that I usually see with microcontrollers so hopefully 63v is enough). The long lead of the capacitor is on the side of the red wire(which I'm fairly certain is how you do it) since that cap doesn't have a band on the side indicating the negative side.
Your microcontroller is running at 5V (most likely) or 3.3V; either way, FAR below the 63V maximum of your capacitor. Capacitor voltages are maximum ratings: applying a voltage higher than that will damage it. That’s it.
If there’s no stripe, it could just be minus signs printed down one side.
If I plug it in, the ring and the microcontroller lights up as expected from the code, but pushing down on the rotary encoder or turning it(using some Styrofoam so my fingers don't touch it directly) does nothing. Touching it directly with my fingers also doesn't do anything, unlike when there was no filtering.
The “filtering” is, as I said, just pull-up resistors. All three inputs are pulled high.
Before I actually found the diagram for the board they used in their project, I tried just finding a filtering diagram for a rotary encoder and saw many different values for them, some even saying the ones from the rotary encoder datasheet didn't work for them which is why I used the values for the board used in the project but that made me wonder, how do you even decide which values to use?
Assuming you mean an actual debouncing circuit (like the encoder module uses on the pushbutton), it’s actually by choosing the “RC time constant” τ (tau), that is, the product (multiplication) of the resistor and capacitor values:
R (ohms) x C (farads) = τ (seconds)
Tau, by definition, is the amount of time it takes the capacitor to charge/discharge to 63% of the voltage change that is applied.
For example, using the values from the dfrobot encoder board’s button, 47kohm x 10μF = 47000 ohms x 0.00001 farads = 0.47 seconds. Since that board keeps the capacitor charged, pressing the button discharges it, so we are going from e.g. 5V to 0V, so our voltage change is -5V.
-5V x 63% = -3.15V.
Take our starting value (5V) and add the change (-3.15V) to it and we get the value after one tau (0.47s here): 1.85V.
So holding the button for 0.47s will discharge the capacitor from 5V to 1.85V. The capacitor voltage is what is (supposed to be) connected to the microcontroller input, giving a stable voltage.
But 0.47s is very slow, since it means normal quick button presses will be missed. A much more reasonable debouncing time is a few milliseconds. The datasheet for your Bourns encoder, for example, suggests 10k ohms and 0.01μF for the encoder phases, which multiplied give a tau of 0.1ms, ensuring encoder pulses won’t get missed.
I wouldn’t be surprised if the 10μF in the dfrobot module is a typo, and they actually intended to install a much smaller value like 1μF or 100nF.
For standard CMOS inputs, the thresholds for “high” and “low” are 70% and 30% of the supply voltage, respectively. The 63% (37%) of one tau isn’t quite 70% (30%), but should be close enough for most purposes. Just err on the side of a lower tau and you’ll be fine. If you use X5R or X7R ceramic capacitors, whose capacitance falls with applied (“DC bias”) voltage, that capacitance loss alone should easily take care of this.
So if you want debouncing to ignore pulses shorter than, say, 25ms, then choose R and C values that equal that or a little bit less,. Since resistors are cheap (regardless of value) while capacitors are more expensive and their cost rises with value, select a cheap capacitor first, then calculate the resistor value to match. E.g. 25ms/1μF = 25k ohm, so use a 22k ohm resistor.
There are of course formulas to calculate it more precisely, but given that capacitors usually have a tolerance of 10-20%, I think a simplified process like this is sufficient.
I'm seeing voltage fluctuating between roughly 9.5 to 10v at random, turning or pushing the button doesn't seem to have an effect at all.
I don't think my breadboard circuit is right with values like that.
Assuming it’s your 5V USB supply, you shouldn’t be seeing anything above 5.5V.
If I only use 1 red wire that goes between the resistor for the positive pin on the rotary encoder and the cap and one black for the negative and another at the other side of the cap, I'm getting a more reasonable 6v or a bit less.
Pin A and the common C are always at full voltage and pin B is at 0 when not used and climbs when used which I assume is what I want to see.
Although, when I connect the multimeter to pin B, the ring light starts switching colors which should be the buttons job.
I'm pretty sure the 3 pins are connected properly since I realized they weren't at first because the board the guy used rearranged the common to be at the end on his board even though it's in the middle, But for the positive and negative, I don't see them identified in the spec sheet so I assume it doesn't matter, I used the same orientation as the rotary board diagram.
If I flip the positive and negative on the rotary encoder, I get around 5v instead of 6 so guess I'll use that orientation from now on.
Yeah it’s wired all sorts of wrong thanks to the hackaday’s crappy, incorrect schematic.
Assuming the pullup resistors are the ones from the filtering which would be 47k ohms.
As I said, they’re just pull-ups, not filters.
If you’re not familiar with how pull-up/pull-down resistors work, I’d strongly suggest doing some research on that first.