Close
0%
0%

Minimal RP2040 Hebbian Button Pattern Learner

This project is a small, physically legible demonstration of online Hebbian-style learning on an RP2040 microcontroller

Similar projects worth following
This project is a small, physically legible demonstration of online Hebbian-style learning on an RP2040 microcontroller using only:

Two momentary buttons (A and B) as inputs
Two LEDs as outputs (PWM brightness encodes belief/confidence)

The device learns next-symbol prediction from a short, decaying history of recent button taps. Every button press simultaneously:

Evaluates the current prediction (shown on the LEDs)
Updates synaptic weights immediately using a competitive Hebbian / anti-Hebbian rule
Shifts the new event into the history buffer

There are no training vs inference modes, no hard-coded pattern detectors, and no stored “patterns” beyond what the system reinforces through continued interaction.

Read the PDF file, it covers everything...

READ THE PDF FILE

Hebbian learning (in this project) is a simple local learning rule often summarized as “neurons that fire together wire together.” In this device, the “neurons” are just a small set of weights that connect a short history of recent button presses to a prediction of the next press. Each tap updates the weights immediately: the connections that helped predict the correct next button are strengthened, while competing connections are weakened. Over time the device learns short-term correlations, and it gradually forgets them if they are not reinforced.

Minimal RP2040 Hebbian Button Pattern Learner

This project is a small, physically legible demonstration of online Hebbian-style learning on an RP2040 microcontroller using only:

  • Two momentary buttons (A and B) as inputs

  • Two LEDs as outputs (PWM brightness encodes belief/confidence)

The device learns next-symbol prediction from a short, decaying history of recent button taps. Every button press simultaneously:

  1. Evaluates the current prediction (shown on the LEDs)

  2. Updates synaptic weights immediately using a competitive Hebbian / anti-Hebbian rule

  3. Shifts the new event into the history buffer

There are no training vs inference modes, no hard-coded pattern detectors, and no stored “patterns” beyond what the system reinforces through continued interaction.

What it demonstrates

This is intended as a hands-on teaching aid for the following concepts:

  • Online learning (learning happens continuously, not in sessions)

  • Temporal correlation learning (short context → next event)

  • Competition between outputs (one prediction suppresses the other)

  • Forgetting (fast decay of short-term context + slow decay of weights)

  • Uncertainty (belief is expressed continuously rather than as hard decisions)

How it works (high level)

The model maintains a fixed-length history window of the last N taps, represented as a positional one-hot activity trace. This trace decays continuously with time, so prediction confidence fades during silence.

Two output neurons compute activations from this history trace. Belief is computed from the activation difference using a logistic function, and LED brightness is derived from belief. The exact LED mapping is intentionally treated as a user-interface choice; the reference firmware dims both LEDs under high uncertainty rather than acting as a literal probability meter.

Learning occurs only on valid button-press events, using the pre-tap context as input and the observed event as the label (event-supervised local learning).

Hardware

The hardware is intentionally minimal:

  • RP2040 board (Raspberry Pi Pico or equivalent)

  • 2x momentary buttons (active-low, using internal pull-ups)

  • 2x LEDs + 2x resistors (220Ω typical)

READ THE PDF FILE

main.cpp

Demonstration code which follows the documentation in main.pdf

plain - 18.31 kB - 01/28/2026 at 07:41

Download

schematic.png

Basic Schematic

Portable Network Graphics (PNG) - 22.36 kB - 01/28/2026 at 07:18

Preview

main.pdf

READ THIS DOCUMENT, ITS THE WHOLE PURPOSE FOR THIS PROJECT POSTING!

Adobe Portable Document Format - 259.54 kB - 01/28/2026 at 07:15

Preview

  • 1 × RP2040 microcontroller board Raspberry Pi Pico
  • 1 × Green 5mm LED Green LED (A)
  • 1 × Blue 5mm LED Blue LED (B)
  • 2 × Momentary Pushbutton Momentary Pushbutton (A and B)
  • 2 × 220 Ohm Resistors If you want, add resistors for the LEDs

  • Submitting the 'project'

    fl@C@3 days ago 0 comments

    I'm submitting this to get a feel for interest in artificial intelligence/Machine Learning on platforms like the RP2040... If there's any interest, I am open for discussion .. . and have A LOT more to share..

View project log

  • 1
    Wire up the buttons and the LEDs. Done.

    Build Instructions-

    Building this is VERY basic.....

    1) Parts Needed

    • 1× RP2040 microcontroller board (Raspberry Pi Pico or compatible)

    • 2× momentary pushbuttons (Button A, Button B)

    • 2× LEDs (LEDA, LEDB)

    • 2× resistors for LEDs (220Ω typical)

    • Jumper wires / breadboard or protoboard

    2) Wiring

    Buttons (active-low inputs)

    Each button connects its GPIO pin to GND when pressed.

    • Button A: GPIO 12 

    • Button B: GPIO 19 

    Both buttons go straight to ground.

    LEDs (PWM outputs)

    Each LED is driven from a GPIO pin through a series resistor to ground:

    • LEDA: GPIO 9 

    • LEDB: GPIO 22

    Both leds to ground.. (use 220 Ohm resistors if you want)

  • 2
    Code

    I use PlatformIO.... This project isn't a lesson in programming microcontrollers, so use whatever you like...

View all instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates