Extending modulino objects: Source code locations (Modulino and firmware). How to build and update the modules

Was wondering if the source code for the underlying processors like the STM32C011F4 on the Modulino Joystick and Modulino Buttons available?

And if so, is it possible to experiment with adding or changing functionality?

Thanks,

Kurt

Some is available here: GitHub - arduino/node_modulino_firmware · GitHub
(but I don't see the joystick :-( )

Thanks,

I should have looked there as well. I looked up under
Arduino Libraries · GitHub as that was where the Modulino project was.

I'm not sure I understand what you mean by this. The firmware source code does contain the implementation for the Modulino Joystick:

https://github.com/search?q=repo%3Aarduino%2Fnode_modulino_firmware+node_joystick&type=code

As for the firmware binary, the general purpose firmware build is used by the Modulino Joystick:

Ah. I didn't look carefully enough - I saw separate files for the motor and matrix boards, and assumed the joystick was also sufficiently complex to warrant its own C file...

"Never Mind."

Thanks @ptillisch,

I remember being here once before.

Did run into some issues with this:
In the Readme...

git clone --recursive https://github.com/arduino/node_modulino_firmware
./build.sh
# symlink / copy the sketches/libraries/Modulino folder to your sketchbook
# compile and run the FirmwareUpdater.ino example while only one modulino is connected to a UNO R4

First the git clone recursive fails.

Cloning into '/home/kurte/git/node_modulino_firmware/sketches/libraries/Modulino'...
The authenticity of host 'github.com (XXXXXXXXX)' can't be established.
ED25519 key fingerprint is SHA256:+xxxxxxxxxxxxxxxxxxxx
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? y
Please type 'yes', 'no' or the fingerprint: yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

I am pretty sure the issue is in the .gitmodules:

[submodule "sketches/libraries/Modulino"]
	path = sketches/libraries/Modulino
	url = git@github.com:arduino-libraries/Modulino

That that form of url implies you are logged in ... should be something like:
url = https://github.com/arduino-libraries/Arduino_Modulino.git

Second problem with Readme...
./build.sh
Does not do anything on my Windows machine ;)
Seriously I wish Arduino would not always be so linux centric...

And the last line in the Readme:

# compile and run the FirmwareUpdater.ino example while only one modulino is connected to a UNO R4

Can you only update the firmware by running that sketch only on an Uno R4 WiFi?

Thanks again, now to play

EDIT: I finagled getting Modulino library linked in to this...
But then Build fails:

kurte@KurtXPS8950:~/git/node_modulino_firmware$ ./build.sh
rm -fR build
mkdir -p build
arm-none-eabi-gcc -c -mcpu=cortex-m0 -mthumb   -DUSE_HAL_DRIVER -DSTM32C011xx   -ICore/Inc -IDrivers/STM32C0xx_HAL_Driver/Inc -IDrivers/STM32C0xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32C0xx/Include -IDrivers/CMSIS/Include -Os -Wall -fdata-sections -ffunction-sections -MMD -MP -MF"build/main.d" Core/Src/main.c -o build/main.o
/bin/sh: 1: arm-none-eabi-gcc: not found
make: *** [Makefile:186: build/main.o] Error 127
kurte@KurtXPS8950:~/git/node_modulino_firmware$

Solved:
sudo apt-get install gcc-arm-none-eabi

I see you reported this already some time ago:

Thanks!

At least traditionally, this has been standard practice for software developers as a whole. My advice for Windows users is to use Git Bash. It is part of the Git for Windows installation, so if you have Git installed on your computer then you likely already have Git Bash installed.

In most cases, this will allow you to run shell scripts natively on the Windows system without any problems at all. You might occasionally find that a certain standard shell commands is not implemented, but my experience of using it daily for over a decade indicates this is very rare in practice.

I greatly prefer this over WSL, because if I want to use Linux I'll just use Linux without the involvement of the ever user hostile Microsoft in the equation.

I'm not sure which boards are supported by the current production FirmwareUpdater sketch. However, I did do extensive testing on an improved version (arduino-libraries/Arduino_Modulino#77) of the sketch, which is in the development version of the Arduino_Modulino library available here:

My findings:

Board FirmwareUpdater Works?
Nano 33 BLE (arduino:zepyr_main) :white_check_mark:
Nano 33 IoT :white_check_mark:1
Nano ESP32 :cross_mark:2
Nano Matter (arduino:zepyr_main) :cross_mark:3
Nano Matter (SiliconLabs:silabs) :cross_mark:4
Nano R4 :white_check_mark:
Nano RP2040 Connect (arduino:mbed_nano) :cross_mark:5
Nano RP2040 Connect (arduino:zepyr_main) :cross_mark:5
UNO Q :white_check_mark:
UNO R4 WiFi :white_check_mark:
VENTUNO Q :white_check_mark:6

Footnotes

1: The on-board devices at addresses 0x60 and 0x6A are misidentified as Modulinos.
2: Update fails: "Write page operation failed at intermediate step!". The target Modulino is left in bootloader mode after this failure.
3: Connected Modulinos are not detected.
4: Sketch always displays a "A Modulino device was detected in bootloader mode." even when there is no such device, and even when no Modulino is connected to the board.
5: Compilation fails due to sketch size exceeding available memory.
6: After rebasing on https://github.com/arduino-libraries/Arduino_Modulino/commit/0b6f55b3646e56607c8b943dfefdebe47c15cdf6.

The updated FirmwareUpdater sketch also eliminates the "only one modulino is connected" requirement.

I'm glad you were successful in the end! It is unfortunate that the firmware wasn't written in the form of an Arduino sketch. I like that we did so for other firmwares such as the UNO R4 WiFi bridge, MuxTO, and MKR/Nano Motor Carrier.

This highlights how much more accessible Arduino made embedded systems compared to the standard approaches in use circa 2005. Of course you are able to overcome such obstacles, but they would be a showstopper for many casual beginners.

Thanks again!

Just playing - But thinking about trying to start of with maybe enhancing the buttons object to maybe:
a) remember the data from previous call to update, and have functions like:
justPressed(btn), justReleased(btn).

b) Not sure maybe just return one byte for the 3 buttons.

c) maybe add stuff to the main loop:

  /* Infinite loop */
  while (1)
  {
    HAL_IWDG_Refresh(&hiwdg);
    if (endTone != 0 && HAL_GetTick() > endTone) {
      HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_1);
      endTone = 0;
    }

#if !defined(MODULINO_LEDMATRIX_BUILD)
    if (PINSTRAP_ADDRESS == NODE_JOYSTICK) {
      ADC_ChannelConfTypeDef sConfig = {0};
...

That maybe, does like when the I2C request comes in to get the state:

      i2c_buffer[1] = !HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0);
      i2c_buffer[2] = !HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1);
      i2c_buffer[3] = !HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_2);

But instead it simply sets a variable (or bit in variable) if these buttons are ever pressed.
Could add some validation in it, like the button has been down for N cycles through the main loop...
And then have the I2C request return this state...

Then could have a method like: btns.hasBeenPressed(btn)...

Will see... Of course I could do what I did in earlier sketch on GIGA, I think and have a background thread that calls the update function every N ms....

But just playing

In case anyone is interested.

I have been playing around with some additions to the ModulinoButons class.
I have some of the things I wanted working.

I have created two draft Pull requests:

Enhance MdulinoButtons by KurtE · Pull Request #87 · arduino-libraries/Arduino_Modulino

The above one has the updated firmware including my changes. I have used the
FirmwareUpdater sketch in the Arduino_Modulino examples, to update the firmware on my Arduino buttons board, which I ran from an Arduino Uno R4 WiFi.

One nit with this sketch says that if it succeeds, it will display Pass on the Led Matrix, but all I see is Pas :wink:

So you can actually run it without the below PR, but if one wants to see it and or
change it...

enhance the firmware for ModulinoButtons by KurtE · Pull Request #28 · arduino/node_modulino_firmware

Quick and dirty test sketch - I probably should change the comments at the top of it.

/*
 * Modulino Buttons - Basic
 * 
 * This example demonstrates how to read button presses from the Modulino Buttons module
 * and control the LEDs above each button.
 * 
 * The Modulino Buttons module features:
 * - Three push buttons labeled A, B, and C
 * - Three LEDs above the buttons (one above each button)
 * - Buttons can be checked by index (0, 1, 2) or by letter ('A', 'B', 'C')
 * 
 * In this example:
 * - Each button press toggles a boolean variable
 * - The corresponding LED reflects the state of that variable
 * - LED on = true, LED off = false
 * 
 * Usage:
 * - Press button A to toggle LED A
 * - Press button B to toggle LED B
 * - Press button C to toggle LED C
 * 
 * Applications:
 * - User input interface
 * - Menu navigation
 * - On/off controls
 * - State indicators
 *
 * This example code is in the public domain.
 * Copyright (c) 2025 Arduino
 * SPDX-License-Identifier: MPL-2.0
 */

#include <Arduino_Modulino.h>

// Create a ModulinoButtons object
ModulinoButtons buttons;

// Variables to store the LED states for each button
// true = LED on, false = LED off
bool button_leds[3] = { true, true, true };
long loop_delay_ms = 1000;

void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 5000) {}
  delay(500);
  // Initialize Modulino I2C communication
  Serial.println("Updated Modulino Buttons test");
  Serial.println("You can enter a how long to delay in MS at the end of loop in Serial monitor");

  Modulino.begin();
  // Detect and connect to buttons module
  if (!buttons.begin()) {
    Serial.println("Modulino Buttons begin Failed\n");
  }
  // Turn on all three LEDs above buttons A, B, and C
  // Parameters: setLeds(LED_A, LED_B, LED_C)
  buttons.setLeds(true, true, true);
}

void print_btn_state(int btn, bool &has_printed, const char *sz) {
  if (!has_printed) {
    Serial.print("BTN: ");
    Serial.write((char)('A' + btn));
    has_printed = true;
  }
  Serial.print(sz);
}

void loop() {
  if (Serial.available()) {
    loop_delay_ms = Serial.parseInt();
    Serial.print("Loop delay set to: ");
    Serial.print(loop_delay_ms);
    Serial.println(" ms");
    while (Serial.available()) Serial.read();
  }
  // Check for new button events
  // Returns true when any button state changes (pressed or released)
  if (buttons.update()) {
    // You can use either index (0=A, 1=B, 2=C) or letter ('A', 'B', 'C') to check buttons
    // The API accepts both char (single quotes) and string (double quotes) for letters
    // Below demonstrates both methods work: 'A' is char, "B" is string, 'C' is char
    for (int btn_index = 0; btn_index < 3; btn_index++) {
      bool something_printed = false;
      if (buttons.isPressed(btn_index) || buttons.wasPressed(btn_index)) button_leds[btn_index] = !button_leds[btn_index];
      if (buttons.isPressed(btn_index)) print_btn_state(btn_index, something_printed, " Pressed");
      if (buttons.justPressed(btn_index)) print_btn_state(btn_index, something_printed, ", Just Pressed");
      if (buttons.justReleased(btn_index)) print_btn_state(btn_index, something_printed, " Just Released");
      if (buttons.wasPressed(btn_index)) print_btn_state(btn_index, something_printed, " (was pressed)");
      if (something_printed) Serial.println();
    }


    // Update the LEDs above buttons to reflect the current variable states
    buttons.setLeds(button_leds[0], button_leds[1], button_leds[2]);
  }
  if (loop_delay_ms) delay(loop_delay_ms);
}

@ptillisch - I wonder if I should continue this part of this discussion on a new thread?

The moderators do have a policy of splitting off tangential discussions initiated by parties other than the topic creator. However, in the case where the tangential discussion is initiated or encouraged by the topic author, we are generally OK with letting them conduct the topic as they prefer (within the forum's universal standards of behavior of course).

So it is entirely up to you. If you want me to split the discussion of the Modulino Buttons enhancements to a dedicated topic, I'm happy to do so. Just let me know.

1 Like

Thanks,

For now, probably fine to leave topic as one...
I might remove the Solution tag...
Depending on how much more I do here.

I put in a proposed fix for this:
Submodule: Modulino to Arduino_Modulino by KurtE · Pull Request #29 · arduino/node_modulino_firmware