Get Informed out of Data

Full width home advertisement

Raspbian

DataScience

Post Page Advertisement [Top]

GPIO command for bash script controlled IO on boot in raspberry pi 4

GPIO command for bash script controlled IO on boot in raspberry pi 4


The latest firmware - includes a new config.txt command for configuring pins at boot time. It can be considered an easier alternative to a custom dt-blob.bin for applications that don't need to reassign the named pins (e.g. "LAN_RUN") or create custom clocks.

GPIO control becomes a vital thing in IoT as often setting the state of I/O on boot ensures the commanding and process continuation.


The command is called "gpio", and the syntax is based on the raspi-gpio utility. Each line applies the same settings (or at least makes the same changes) to a set of pins, either a single pin ('3'), a range ('3-4'), or a comma-separated list of either ('3-4,6,8'). The pins are followed by a '=', then one or more comma-separated attributes from this list:

      ip - Input
      op - Output
      a0-a5 - Alt0-Alt5
      dh - Driving high (for outputs)
      dl - Driving low (for outputs)
      pu - Pull up
      pd - Pull down
      pn/np - No pull
gpio commands are applied in order, so those appearing later override those appearing earlier.

Examples:

      # Select Alt2 for GPIOs 0 to 27 (for DPI24)
      gpio=0-27=a2

      # Set GPIO12 to be an output set to 1
      gpio=12=op,dh

      # Change the pull on (input) pins 18 and 20
      gpio=18,20=pu

      # Make 17 to 21 inputs
      gpio=17-21=ip

Pins configured by this command are not reserved in any way, so they won't stop kernel drivers or the user-space sysfs GPIO interface from claiming and using them.

No comments:

Post a Comment

Bottom Ad [Post Page]