Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 2 of 2
  1. #1
    Member
    Join Date
    Apr 2019
    Location
    Wunstorf, Germany
    Posts
    86

    Using Argon One case with fan and powerbutton together with piCorePlayer?

    Hello!

    This is a new thread for the question how to use the fan and the powerbutton of the Argon One case together with piCorePlayer.
    Let's start at the beginning.

    I want to use a Raspberry Pi 4 as a LMS server with the piCorePlayer installation. This will be no problem.
    I want to place this into this case: https://www.argon40.com/catalog/prod...rry-pi-4-case/
    This case has a software for using the Power-Button together with eg. Raspbian.

    Does anyone know if this software button will also work somehow together with piCorePlayer? So is it possible to switch it off gracefully with the button?
    This case has also been available for older Raspberry Pi.

    The script for the button and the fan can be found here (for Raspbian): https://download.argon40.com/argon1.sh

    First part: "The fan"

    The installation of the script consists of a few different parts.
    First it installs the following packages: "raspi-gpio python-rpi.gpio python3-rpi.gpio python-smbus python3-smbus i2c-tools"
    Then it creates a few files:
    - daemonconfigfile (there are only temperatures and fan speeds in a "table"
    - shutdownscript (this will be called later from the daemon when the button is pressed.
    - powerbuttonscript (this is the script that will later run as a daemon)
    - daemonfanservice (this is the configfile for the service, it is placed at: /lib/systemd/system/$daemonname.service)
    - removescript (to remove the installation)
    - configscript (to configure the reactions to different temperatures, later it will write the daemonconfigfile)
    At the end it starts the service via:
    Code:
    sudo systemctl daemon-reload
    sudo systemctl enable $daemonname.service
    sudo systemctl start $daemonname.service
    This is the part of the daemon for temperature checking and switching the fan to the different speeds:
    Code:
    echo 'def temp_check():' >> $powerbuttonscript
    echo '	fanconfig = ["65=100", "60=55", "55=10"]' >> $powerbuttonscript
    echo '	tmpconfig = load_config("'$daemonconfigfile'")' >> $powerbuttonscript
    echo '	if len(tmpconfig) > 0:' >> $powerbuttonscript
    echo '		fanconfig = tmpconfig' >> $powerbuttonscript
    echo '	address=0x1a' >> $powerbuttonscript
    echo '	prevblock=0' >> $powerbuttonscript
    echo '	while True:' >> $powerbuttonscript
    echo '		temp = os.popen("vcgencmd measure_temp").readline()' >> $powerbuttonscript
    echo '		temp = temp.replace("temp=","")' >> $powerbuttonscript
    echo '		val = float(temp.replace("'"'"'C",""))' >> $powerbuttonscript
    echo '		block = get_fanspeed(val, fanconfig)' >> $powerbuttonscript
    echo '		if block < prevblock:' >> $powerbuttonscript
    echo '			time.sleep(30)' >> $powerbuttonscript
    echo '		prevblock = block' >> $powerbuttonscript
    echo '		try:' >> $powerbuttonscript
    echo '			bus.write_byte(address,block)' >> $powerbuttonscript
    echo '		except IOError:' >> $powerbuttonscript
    echo '			temp=""' >> $powerbuttonscript
    echo '		time.sleep(30)' >> $powerbuttonscript
    They are reading the temperature with "vcgencmd measure_temp" and if it reaches the next step from the config they call this:
    Code:
    bus.write_byte(address,block)
    where address is 0x1a and block is the fanspeed from config.

    I don't know what this bus.write_byte is doing. Maybe it is enough to write this a single time to have the fan running always at the same speed?

    The fan is controlled via I2c as paul has written and bus.write... is for writing to I2c.

    Is it possible to write to I2c with piCorePlayer? So I can write one byte at start to let the fan work in one defined speed.

    Quote Originally Posted by paul- View Post
    Yes you can, we can probably run the scripts(Daemon) that they use. You just can use the installation script.
    Second Part: "The powerbutton"

    Quote Originally Posted by Aldoszx View Post
    I also have this RPi4 case.
    From the script itself, i saw that: 'shutdown_pin=4'.
    I suppose that is the pin used for shutdown command.
    And, it must be pulled down: 'pull_up_down=GPIO.PUD_DOWN'
    So I used this configuration in piCorePlayer:
    Name:  Bildschirmfoto 2020-01-24 um 21.05.05.png
Views: 64
Size:  17.2 KB
    I pressed the button to create the script and it can be found in the filesystem.

    But what happens is that I get the following messages at startup:
    Code:
    Mounting USB Drives...
    Mounting USB Drive: 5D0B-9332...
    FUSE exfat 1.2.7
    WARN: volume was not unmounted cleanly.
    Disk Mounted at /mnt/LMS.
    Mounting USB Drive: 5E28-AD65...
    FUSE exfat 1.2.7
    WARN: volume was not unmounted cleanly.
    Disk Mounted at /mnt/Musikbox.
     Done.
    So the Pi was not correctly shutdown, as the filesystems are not clean.

    Is there any possibility to see if the shutdown script is called when switching off without an attached monitor? E.g. via looking at the logfile via ssh or something like that?

  2. #2
    Senior Member paul-'s Avatar
    Join Date
    Jan 2013
    Posts
    2,536
    First, do not try to run those scripts directly.....remove anything you have tried.

    Lets talk about shutdown first. If you just configure the shutdown tweak the way you did it, does the device shutdown? Did you install the shutdown-monitor extension?
    piCorePlayer a small player for the Raspberry Pi in RAM.
    Homepage: https://www.picoreplayer.org

    Please donate if you like the piCorePlayer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •