Using the I2C bus for extending the Lego EV3
Using the I2C bus for extending the Lego EV3has allowed for a wide range of third-party development of custom sensors and motor adapters.
This is done via the EV3 bricks fast-interrupt based I2C bus on the four input ports.
I used the I2C bus to create a custom LED controller via an Arduino.
Arduino Programming Setup
For Arduino I used a UNO for prototyping and a Pro Mini for the final design.
The programming is once again done in VSCode (vscode) although this time I’m using the Arduino C/C++ and the Arduino extension for direct programming of the Chip.
I found it was necessary to install the desktop Arduino IDE for the VSCode extension to work properly.
EV3 to Arduino (via I2C)
For the initial connection of EV3 to Arduino, I followed the steps on this page dexterindustries connecting-EV3-arduino, by sacrificing a spare EV3 cable and creating the equivalent code in Python.
One of my initial gotchas when sending multi-byte commands via Pythons
was working out that the cmd byte is just the first byte sent, and it’s up to the receiver to interpret it as either a cmd or just another byte in the sequence.
I also needed to write guard logic to handle lag in the I2C bus being ready.
Arduino to WS2821 LEDs
This is the guide I used to get started with the Arduino and addressable LEDs
For the most part, this worked as expected, however, I ended using the library instead of the Adafruit one.
Bringing it all together
For my project the EV3 sends the required pattern, colors, and intensity via the I2C bus to the Arduino, the Arduino interprets this and runs the WS2812 LED strips
- EV3: current LEGO Technic Mindstorms programmable Brick
- EV3dev: Debian Linux-based operating system for EV3 and some others
- I2C: two-wire serial protocol for communication
- Arduino: Open-source electronic prototyping platform
- WS2812: is an RGB LED with the built-in control circuit, uses three wire for control (Power, Ground, Data)
- Python / C / C++: Programming languages