"GPIO" (General Purpose I/O)
"GPIO" provides low-level general-purpose input and output through digital pins directly connected to the processor running the Wolfram Language.
Note: By default, "GPIO" allows any pin to be used interchangeably in read and write mode. DeviceConfigure can be used to configure specific pins as read or write.
Device Discovery

- FindDevices["GPIO"] gives a GPIO DeviceObject if GPIO is available on your computer system.
Opening the Device

- If GPIO is present, it is always accessible and does not require a connection step.
- DeviceOpen["GPIO"] is not required, but can be used to obtain a DeviceObject whose properties can be queried.
Configuring the Device

- Configuration is not required for GPIO. Without configuration, any pin will automatically switch between input and output on read and write. Note that if a pin is used in a direction that is not intended, this may damage your system.
- Possible directions are "Input", "Output", and None.
- Setting the direction to None releases a pin if it has previously been configured.
- DeviceConfigure ignores requests to configure any pin that is being accessed by an asynchronous task.
- If an attempt is made to use a GPIO pin in a direction inconsistent with its configuration, an error will be generated.
DeviceConfigure["GPIO",n->dir]
sets the direction of pin n to be dir.
DeviceConfigure["GPIO",{n1->dir1,n2->dir2,…}]
sets direction diri for pin pini.
Reading Data

- The value of a GPIO pin is always either 0 or 1.
-
Note By default, "GPIO" allows any pin to be used interchangeably in read and write mode. DeviceConfigure can be used to configure specific pins as read or write.
DeviceRead["GPIO",p]
gives the value of GPIO pin p.
DeviceRead["GPIO",{p1,p2,…}]
gives a list of the values of GPIO pins pi.
Writing Data

- The value v must be either 0 or 1.
-
Note By default, "GPIO" allows any pin to be used interchangeably in read and write mode. DeviceConfigure can be used to configure specific pins as read or write.
DeviceWrite["GPIO",p->v]
writes the value v to GPIO pin p.
Closing and Releasing Resources

- DeviceClose["GPIO"] is not required, but can effectively be used to reset all pins to their default state and marks the corresponding DeviceObject as closed.