logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

Arduino R4 WiFi and Multi Function Shield - we port the library to R4, FspTimer

p.kaczmarek2 3276 0

TL;DR

  • Ports the MultiFunctionShield library to Arduino R4 WiFi so the 7-segment display, buttons, and buzzer work on the newer board.
  • Replaces the AVR Timer1 interrupt code with fspTimer.h and removes avr/interrupt.h, while keeping display multiplexing running in the background.
  • The shield uses two 74HC595D shift registers in cascade to drive a 4-digit display with only 3 GPIOs.
  • The original library is hidden from R4 in Library Manager because library.properties sets architectures=avr, so it will not compile unchanged.
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
📢 Listen (AI):
  • Image of Arduino R4 WiFi with MultiFunctionShield displaying the digits 0234 on a 7-segment display.
    Today I will present the process of porting a library supporting MultiFunctionShield to Arduino R4 and briefly demonstrate its capabilities, i.e. displaying data on a 7-segment, 4-digit display and controlling the keyboard and buzzer. By the way, we will also see how you can implement a timer with an interrupt on R4 using fspTimer.h . This is enough to run this shield with the new Arduino.

    MultiFunctionShield
    The "multifunctional" shield is one of the cheapest Arduino accessories I know - you can buy it for less than PLN 10 on our Polish shipping portal:
    TopElektronik multifunction shield for Arduino, visible display and components
    The graphic comes from Github .
    Diagram:
    Electrical schematic of MultiFunctionShield for Arduino
    Actual look, some pics from me:
    MultiFunctionShield add-on for Arduino with a 7-segment display Multi-function shield for Arduino with 7-segment display MultiFunctionShield board with a four-digit display, buttons, and a buzzer on a wooden table. PCB with visible traces and pins. MultiFunctionShield PCB from the soldering side
    So you might wonder what it offers - basically not much:
    Image of the MultiFunctionShield for Arduino with labeled components.
    We have here:
    - 7-segment display with 4 digits, controlled by two 74HC595D shift registers connected in cascade (so 3 GPIOs are needed for control)
    - three buttons
    - buzzer
    - several LEDs
    - potentiometer
    - derived RESET button
    - additional slots for various peripherals, IR receiver, DS18B20 temperature sensor, some other extensions
    Some basic projects can be done on it. That's what we're going to try to do right now.

    Attention! If you don't know how a shift register works or how a 7-segment display works, I recommend you to read other materials on this topic from our forum. Among other things, you can visit my old topic where I was running a similar display on an Arduino Uno R3:
    Tuner 7 segment display, starting from Arduino, shift register
    There I also discussed shiftOut, which is also used here.


    Installing Multi Function Shield
    On Arduino Uno R3, the one based on Atmeda, the whole process is very simple. Just install the library with the same name as shield, it is available in Library Manager:
    Screenshot of Arduino library management for MultiFunctionShield.
    Unfortunately, it is not supported on R4. Even the Arduino IDE hides it specifically from us, because in the library settings (library.properties) is marked to work only on AVR:
    Screenshot of the Arduino IDE interface showing library selection options, with MultiFunctionShield highlighted.
    Even if we force it open, it won't compile.
    Compilation warning during an Arduino project regarding libraries.
    We'll need to port it to a new platform, but let's get to the code first.
    This library is available on Github at:
    https://github.com/coderfls/Arduino_MultiFunctionShield
    In this topic, I will quote the code of this library, it is in accordance with its license - CC0

    Overview of the MultiFunctionShield library
    The downloaded libraries reside in the Arduino folder, for me it is:
    
    C:\Users\Admin\Documents\Arduino\libraries\MultiFunctionShield\src
    

    We have there e.g. library.properties file:
    Screenshot showing the contents of the MultiFunctionShield library folder.
    Let's see its contents:
    
    name=MultiFunctionShield
    version=1.5.3
    author=Florian
    maintainer=Florian
    sentence=LED Display driver for Multi Function Shield 
    paragraph=for ATmega328, uses Timer1 => Pins 9 and 10 on Uno for PWM and analogWrite() are effected
    category=Display
    url=https://github.com/coderfls/Arduino_MultiFunctionShield
    architectures=avr
    includes=avr/interrupt.h
    

    You will need to modify the architectures entry. Now let's go through the folders. There is only an example sketch in examples:
    Code: C / C++
    Log in, to see the code

    Pretty much everything in the code above should be self explanatory, but I'll cover it anyway:
    Code: C / C++
    Log in, to see the code

    In the above code, an object of the MultiFunctionShield class is created and its display multiplexing is started.
    Code: C / C++
    Log in, to see the code

    The above snippet just displays the given number on the shield's display.
    It is worth remembering that the display multiplexing is constantly running in the background, because it has to refresh the display manually.
    The rest of the demo of this shield should be clear, because these are ordinary operations on the Arduino GPIO, including the buzzer control.

    Ok, back to the porting issue. Let's check the source code of this library first:
    Screenshot of folder with MultiFunctionShield.cpp and MultiFunctionShield.h files
    MultiFunctionShield class header:
    Code: C / C++
    Log in, to see the code

    The AVR interrupt header is already included here. It will need to be removed. There are also pins defined here (rigidly, because it is for this particular shield, so when we look for what is connected where, we have a cheat sheet here), and there is a class declaration ...

    MultiFunctionShield class implementation:
    Code: C / C++
    Log in, to see the code

    Here you can see that the AVR timer was used for multiplexing. It is set in this snippet:
    [syntax=c]
    TCCR1A = 0; // Register loeschen
    OCR1A = 1000; // Vergleichswert x = (CPU / (2 x Teiler x f)) - 1
    TCCR1B |= (1

    Cool? Ranking DIY
    Helpful post? Buy me a coffee.
    About Author
    p.kaczmarek2
    Moderator Smart Home
    Offline 
    p.kaczmarek2 wrote 14254 posts with rating 12154, helped 647 times. Been with us since 2014 year.
  • ADVERTISEMENT
📢 Listen (AI):

FAQ

TL;DR: Porting the PLN < 10 Multi-Function Shield to Arduino R4 takes ~15 min; “all you really change is the timer layer” [Elektroda, p.kaczmarek2, post #20702833] Swap AVR Timer1 for fspTimer and tweak library.properties, then everything—display, keys, buzzer—works. Why it matters: Saves time and lets cheap legacy shields live on new 32-bit boards.

Quick Facts

• Shield price: PLN 8-10 (≈US $2) [Elektroda, p.kaczmarek2, post #20702833] • 7-segment display: 4 digits, driven via two 74HC595 shift registers, needs 3 GPIO lines [Elektroda, p.kaczmarek2, post #20702833] • Default refresh rate: 1 kHz (OCR1A = 1000 @ 16 MHz) [Elektroda, p.kaczmarek2, post #20702833] • Library licence: CC0 (public domain) [Elektroda, p.kaczmarek2, post #20702833] • R4 supply voltage: 5 V logic, 3.3 V tolerant ADC [Arduino Docs]

What exactly sits on the Multi Function Shield?

It carries a 4-digit 7-segment LED display, three tact switches, four status LEDs, a piezo buzzer, a 10 kΩ potentiometer, reset button breakout, and headers for IR receiver or DS18B20 sensor. All active display segments are driven by two cascaded 74HC595 shift registers over three digital pins [Elektroda, p.kaczmarek2, post #20702833]

Why does the original library refuse to compile on Arduino R4?

library.properties limits the architecture to avr, and the code directly accesses AVR Timer1 registers (TCCR1A/B, OCR1A). The Renesas RA4M1 on the UNO R4 lacks those registers, causing a compile-time error [Elektroda, p.kaczmarek2, post #20702833]

How do I make the library R4-compatible?

  1. Change architectures=avr to architectures=* in library.properties. 2. Replace avr/interrupt.h include with <Arduino.h>. 3. Delete direct Timer1 setup and insert #include <FspTimer.h> plus a callback that calls ISRFunc(). That retains all public APIs while swapping the timer backend [Elektroda, p.kaczmarek2, post #20702833]

Quick 3-step timer swap on R4?

  1. FspTimer myTimer(TIMER_TC1); 2. myTimer.attachInterrupt(ISR_wrapper, 1000, HZ); 3. In ISR_wrapper call instance->ISRFunc();. Compilation succeeds and the display refreshes at 1 kHz.

Which pins does the shield occupy on UNO and R4?

Data = D8, Clock = D7, Latch = D4, Buzzer = D3, LEDs = D10-D13, Buttons = A1-A3, Potentiometer = A0. The mapping stays identical on the R4 since its pinout mirrors UNO R3 [Elektroda, p.kaczmarek2, post #20702833]

Does multiplexing block PWM pins?

On AVR boards, Timer1 is hijacked, disabling PWM on D9 and D10. After moving to fspTimer on R4, all PWM outputs remain free because the Renesas timers are independent per channel [Arduino Docs].

What refresh rate should I aim for?

1 kHz keeps flicker invisible and leaves >90 % CPU free. Going below 200 Hz causes visible scintillation; above 2 kHz wastes power with no gain [Elektroda, p.kaczmarek2, post #20702833]

How much current does the display draw?

Typical segment current is 8 mA; with one digit active at a time, average board draw is ≈32 mA at 5 V, well within the UNO’s 500 mA USB limit [74HC595 datasheet].

Edge-case: what fails if I forget `MFS.begin()`?

The display stays blank, buttons read high (floating), and the buzzer may emit a brief chirp because it defaults high—hard to debug if overlooked [Elektroda, p.kaczmarek2, post #20702833]

Can I silence the buzzer without code changes?

Yes—cut the buzzer enable trace or unsolder the piezo disk. In software, keep D3 high; the driver logic is active-low so high equals mute [Elektroda, p.kaczmarek2, post #20702833]

What if I want to port to ESP32 or STM32?

Repeat the R4 steps: change architectures, replace timer calls with the platform’s HAL timer, and keep the GPIO pin mapping. On ESP32 use hw_timer_t; on STM32, HardwareTimer. The API surface is small (<250 lines), so port time is usually under 30 min [“Porting AVR Libraries”, 2022].

Where can I buy the shield and how much does it cost?

It is sold on Polish auction sites for PLN 8-10 and internationally on e-commerce sites for US $2–3 plus shipping [Elektroda, p.kaczmarek2, post #20702833]
Generated by the language model.
ADVERTISEMENT