I use gpio #32 (wPi #26) as PWM output to control the speed of a fan based on temperature. The job starts at system startup with a dedicated account.

I would like to display the current value that is set with gpio command on a dashboard using a different account (eg when gpio pwm 26 50 is issued then I am interested in the 50), but I cannot not find any way to read the current PWM configuration and values. For example, $ gpio readall does not tell me the duty cycle et cetera, just tells me the below snapshot that is meaningless in my use case.

 +-----+-----+---------+------+---+-Pi ZeroW-+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
                                        | 32 | 1 | ALT0 | GPIO.26 | 26  | 12  |

How can I read the current PWM output values of wPi #26 from the cli?

  • You can't. May we know why you don't store the value when you set it? – joan Dec 12 '20 at 18:25
  • @joan I did not store it because the common sense dictates not to store something that you can access anytime as writing the sd card regularly shortens its life. But if it cannot be read then I guess I will have no other option but to write it somewhere so that other accounts may access it based on need. – ben Dec 12 '20 at 18:53
  • If you are that concerned about SD card writes perhaps store in a temporary RAM file system. – joan Dec 12 '20 at 19:00
  • That is done already. I just didn't find that too elegant and rather seemed to be like a workaround to me. – ben Dec 12 '20 at 19:05
  • I've added how that can be done but if someone finds another way to read this data would be great. – ben Dec 13 '20 at 21:05

A potential solution is to store the values in a RAM filesystem and write the values into a file on the ramdisk when PWM output changes.

Job to create the filesystem:

Description=Creates a small ramdisk that can be used to share data between accounts
After=syslog.target network.target








[ -d $TARGET ] || mkdir $TARGET

mount -t tmpfs -o size=$SIZE myramdisk $TARGET

Then this small one-liner in your other shell scripts, where you want to write to the ramdisk from, will ensure the things are written to the ramdisk and never gets written to the SD card in case the ramdisk creation fails

[ ! -z "$(df /ramdisk/ | grep myramdisk)" ] || exit -1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.