Skip to content

A fan control daemon for the Argon ONE case for the Raspberry Pi 4.

License

Notifications You must be signed in to change notification settings

mgdm/argonone-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Argon ONE utils

This repo provides two things:

  • A port of the logic of the Argon ONE fan control daemon script to Go instead of Python.
  • Some systemd and device tree configuration to make the power button shut down the machine cleanly.

This probably won't work for you. I use this on my Raspberry Pi 4B running NixOS. Everything is hard coded to work on that machine with no accounting for other OSes or configurations.

There's no warranty of any kind for this.

I'm using NixOS! How do I set up the fan control daemon?

The Argon ONE's fan is controlled using I2C. On Raspbian, enabling I2C is a simple matter of using raspi-config, which will add a line similar to dtparam=i2c_arm=on to /boot/config.txt, and rebooting. This doesn't work for me on NixOS even using the Raspberry Pi vendor kernel, so I had to work on a device tree overlay to enable it instead. For some reason I think the I2C bus names under NixOS are swapped, so this code works with i2c-1 whereas on Raspbian I believe it would be i2c-0, though I have not tested this.

The overlay looks like nix/hardware/i2c.nix. Copy that somewhere under /etc/nixos and include that in your configuration.nix as follows:

{   
    imports =
    [
        ./hardware-configuration.nix
        ./hardware/i2c.nix
    ];

    # Other settings go here...

    hardware.raspberry-pi."4".i2c.enable = true;
}

(This option name uses the convention of the nixos-hardware overlay, to which I will eventually PR this).

Then to configure the service:

{
#    Import the overlay to provide the argonone-utils package
    nixpkgs.overlays = [ (import ./overlays) ];

    systemd.services.argonone-fancontrold = {
        enable = true;
        wantedBy = [ "default.target" ];

        serviceConfig = {
            DynamicUser = true;
            Group = "i2c";

            ExecStart = "${pkgs.argonone-utils}/bin/argonone-fancontrold";
        };
    };
}

In hardware-configuration.nix, I made the following additions:

{
    boot.initrd.kernelModules = [  "i2c-dev" "i2c-bcm2835"  ];
    boot.kernelModules = [ "i2c-dev" "i2c-bcm2835" ];
    hardware.i2c.enable = true; # This adds the i2c group
}

Hopefully that should be it!

I'm using NixOS! How do I make the power button work?

Most of the functionality for making the power button turn the machine off already exists in the kernel and systemd. There's no need for a script to monitor the GPIOs unless you want to do something different like a quick press for reboot or a long press for shut down. The supplied Argon ONE script monitors the GPIO at 100Hz in order to do this.

I thought about rewriting this like I did with the fan control, but using interrupts, but then I got told by @adventureloop about the gpio-keys kernel module. This needs some device tree overlays to set up on NixOS (again, it's probably simpler on Raspbian), but once the overlay is applied systemd will respond to a double tap on the power button by shutting down. This is only the first step--it doesn't turn off the power to the Pi. However, with a quick systemd one-shot unit, we can poke the right I2C command at the board to make it cut the power just after everything else is shut down.

To use it:

  • include power-button.nix in your configuration
  • add gpio-keys to boot.kernelModules (I will add this to power-button.nix eventually)
  • enable it using hardware.argon-one.power-button.enable = true;

After a rebuild, a double tap the power button should cleanly shut down and turn the machine off.

About

A fan control daemon for the Argon ONE case for the Raspberry Pi 4.

Resources

License

Stars

Watchers

Forks

Packages