Youtube tutorial (one of many). This shows how to
uses sysfs GPIO in the shell. Note that we are writing a
Python program, though.
Distilled, what we want to do (in Python) is this …
$ cd/sys/class/gpio
$ echo25>export$ catgpio25/direction
in$ echoout>gpio25/direction
$ catgpio25/value
0$ echo1>gpio25/value# see if it works$ # now for real$ i=0$ whiletrue;do> echo $((i%2)) > gpio25/value> i=$((i+1))> sleep 0.5> done
The new kid, libgpiod
solves many of the problems that Sysfs GPIO has. Will switch to that
when time is right (after we learned what encapsulation is).
After exporting the GPIO (echo25>export), the directory
gpio25 and the files it contains are not immediately
visible. Rather, the operation completes asynchronously. This
means that you have to wait between the export and the
access. 1/10 second should be sufficient.
You do this using time.sleep(). Read the documentation of it.
A starting point, regarding the “Use argparse for commandline
parsing” can be found here.
Write the program locally, on your PC, using VS Code (or whatever is
your favorite editor).
WinSCP. You can use WinSCP to transfer the program
to the Raspberry. Be aware though that the execute permission
might not be transferred correctly - Windows and Unix are
different.
VS Code, There is also a VS Code extension, Remote SSH, that you might
want to try.