ke5fuj
Posts: 3
Joined: Thu Sep 19, 2019 8:09 pm

Beginner Pi4 GPIO CLI Control

Thu Sep 19, 2019 8:22 pm

Hello Community! I am brand new to the Pi world and wanted to see what these things can do. I have my Pi4 setup running the latest version of Raspbian and can SSH to it and everything. I found a tutorial on Youtube that talks about how to use the CLI to issue simple commands to set and test the GPIO pins to turn on an LED. Well I can't get it to work. So I switched to a multimeter and tried it directly on the pins and still can not see the change of state on the pins using the CLI to issue simple commands like this...

gpio -g mode 18 output
gpio -g blink 18
or
gpio -g write 18 1 (to turn it on)
gpio -g write 18 0 (to turn it off)

Here is what I have done so far....

git clone git://git.drogon.net/wiringPi

This does not work for somer reason... I get this... response

fatal: unable to connect to git.drogon.net:
git.drogon.net[0: 188.246.205.22]: errno=Connection refused
git.drogon.net[1: 2a03:9800:10:7b::2]: errno=Network is unreachable

before anyone asks, yes I can get to the internet with the Pi4 and it is unrestricted access. I'm a network engineer, so I promise its not the network. :)

What I did find was that the "GPIO" commands were already in the OS. So I did this....

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

Raspberry Pi Details:
Type: Unknown17, Revision: 01, Memory: 0MB, Maker: Sony
* Device tree is enabled.
*--> Raspberry Pi 4 Model B Rev 1.1
* This Raspberry Pi supports user-level GPIO access.

From what little I've found about this, the "unknown17" seems to be a problem.

Some more googling and I've tried this....

wget unicorn.drogon.net/wiringpi-2.48-1.deb

And got this....

Resolving unicorn.drogon.net (unicorn.drogon.net)... 46.43.1.171, 2001:41c9:1:41e::171
Connecting to unicorn.drogon.net (unicorn.drogon.net)|46.43.1.171|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 52740 (52K) [application/x-debian-package]
Saving to: ‘wiringpi-2.48-1.deb’

wiringpi-2.48-1.deb 100%[==================================>] 51.50K 193KB/s in 0.3s

2019-09-19 15:01:29 (193 KB/s) - ‘wiringpi-2.48-1.deb’ saved [52740/52740]

So that's about where I'm at for now. I'm just looking to control the outputs from the CLI for now to make sure I am comfortable doing it, and then I will start learning how to use the inputs to monitor one-wire temperature sensors next.

Any help would be greatly appreciated!

User avatar
neilgl
Posts: 1573
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Beginner Pi4 GPIO CLI Control

Thu Sep 19, 2019 9:37 pm

Ah wiringpi is excellent (thanks Gordon) but he has stopped supporting it (sorry) so this might work for GPIO2:

Code: Select all

raspi-GPIO set 2 op on dl
And see this for the various parameters
https://www.raspberrypi.org/documentati ... xt/gpio.md

ke5fuj
Posts: 3
Joined: Thu Sep 19, 2019 8:09 pm

Re: Beginner Pi4 GPIO CLI Control

Thu Sep 19, 2019 11:59 pm

Thanks for the reply Neilgl. Unfortunately, it does not like the "set" command. Take a look....

[email protected]:/home/pi# gpio -h
gpio: Usage: gpio -v
gpio -h
gpio [-g|-1] ...
gpio [-d] ...
[-x extension:params] [[ -x ...]] ...
gpio [-p] <read/write/wb> ...
gpio <mode/read/write/aread/awritewb/pwm/pwmTone/clock> ...
gpio <toggle/blink> <pin>
gpio readall
gpio unexportall/exports
gpio export/edge/unexport ...
gpio wfi <pin> <mode>
gpio drive <group> <value>
gpio pwm-bal/pwm-ms
gpio pwmr <range>
gpio pwmc <divider>
gpio load spi/i2c
gpio unload spi/i2c
gpio i2cd/i2cdetect
gpio rbx/rbd
gpio wb <value>
gpio usbp high/low
gpio gbr <channel>
gpio gbw <channel> <value>

[email protected]:/home/pi# gpio set 18 op on dl
gpio: Unknown command: set.

UPDATE:

So I just found this posting and these commands make the IO change state and you can monitor the state of the IO. Is this just a different way to do it? Right, wrong, etc?

https://raspberry-projects.com/pi/comma ... mmand-line

User avatar
rpdom
Posts: 16306
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Beginner Pi4 GPIO CLI Control

Fri Sep 20, 2019 6:50 am

ke5fuj wrote:
Thu Sep 19, 2019 11:59 pm
So I just found this posting and these commands make the IO change state and you can monitor the state of the IO. Is this just a different way to do it? Right, wrong, etc?
Using the sysfs interface is just another way to do it. The gpio commands can be more friendly though.
Thanks for the reply Neilgl. Unfortunately, it does not like the "set" command. Take a look....

[email protected]:/home/pi# gpio -h
neilgl said to use the raspi-gpio command, not the gpio command. If it isn't installed you can get it with sudo apt update && sudo apt install raspi-gpio

However, I believe
neilgl wrote:

Code: Select all

raspi-GPIO set 2 op on dl
should have been

Code: Select all

raspi-gpio set 2 op np dl

Code: Select all

raspi-gpio help
shows available options.

User avatar
neilgl
Posts: 1573
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Beginner Pi4 GPIO CLI Control

Fri Sep 20, 2019 9:25 am

Yes it should have been raspi-gpio. The iPad auto corrected it...
And a different GPIO number would be better than 2 due to its 1.8k pull-up resistor.

ke5fuj
Posts: 3
Joined: Thu Sep 19, 2019 8:09 pm

Re: Beginner Pi4 GPIO CLI Control

Fri Sep 20, 2019 1:40 pm

Thanks guys!

I did say I was a beginner.... :lol:

I thought the raspi in raspi-gpio was part of the command line label on his machine. Like "[email protected]:~#" Doh! ;)

So I found that this worked.

raspi-gpio set 24 op pn dl
raspi-gpio set 24 op pn dh

Now I just have to figure out how to write python and control it from a web page and with automation.... This is going to be a fun process for sure...

Return to “Beginners”