mruby-denko-milkv-duo
June 13, 2025 ยท View on GitHub
The Milk-V Duo is a tiny (same footprint as a Raspberry Pi Pico) single board computer, but with a 1 GHz RISC-V CPU running Buildroot Linux. This project makes it simple to do electronics programming on it in mruby. It implements Denko::Board compatible with the CRuby gem, so all those peripheral drivers/classes can be used as-is, and are included in the the mruby build. About 50 are implemented so far.
Supported Milk-V Boards
- Milk-V Duo 64M
- Milk-V Duo 256M
- Milk-V Duo S
Installation
- Download the appropriate Buildroot Linux image for your board, from the official repo.
- Using balenaEtcher or a similar tool, flash the image to a micro SD card.
- Insert the SD card into your board, and connect it to your computer.
- Download and unzip the mruby binaries for your board, from the releases section of this repo.
- The Milk-V Duo creates a new network interface on your comptuer, so you can SSH/SCP into it.
- Its IP address is
192.168.42.1, default username isroot, and password ismilkv - Copy the binaries onto the board:
# Some older macs may require you omit the -O flag scp -O UNZIPPED_BINARY_FOLDER/* root@192.168.42.1:/usr/local/bin - SSH into the board:
ssh root@192.168.42.1 - Try the
mirbshell, or copy over examples from this folder, and try them withmruby FILENAME.rb - If you have issues with PWM / I2C / SPI, see the Pinmux section below.
Pinmux
Some pins on the Duo can perform multiple functions, but only one at a time (multiplexing).
Default (at Boot) Multiplexing Setup
Notes:
- The Linux boot console uses
UART4by default. - Hardware
SPI2(orSPI3on the Duo S) is the only usable SPI device available. It becomes/dev/spidev0in both cases. When initializingDenko::SPI::Busgive no index at all (default 0), orindex: 0.
Remultiplexing
- View the current multiplexing setup at any time with
duo-pinmux -lor by callingBoard#mapfrom mruby. - Use
duo-pinmuxto remux pins as needed. See official documentation here.
Notes:
- Unlike most Linux systems, remuxing does not require a reboot to take effect.
- However, changes made by
duo-pinmuxare not saved across reboots. - GP26 and GP27 must be muxed to their default GPIO functions for the SARADC (analog input) to work.
Known Issues
Sensor::QMP6988works only onI2C::BitBangbuses, not on hardware I2C.Sensor::RCWL9620does not work at all.
Limitations (relative to CRuby Denko)
- mruby does not have
Thread. Methods like#polland#blinkwill not work, since they cannot start their own threads in the background to update peripheral state, like they do on CRuby. Board#digital_listenis implemented however, but in a C thread that collects pin change events.- It does not use interrupts, but polls, aiming for ~10 kHz.
- Peripherals like
RotaryEncoderwill not be as accurate as they are on denko-piboard. - It still cannot update
DigitalIOinstances and run callbacks in the background. - Do this by calling
Board#handle_listenersperiodically, in your application loop.
Board#analog_listenis not implemented at all, as it would be too slow.Board#spi_listenis not implemented.SPI::InputRegister#listenwill not work.- Milk-V Duo has no on-board digital-to-analog converters (DACs), but the
AnalogIO::Outputclass is included. It should work with external DACs, when support for these is added. - Milk-V Duo has no on-board EEPROM.
EEPROM::Boardis automatically included, but will not work. - UART hardware is available, but mruby support is not implemented yet.
- The
UARTclasses are automatically included in the build, but will not work yet. - Consequently,
Sensor::JSNSR04Talso will not work.
- The
/dev/i2c-0is fixed at 400 kHz and/dev/i2c-1is fixed at 100 kHz. These are reconfigurable, if you build your own Linux image from here.
Build Instructions
- On Ubuntu 24.04:
sudo apt install wget git make gcc - Install Ruby 3.3 or later, from
apt,rbenvor elsewhere. - Clone mruby at this commit or later.
- Clone the Milk-V Duo SDK, so
duo-sdkandmrubyare in the same directory. - Copy the build config from this repo into
mruby/build_config - Edit
MILKV_DUO_VARIANTin the copied file to match your board: 64M, 256M or S. - Modify the build config as neeeded.
- In
mrubyroot:rake MRUBY_CONFIG=build_config/denko_milkv_duo.rb - When completed, the cross-compiled binaries will be in
mruby/build/#{MILKV_DUO_VARIANT}/bin - Folow the install instructions above.