Running Adafruit BBIO PWM as non-root user on BeagleBone Black (workaround)

This post describes a workaround to an issue in Adafruit BeagleBone IO library where non-root user cannot start PWM on BeagleBone Black.

Problem with a Sysfs File

Consider below simple PWM code with Adafruit BBIO Python library in Ubuntu 16.04 (kernel 4.4).

On some BeagleBone images, above code – PWM.start() line – throws an error. However, same script executes fine sudo.

Obviously, this post is not relevant to you if above error is not encountered. Latest BeagleBone images may have a proper fix.

The Reason

PWM.start() method tries to access corresponding device file period (and others) when setting up PWM. The device files like period, duty_cycle and polarity are visible only when pwm is setup. This is done by writing 1 (pwm1) or 0 (pwm0) to /sys/devices/platform/ocp/*.epwmss/*.pwm/pwm/pwmchip*/export.

However, when pwm1/0 and device files created under it are owned by user root and group root. So a non-root user do not have permissions to write to the device files. This is a bug, that may have got fixed in latest BeagleBone images.

The Workaround

Udev rules allow non-root users to access PWM devices if that user is part of pwm unix group. Check that by typing groups command on your BeagleBone terminal.

As you might have guessed, for all PWM device files, the trick is to change the group from root to pwm and let all user of group pwm have write permissions. Once this is done, you will be able to do execute PWM Python scripts without the need for sudo.

Below is my script that changes group for all PWM devices on BeagleBone Black. Remember to execute this script with sudo – for one last time!


Adafruit BBIO Issue #168

Robotics & AI Enthusiast

Leave a reply:

Your email address will not be published.