Categories
Computing

Day 4, Box 2 – flashing LED

For Day 1, go here. The series is tagged advent-2025.

For Box 2 in the calendar, we get an LED, a resistor and a pair of jumper leads. We can connect those up:

And type these lines into the REPL:

place struct { uint32@0x014 gpio_out_set; uint32@0x024 gpio_oe_set; } @xd0000000 sio_hw;

place struct { struct { uint32@0x4 ctrl; }[30] gpio; } @x40014000 io_bank0;

const block_led = 0d14;

const gpio_field = 0x1 << block_led;

poke io_bank0.gpio[block_led].ctrl, 0d5;

poke sio_hw.gpio_oe_set, gpio_field;

poke sio_hw.gpio_out_set, gpio_field;

This is almost the same as hello_led, but I have removed a couple of the constant definitions, to minimise typing.

Of course, typing line-by-line will get old quick, so we need a way to load a whole Yarg file at once. That’s the job of hostyarg, which currently requires go to be installed. This tool will take an existing Yarg uf2 file and add a Yarg file to it.

So head over to the go website, and install go for your O/S. Follow the release README to then install hostyarg.

Once you have that, you’ll want to flash an LED like the MicroPython folks. Let’s stop poking raw registers for GPIO, and use a library. In fact we’ll use two – one for GPIO (called, ‘gpio’!), and one for a sleep function (‘timer’).

Here’s the file (flash.ya) in full, and it’s in this GitHub repo:

import("gpio");
import("timer");

const blocky_LED = 0d14;
gpio_init(blocky_LED);
gpio_set_direction(blocky_LED, GPIO_OUT);

var n = 4;

while (n > 0) {
    gpio_put(blocky_LED, !gpio_get(blocky_LED));
    sleep_ms(500);
    n = n - 1;
}

Yarg files are plain text (officially utf8, but ascii will be fine for this example).

We need to use hostyarg to add it to the uf2 from the release. First we make a copy (I’ll assume you’re using the repo’s file structure), and then add the file:

% cd box2
% cp ../yarg-lang-pico-0.2.1/yarg-lang-pico-0.2.0.uf2 box2.uf2

% hostyarg addfile -fs box2.uf2 -add flash.ya

box2.uf2 now can be flashed onto the pico in the usual way. Once that boots up, and presents the > prompt (maybe press return to get it), use the import function to run it:

> import("flash");

And we see the LED flash! That’s it for box2.

You’ll see a box2.uf2 in the repo if you can’t get hostyarg working. If you want to edit the flash.ya file, you’ll need to copy the base uf2 and use addle each time. There’s no way to edit an existing file at this time.

Categories
Computing

Day 3: Pacing

For Day 1, look here. The series is tagged advent-2025.

There are 12 boxes in the PiHut Let it Glow calendar. The first couple of days also illustrate that Yarg will need a bit of work for some of them. As such, I won’t be posting every calendar day! I’m also going to consider this post series successful if I complete them in some of the time after Christmas. There is a lot on at this time of year, and I’ve done no preparation for these posts.

Categories
Computing

Day 2: Hello Led

For Day 1, go here. The series is tagged advent-2025.

Box 1 contains a Pico, a USB lead and two breadboards:

Over in Micropython, the task is to light the LED on the board, configuring Thonny, etc along the way. Here in Yarg we need to:

  • Download the 0.2.1 release (yarg-lang-pico-0.2.1.tgz)
  • Uncompress the file (on a Mac, the finder will do that with a couple of double-clicks).
  • Connect the pico to the Mac holding down the bootsel button (see the linked PiHut guide above, if that’s unfamiliar. It’s harmless to try both – use their day 1 to explore, and then come back here to do Yarg Day 1)
  • Copy yarg-lang-pico-0.2.0.uf2 to the RPI-RP2 drive, and wait for the pico to restart:

Connect to the USB serial port it shares. Some exploring may be needed to find it in your serial program of choice. VS Code is a bit big to download, but seems to be free and available on all the PC platforms. The ‘Serial Monitor’ Extension seems to work well. Recent testing in putty on windows suggests Yarg doesn’t like that option (yet!)

‘Serial’ connected to Pico device (115200, 8N1, Local Echo, send CR+LF on return)

Type in, line by line, the hello_led example (I cut and paste from this post!)

const NUM_BANK0_GPIOS = 30;

place struct { uint32@0x014 gpio_out_set; uint32@0x024 gpio_oe_set; } @xd0000000 sio_hw;

place struct { struct { uint32 status; uint32 ctrl; }[NUM_BANK0_GPIOS] gpio; } @x40014000 io_bank0;

const pico_led = 0d25;
const gpio_field = 0x1 << pico_led;

const GPIO_FUNC_SIO = 0d5;

poke io_bank0.gpio[pico_led].ctrl, GPIO_FUNC_SIO;
poke sio_hw.gpio_oe_set, gpio_field;

poke sio_hw.gpio_out_set, gpio_field;

And the light will come on:

Box 1 completed! If you’d like to understand hello_led more, there is an annotated version.