Skip to content

Minimizing Blinky's Size to Its Utmost Extent

Simplifying microcontroller programming for beginners usually begins with the fundamental Blink Arduino sketch or similar routines. Lighting an LED on and off is a basic task, hardly complex. However, what's the appropriate size for a microcontroller project beyond this simple exercise?

The fundamental Blink Arduino code, which many are familiar with, or have implemented on various...
The fundamental Blink Arduino code, which many are familiar with, or have implemented on various microcontrollers, typically involves switching an LED on and off. Delving deeper, one might wonder about the size limits of the code.

Taunting the Minimal: Blinky Bloke's Odyssey

Minimizing Blinky's Size to Its Utmost Extent

Dabbling with the fundamentals of Blink Arduino sketches is a breeze for most of us geeks. Ticking an LED on and off? Piece of cake, mate. But just how compact could you make a blink sketch? Or, better yet, how minuscule? Artful Bytes aimed to shed some light on this enigma.

The objective: concoct a program for a microcontroller that would blink an LED with the ON and OFF periods as close to a grand as possible. The battle of wits kicked off with the NUCLEO-L432KC Cortex-M4, boasting 256 K of flash and 64 K of RAM.

No spoilers here, but the journey begins with a brain injury-inducing AI and cloud solution. Artful Bytes then streamlined the process by ditching the AI for an RTOS approach, followed by a diet of C, assembly, and, finally, machine code. The goal was to shrink the microcontroller code to its barest essence. But here's where things get fascinating—the video title claims they've "Shrunk Blinky to 0 Bytes." Astonishingly, when you eliminate digital code-running hardware altogether, you can still get that LED to dance. That's right, zero bytes is possible.

We've previously showcased the tiniest blinky in a physical sense, but today we're chatting about code size.

Shrinking the Legacy: Blinky's Ancestors

Remember those good old days when the simplest blink program for an ESP32 required merely a handful of lines in C? Here's a refresher:

```cvoid setup() { pinMode(5, OUTPUT);}

void loop() { digitalWrite(5, HIGH); delay(1000); digitalWrite(5, LOW); delay(1000);}```

This code sets a pin as output, turns it on for one second, takes a breather, and then turns it off for another second, creating the iconic blinky effect.

Digging Deeper: Analog Hardware for Blinky Business

Forget digital code; you can create a blinking effect with analog hardware. How, you ask? By harnessing the power of an astable multivibrator—a nifty oscillator that spits out a consistent square wave. Here's the lowdown on constructing your own:

Components Needed:

  • 2 x Transistors (e.g., NPN)
  • 2 x High-value Resistors (e.g., 10kΩ)
  • 2 x Low-value Resistors (e.g., 1kΩ)
  • 2 x Capacitors (e.g., 10μF)
  • 1 x LED
  • 1 x Resistor for the LED (e.g., 220Ω)
  • Power Source (e.g., battery)

Circuit Setup:

  1. Transistors: Link the collectors of both transistors together to the positive supply rail.
  2. High-value Resistors: Connect one end of each high-value resistor to the base of its respective transistor.
  3. Low-value Resistors: Connect one end of each low-value resistor between the collector and the base of its respective transistor.
  4. Capacitors: Connect one capacitor between the base of the first transistor and ground. Connect the second capacitor between the base of the second transistor and ground.
  5. LED: String together the LED and its resistor between the collector of one transistor and ground.

How It Works:

  • When one transistor fires up, the other gets switched off due to the cross-coupling arrangement, establishing a stable oscillation.
  • This oscillation in turn causes the LED to blink on and off, with the frequency governed by the capacitors and resistors.

And voila! You've crafted a blinking circuit without any digital code, relying solely on the inherent properties of transistors and capacitors.

Modern Marvels: Quantum Leaps in Microcontrollers

For digital solutions, miniature marvels like the MSPM0C1104 from Texas Instruments are at your service. These bad boys boast a 24 MHz Arm Cortex-M0+ core and up to 16 KB of flash memory. Tailored for space-constrained applications, they're perfect for controlling LEDs with a minimum of fuss.

In the quest for minimizing digital code, Artful Bytes claimed to have "Shrunk Blinky to 0 Bytes," demonstrating that even without digital code-running hardware, an LED can still be made to blink. (Artful Bytes)

Reminiscing about the past, a simple blink program for an ESP32 required only a few lines of C code. (The Good Old Days)

Read also:

    Latest