ROCK 4A GPIO Issues

In 2021, I bought a ROCK 4A, a Penta SATA Hat, a SATA Hat Top Board, and the metal case that was available at the time that would fit all of these plus four SDDs. Since then, it has been serving as a NAS running OMV on Armbian, with relatively few issues. However, the Top Board has an OLED display and a PWM fan, and for most of the time that I’ve had this device, I have only had one of those two things functioning properly. This has predominantly been the fan, thankfully, but at the moment the display is working and the fan is not.

I’m no stranger to programming, but coding for GPIO is unfamiliar territory for me. I have MRAA installed (after following the instructions here) and its command-line utilities allow me to turn the fan on and off. I have also been able to write programs to turn the fan on and off, but not any that will set intermediate values using PWM. For example, both of these Python scripts run without any errors, but only the first one runs as expected while the second one does not:

First Script

# GPIO Script
import mraa
import time      

pin = 13

gpio = mraa.Gpio(pin)
gpio.dir(mraa.DIR_OUT)

value = 0

while True:
  value = +(not value)
  gpio.write(value)
  print("value: {}".format(value))

  time.sleep(3)

Second Script

# PWM Script
import mraa
import time

pin = 13

gpio = mraa.Pwm(pin, owner=True, chipid=-1)      

gpio.period_us(700)
gpio.enable(True)

value = 0

while True:
  value = +(not value)
  gpio.write(value)
  print("value: {}".format(value))

  time.sleep(3)

I suspect that the issue with the second script is that the “chipid” value needs to be set to a positive value, but I have tried 0, 1, and 2, and they all cause an error, “ValueError: Error initialising PWM on pin”.

In another thread, I saw a suggestion to try the Periphery library with Python instead. I installed that and ran the script below, which resulted in the error “periphery.pwm.PWMError: [Errno 16] Exporting PWM channel: Device or resource busy”:

from periphery import PWM

pwm = PWM(2, 0)

pwm.frequency = 1e3

pwm.duty_cycle = 0.75

pwm.enable()

pwm.close()

I have the “rockpi-penta” package installed (which is why the display works), and I guess that could be what’s causing the contention issue on that pin, but if that’s the case, why isn’t the fan working properly?

The heatsink that the case bottom provides for the CPU is pretty massive, so the CPU temperatures typically stay in the range of 29 to 36 degrees without active cooling, but I just want a contingency in case it happens to get warm in there on a hot day.

Can anyone with appropriate knowledge suggest what they would do in this situation? Thanks!