I have been using a KY040 rotary encoder within Node Red for a while, but my solution is a little clunky. I have attached it to an ESP8266 loaded with ESP-Easy, which outputs the count via MQTT to my Pi. This works, but it involves two pieces of controlling hardware.
Node Red captures the MQTT flow and I use the Pi GPIO nodes to make my PWM solution dance. Easy.
But in my quest to make a standalone Pi / KY040 / Node Red setup I've attempted a number of methods to read the encoder without success. After trawling the web for a couple of days I have not found another person trying to accomplish the same as me.
First I installed the Python Function node, installed a few Python files, and tried to run their scripts (like https://guy.carpenter.id.au/gaugette/2013/01/14/rotary-encoder-library-for-the-raspberry-pi/) without success.
Then I tried to capture the bitstream using the serial node, which can see /dev/tty/AMA0 but the Pi denies me access. Using the browse function in the node itself, this is the only choice available)
I installed the NPM libraries for serial port, which offered no further advancement.
Whilst I'm really comfortable working in the NR environment, I'm a bonehead at writing Python.
So feeling a little defeated, I thought I would see if anybody here was able to share their success story.