MIND+ generated code initializes SEN0364 before I2C multiplexer (DFR0576)
Patrick.Gelinaud 2026-01-05 00:05:48 199 Views3 Replies Hello,
We are working on an educational project to build a line-following robot with children, and we would like to program it using MIND+.
Hardware setup
-Platform: UNIHIKER K10
-Color sensors: SEN0364
-I2C expansion board: DFR0548
-I2C multiplexer: DFR0576
Current status
Using MIND+, we successfully tested the SEN0364 color sensor on the I2C bus when it is connected through the DFR0548 extension board.
In this configuration, the sensor works correctly.
Requirement
For line following, we need to use multiple SEN0364 color sensors.
To achieve this, we use the DFR0576 I2C multiplexer.
Our understanding
As we understand the I2C multiplexer operation, the correct sequence should be:
-Open / select the I2C multiplexer
-Select the desired multiplexer channel (port)
-Then send commands to the SEN0364 color sensor on that channel
Observed issue in MIND+
We implemented the blocks in MIND+ according to this logic.
However, when we examine the generated C code, we observe that:
-The initialization of the SEN0364 color sensor is always placed before any I2C multiplexer selection
-This initialization code is located after void setup(), but before the I2C multiplexer is opened and a channel is selected
Please see the attached document for the generated code.
Hypothesis
Because the SEN0364 sensor is initialized before the I2C multiplexer channel is selected, we suspect that:
-The sensor cannot be properly initialized
-This is the reason why the SEN0364 sensors do not work when connected through the I2C multiplexer
When manually editing the code generated by MIND+ and reversing the instruction order (initializing the I2C multiplexer and selecting the channel before initializing the SEN0364 sensor), we observe that the color sensor works correctly through the I2C multiplexer.
Questions
-Can you please confirm whether our analysis is correct?
-Is this a known limitation or bug in MIND+?
Is there a recommended workaround or solution, such as:
-A different way to use I2C multiplexers in MIND+
-Planned support for this use case?
This feature is very important for educational robotics projects, especially for line-following robots, where multiple color sensors are required.
Thank you very much for your support.
Best regards,
Patrick
Hello ,
This is a very insightful analysis of the I2C communication flow within the Mind+ environment. You have correctly identified a conflict between the hardware requirements of I2C multiplexing and the code generation strategy of the software.
Here is a breakdown of why this is happening and a practical workaround to get your line-following robot running.
# Analysis of the Issue
Your analysis is correct. For an I2C multiplexer (like the DFR0576) to function, the "Select Port" command must be sent over the main bus before any communication is attempted with the device sitting behind that port.
## Why Mind+ generates code this way:
In Mind+, the initialization blocks for I2C sensors are designed to be "safe." To prevent users from accidentally placing initialization code inside a loop()—which would cause the sensor to reset constantly and crash the program—Mind+ force-generates initialization code into the setup() function.
The software gives code generated for setup() a higher priority/fixed position. Blocks that are "freestanding" (like your Select Port blocks) are treated as standard procedural code. Consequently, the compiler always places the sensor's begin() call at the top of the sequence, regardless of where you place the block in the UI.
## Is this a bug?
Strictly speaking, it is not a bug but a code generation strategy. This strategy works for 99% of users to ensure stability. However, I2C multiplexers are a "special case" where the order of operations is critical. Adjusting the entire global generation logic for one specific module is a high-risk change for the software developers, which is why this limitation exists.
## Recommended Workaround: Using the "Code Block" Extension
The simplest way to bypass this fixed order without manually editing the C++ code every time is to use the Code Block extension. This allows you to inject raw code exactly where you want it in the sequence.
## Steps to resolve:
1. Install the Extension: Go to the "Extensions" manager in Mind+, search for "Code Block" (often found under User-ext or Community extensions), and add it to your project.

2. Deconstruct the Initialization: Remove the standard "Init visible spectrum sensor" block that is causing the early initialization.
3. Manual Initialization via Code Block:

4. The Result: Because the Code Block is treated as a standard block (like the Select Port block), Mind+ will generate them in the exact order they appear in your workspace, ensuring the multiplexer switches ports before the sensor attempts to wake up.
LL Thanks, I'll try it.



