5

I have a brand new Compute Module 4 with Raspberry Pi OS installed. The system is up-to-date, but I cannot read GPIOs or change their state.

$ gpio -v
gpio version: 2.52
Copyright (c) 2012-2018 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
  Type: (null), Revision: 00, Memory: 4096MB, Maker: Sony
  * Device tree is enabled.
  *--> Raspberry Pi Compute Module 4 Rev 1.0
  * This Raspberry Pi supports user-level GPIO access.

If I try to read all gpios I get this error:

$ gpio readall
Oops - unable to determine board type... model: 20

If I try to change the state of a GPIO it doesn't work

$ gpio mode 13 out
$ gpio write 13 1

However it does work with the following:

echo "13" > /sys/class/gpio/export                    
echo "out" > /sys/class/gpio/gpio13/direction         
echo "1" > /sys/class/gpio/gpio13/value 

What would be the correct way of using GPIOs on the CM4?

2

4 Answers 4

4

"What would be the correct way of using GPIOs on the CM4?"

This is strictly opinion based, and thus off topic.

The strict (Linux kernel purist) answer is to use gpiochip interface. Unfortunately this currently provides limited functionality and is a little tardy.

Linux kernel purists consider ANY method of accessing hardware which bypasses the kernel incorrect.

All of the current Pi libraries directly access hardware for performance/functionality. (Joan's lg library is a possible exception.)
See Controlling Raspberry Pi GPIO with c and Python

As others have pointed out WiringPi is deprecated, and has no support for CM4; support for Pi4 is limited and incomplete.
However if you want a gpio readall equivalent you could try GPIOreadall

3

You would probably be better served by using my lg archive of programs. C and Python are supported.

The archive uses the new /dev/gpiochip interface rather than the deprecated sysfs interface used by wiringPi and RPi.GPIO.

lg also has the advantage of being a generic Linux archive and is not tied to the Raspberry Pi.

2

That gpio utility is part of WiringPi which was deprecated.

There is an unofficial mirror: https://github.com/WiringPi

Are you planning on developing something in a language such as Python or C ?

I use the RPi.GPIO library in Python: https://sourceforge.net/p/raspberry-gpio-python/wiki/BasicUsage/

Another Python library gpiozero simplifies things even more: https://gpiozero.readthedocs.io/en/stable/

1

In my experience (up to & including the buster release), gpio works fine on the RPi 4B if you install the WiringPi 2.52 update after doing the usual WiringPi installation using apt-get.

3
  • WiringPi is obsolete
    – nowox
    Commented Oct 3, 2021 at 15:46
  • @nowox: There are some that would disagree with your opinion.
    – Seamus
    Commented Oct 3, 2021 at 19:40
  • That’s interesting, I’ll check that!
    – nowox
    Commented Oct 3, 2021 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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