Haalarit part 2 – Rotary encoder and LEDs

So the next task was to figure out the rotary encoder. The plan with it was to eventually have it control some basic settings of the system. For instance changing what would be displayed on the screen.

Image of generic rotary encoder

Image from esp32io.

In most cases though it would make sense to control the ESP32 over wifi from my phone. The ESP32 could create a wlan network I could connect to with my phone and open a website to update the settings. But the web based stuff will be just a plan for the future.

I was following some tutorial, that adviced to use the EzButton library. I tried it out and got it quickly working. However, I found the input to be sort of slow and a little unrealiable. This might have been due to a too high debounce time or that the library was maybe not inteded for rotary encoders. Or it might have been something else in the code I was doing wrong.

In any case I decided to look for a different library and found this RotaryEncoder library that seemed to be quite well thought out. Probably most importantly the examples had a code snippet for adding a interrupt for listening to changes in the encoder position.

IRAM_ATTR void checkPosition() {
  encoder->tick(); // just call tick() to check the state.
}


void setup() {
    attachInterrupt(digitalPinToInterrupt(PIN_IN1), checkPosition, CHANGE);
    attachInterrupt(digitalPinToInterrupt(PIN_IN2), checkPosition, CHANGE);
}

(You can see the full example code here: Github)

I got the hardware interrupts working quite quickly and now the input was much more reliable. I noticed that if I rotated the encoder in one direction and rotated it in the opposite direction, the first step in the opposite direction was not registered. Other than that there were no problems with it and the push button seemed to work nicely too.

Now the next thing would be to make the programmable led strip work. But that will have to wait for now since that needs some extra setup. After I get it working it would be time to try to integrate these four components into a full system.

My initial plan is to get this done in time for May 1st like I mentioned in part 1, but I will need some time to figure out how to attach everything to the overalls in addition to sowing at least 50 clothes patches into them. The unfortunate part is that ordering the overalls has taken my student organization an unusally long time.

I also have an ESP32 camera development board, so I would ideally use that so I could also snap pictures during events really nicely. One idea ir to make it take a picture every 30 minutes to an SD card. Luckily I have already gotten the camera to work once.

For those interested I have released the code as open source at codeberg.