<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

M5Stack 8ANGLE Potentiometer and LED Module - Arduino C++

Return to chapter overview

The 8ANGLE module has 8 x potentiometers, 9 x RGB LEDS, and a slider toggle switch, with an I2C connection. It has been very useful for manually fine-tuning the parameters for PID loops, and many other things. The multi-coloured LEDs look nice too.


Pretty pictures



This is what I originally used for manual PID tuning, needing three analogue inputs. The 8ANGLE is more fun.




Manufacturer documentation: https://docs.m5stack.com/en/unit/8Angle

The 8ANGLE module uses I2C communications, with default I2C address 0x43, but a different address can be programmed if necessary.

The connector is a standard 4-pin "Grove" connector. Connect to the same pins on the Arduino board.



I2C clock

Open collector, may need pull-ups to 3.3V or 5V



I2C data

Open collector, may need pull-ups to 3.3V or 5V



5V supply

Max. 50mA with all LEDs white at full brightness





It uses a 5V supply (max. 50mA), but has an onboard 3.3V regulator. Its internal STM32 microcontroller is powered by 3.3V, and has 5V-tolerant inputs, so they can be used with 3.3V or 5V boards without problems - no level shifters are needed.

You may need pull-ups to 3.3V or 5V (depending on your board's VCC) on the open-collector SCL and SDA lines, if your board does not already have them. The value depends on the speed and how many I2C devices are connected, 4K7 is usually ok. But it seems to work well without them, maybe the internal pull-ups are being used.

The module has 256 x 8-bit 'registers', but not all of them are used. The potentiometer values are 16 bits, so you must read 2 bytes. The LED values are 32 bits, so you must read/write 4 bytes. It fails if you don't read 2 or 4 bytes.


The module cannot be accessed too fast, else it misses messages, especially on the fast boards like the Zero. My first version used Wire.write(buffer, length) to write multiple bytes to the 8ANGLE. This sometimes caused it to hang. But if each byte is written separately in a loop, then it works.

All methods return true on success, false on failure, but in practice you only need to check the return value of begin() to determine if the 8ANGLE module is connected.



This code has been tested on the Arduino Uno R3 and the Arduino Zero, but should work on them all.




Arduino demo sketch source code: M5Stack-8ANGLE.zip

Note: On 8 and 16-bit microcontrollers, an 'int' is 16 bits and 'long' is 32 bits, so we need 'long' for the 24-bit RGB values. On 32-bit devices 'long' and 'int' are both 32 bits. It's often more efficient to use the native 'int' instead of 'uint8_t' or 'int16_t', because the compiler usually converts them to 'int' for arithmetic operations.


M5Stack 8ENCODER Rotary Encoder Module

M5Stack also has a similar module which has rotary encoders instead of potentiometers. Each encoder has 30 steps, with half-step in between = 60 counts per revolution.

Manufacturer documentation: https://docs.m5stack.com/en/unit/8Encoder

Here's the code I wrote for this one: M5Stack-8ENCODER.zip



M5Stack schematics