Skip to content

denko-rb/mruby-milkv-duo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mruby-milkv-duo

This mruby gem provides GPIO, ADC, PWM, I2C and SPI functionality for the Milk-V Duo series of single board computers. It depends on the wiringX C library included in the Milk-V SDK, as well as some Linux /dev and /sys access.

The interface and feature set aim to match the lgpio CRuby gem. This gem is primarily meant as a hardware abstraction layer for a future mruby port of denko.

Milk-V mruby GPIO demo

Features

Duo Class Methods

  • GPIO Mode/Read/Write
  • GPIO Input Alerts
    • Alerts are generated by a separate thread, and can be read from a queue in mruby
    • Does not use interrupts. Polls pins every ~100 microseconds instead
  • Hardware PWM Output
  • SARADC (Analog) Input
    • On GPIO 26 and 27 only
    • Always 12-bit resolution (0-4095 range)
    • Full scale voltage is only 1.8V, not 3.3V.
  • Hardware I2C
  • Hardware SPI
    • Only default SPI mode for now (should be SPI mode 0)
  • Ultrasonic Read (HC-SR04)
  • Pulse Sequence Read (DHT enviro sensors)
  • Bit Bang I2C
  • Bit Bang SPI
    • SPI modes 0 through 3 supported
    • Optional LSBFIRST or MSBFIRST transfers
  • Bit Bang 1-Wire
  • WS2812 addressable LEDs over Hardware SPI
    • Only outputs on SPI2 MOSI pin
    • SPI clock must be set to 2.4 MHz
  • On-off Keying (OOK) Modulated Waves (based on Hardware PWM)
    • Carrier generated by hardware PWM. Software modulated with monotonic clock timing.

Classes

  • Duo::HardwarePWM (convenience wrapper for PWM methods)
  • Duo::PositionalServo (based on Hardware PWM)
  • Duo::Infrared (based on OOK waves)
    • Default frequency: 38 kHz. Default duty cycle: 33.33%

Pinmux

  • Some features of the Duo are multiplexed onto the same pins.
  • Use duo-pinmux to set them up BEFORE using them. See official docs for more info.
  • Run mruby pinmux_custom.rb, from the examples folder, to get the pinmux layout used in all examples.

Install Instructions

  • Download the Linux image for your board, from the official repo.
  • Using balenaEtcher or similar, flash the image to a micro SD card.
  • Insert the SD card into your Duo 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 should have created a network interface on your computer, so you can SSH/SCP into it. The default username is root and password is milkv.
  • Copy the binaries onto the board:
    # Linux
    scp -O UNZIPPED_BINARY_FOLDER/* [email protected]:/usr/local/bin
    # Mac
    scp UNZIPPED_BINARY_FOLDER/* [email protected]:/usr/local/bin
  • SSH into the board with ssh [email protected].
  • Try the mirb shell, or copy over examples from this folder, and try them with mruby FILENAME.rb.
  • If you have issues with the examples (specifically PWM), make sure to read the pinmux section above.

Build Instructions

  • Unless running Ubuntu, set up a virtual machine with Ubuntu 24.04, then install:
sudo apt install wget git make gcc
  • Clone mruby and duo-sdk, then enter the mruby directory:
git clone https://github.com/mruby/mruby
git clone https://github.com/milkv-duo/duo-sdk
cd mruby
  • In mruby/build_config/milkv_duo.rb:

    • Set MILKV_DUO_VARIANT to the string that matches your board
    • Uncomment conf.gem :github => 'denko-rb/mruby-milkv-duo' (last line), to enable this gem
  • Cross-compile mruby with: rake MRUBY_CONFIG=build_config/milkv_duo.rb.

  • The binaries will be in build/milv_duo/bin/, relative to the mruby top-level directory.

  • Follow the install instructions above to copy them to the board.