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:
This is the part of the daemon for temperature checking and switching the fan to the different speeds:Code:sudo systemctl daemon-reload sudo systemctl enable $daemonname.service sudo systemctl start $daemonname.service
They are reading the temperature with "vcgencmd measure_temp" and if it reaches the next step from the config they call this: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
where address is 0x1a and block is the fanspeed from config.Code:bus.write_byte(address,block)
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.
Second Part: "The powerbutton"
So I used this configuration in piCorePlayer:
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:
So the Pi was not correctly shutdown, as the filesystems are not clean.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.
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?
Results 1 to 10 of 48
-
2020-01-24, 13:11 #1
Using Argon One case with fan and powerbutton together with piCorePlayer?
-
2020-01-24, 14:07 #2
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
-
2020-01-25, 00:18 #3
I did not run those scripts, I only tried to understand how they work.
Yes, the Pi is shutting down and yes I installed the shutdown monitor.
-
2020-01-25, 05:52 #4
Then shutdown is working. I’ll check out the fan speed dependencies, they should all be availiable.
As for the disk mount errors, the dirty bit is set, it could have come from anywhere. It’s mostly harmless, how many times do you Just pull the stick from your Mac, vs ejecting it?
You’ll have to scan/fix them. Probably easier for you to do it on your Mac.piCorePlayer a small player for the Raspberry Pi in RAM.
Homepage: https://www.picoreplayer.org
Please donate if you like the piCorePlayer
-
2020-01-25, 06:26 #5
-
2020-01-25, 10:28 #6
First, remove the shutdown monitor and don't use that on the tweaks page....this script will do all of it a different way.
I have uploaded the dependencies to our repo
smbus-python3.6.tcz
RPi-GPIO-python3.6.tcz
Install them from the extensions web page.
This is the actual script, save it to your home directory as /home/tc/argononed.py
Then put in the user commands on the pcp tweaks page.
python3 /home/tc/argononed.py
Code:#!/usr/bin/python import smbus import RPi.GPIO as GPIO import os import time from threading import Thread rev = GPIO.RPI_REVISION if rev == 2 or rev == 3: bus = smbus.SMBus(1) else: bus = smbus.SMBus(0) GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) shutdown_pin=4 GPIO.setup(shutdown_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) def shutdown_check(): while True: pulsetime = 1 GPIO.wait_for_edge(shutdown_pin, GPIO.RISING) time.sleep(0.01) while GPIO.input(shutdown_pin) == GPIO.HIGH: time.sleep(0.01) pulsetime += 1 if pulsetime >=2 and pulsetime <=3: os.system("pcp rb") elif pulsetime >=4 and pulsetime <=5: os.system("pcp sd") def get_fanspeed(tempval, configlist): for curconfig in configlist: curpair = curconfig.split("=") tempcfg = float(curpair[0]) fancfg = int(float(curpair[1])) if tempval >= tempcfg: return fancfg return 0 def load_config(fname): newconfig = [] try: with open(fname, "r") as fp: for curline in fp: if not curline: continue tmpline = curline.strip() if not tmpline: continue if tmpline[0] == "#": continue tmppair = tmpline.split("=") if len(tmppair) != 2: continue tempval = 0 fanval = 0 try: tempval = float(tmppair[0]) if tempval < 0 or tempval > 100: continue except: continue try: fanval = int(float(tmppair[1])) if fanval < 0 or fanval > 100: continue except: continue newconfig.append( "{:5.1f}={}".format(tempval,fanval)) if len(newconfig) > 0: newconfig.sort(reverse=True) except: return [] return newconfig def temp_check(): fanconfig = ["65=100", "60=55", "55=10"] tmpconfig = load_config("etc/argononed.conf") if len(tmpconfig) > 0: fanconfig = tmpconfig address=0x1a prevblock=0 while True: temp = os.popen("vcgencmd measure_temp").readline() temp = temp.replace("temp=","") val = float(temp.replace("'C","")) block = get_fanspeed(val, fanconfig) if block < prevblock: time.sleep(30) prevblock = block try: bus.write_byte(address,block) except IOError: temp="" time.sleep(30) try: t1 = Thread(target = shutdown_check) t2 = Thread(target = temp_check) t1.start() t2.start() except: t1.stop() t2.stop() GPIO.cleanup()
piCorePlayer a small player for the Raspberry Pi in RAM.
Homepage: https://www.picoreplayer.org
Please donate if you like the piCorePlayer
-
2020-01-25, 14:06 #7
-
2020-01-25, 14:11 #8
- Join Date
- Jan 2020
- Posts
- 15
Thanks Paul for the script.
The shutdown works.
Unfortunately, the fan does not start.
I have changed the temperature threshold but no luck.
Maybe I am doing something wrong or something is missing.
Trying to run "python3 /home/tc/argononed.py" from ssh got me this:
tc@piCoreTone:~$ python3 /home/tc/argononed.py
Traceback (most recent call last):
File "/home/tc/argononed.py", line 9, in <module>
bus = smbus.SMBus(1)
FileNotFoundError: [Errno 2] No such file or directoryLast edited by Aldoszx; 2020-01-25 at 14:30.
-
2020-01-25, 14:36 #9
[QUOTE=Aldoszx;962149]Trying to run "python3 /home/tc/argononed.py" from ssh got me this:[QUOTE]
That is the same as I got. I have a Pi 4, so normally I would think that the line:
bus = smbus.SMBus(0)
would be called.
I tested: "python3 smbus" an got the same errormessage. So I think smbus is missing.
Originally there were three dependencies with smbus: "python-smbus python3-smbus i2c-tools". Is this now all in "smbus-python3.6.tcz"?
I found nearly the same error here: https://github.com/johnbryanmoore/VL...thon/issues/13
Do we also have to enable I2c?Last edited by carsten_h; 2020-01-25 at 14:45.
-
2020-01-25, 15:00 #10
- Join Date
- Jan 2020
- Posts
- 15
I think i2c-tools is missing !