Getting Started with Bash Commands Using BEVRLink 4/8-Channel Relay Hat for Raspberry Pi

Getting Started with Bash Commands Using BEVRLink 4/8-Channel Relay Hat for Raspberry Pi

If you’re looking to control devices with your Raspberry Pi inside bash or with scripts using the BEVRLink 4/8-Channel Relay Hat, you can use the pinctrl tool to interact with GPIO pins effectively.

For this we have connected a Raspberry Pi 5 to the BEVRLink Raspberry Pi 5 8 Channel Relay 12V. With this relay module board you need the BEVRLink Power Supply 12V 2A

This guide works for BEVRLink Raspberry Pi 5 4 Channel Relay, just omit the relay 5-8 and the status LED from the code. With this relay module you can either power the Raspberry Pi directly or back feed it from a connected BEVRLink relay module through the Expansion Connector.

Optional for a safe setup we recommend to use case for both the manager and relay boards: BEVRLink Cases

What You Will Need

  • Raspberry Pi (any model with GPIO pins)
  • BEVRLink 4/8-Channel Relay HAT
  • MicroSD card (16GB or larger) with Raspberry Pi OS installed
  • Power supply for the Raspberry Pi
  • Internet connection

Pinout for BEVRLink Relay Hat

Relay Channel RPI Pin Number BCM Pin Description
Channel 1 29 5 4 & 8 ch HAT
Channel 2 31 6 4 & 8 ch HAT
Channel 3 33 13 4 & 8 ch HAT
Channel 4 36 16 4 & 8 ch HAT
Channel 5 35 19 8 ch HAT
Channel 6 38 20 8 ch HAT
Channel 7 40 21 8 ch HAT
Channel 8 37 26 8 ch HAT
Status LED 32 12 Status LED

Controlling Relays with pinctrl

Example: Controlling Relay Channel 1 (BCM Pin 5)

  1. Configure Pin as Output:

    pinctrl 5 op
    
  2. Turn on the Relay (Set High):

    pinctrl 5 dh
    
  3. Turn off the Relay (Set Low):

    pinctrl 5 dl
    

Example: Controlling Status LED (BCM Pin 12)

  1. Configure Pin as Output:

    pinctrl 12 op
    
  2. Turn on the Status LED (Set High):

    pinctrl 12 dh
    
  3. Turn off the Status LED (Set Low):

    pinctrl 12 dl
    

Example: Controlling multiple outputs

  1. Configure Pins as Outputs:

    pinctrl 5,6,13,16,19,20,21,26,12 op
    
  2. Turn on the Pins (Set High):

    pinctrl 5,6,13,16,19,20,21,26,12 dh
    
  3. Turn off the Pins (Set Low):

    pinctrl 5,6,13,16,19,20,21,26,12 dl
    

Conclusion

Using pinctrl, you can effectively control the relays and status LED of the BEVRLink 4/8-Channel Relay Hat directly from your Raspberry Pi using Bash commands. This method provides direct interaction with GPIO pins, ensuring reliable and straightforward control for your projects.

Experiment with different setups and enjoy the flexibility this powerful combination offers!


This guide integrates the use of pinctrl for GPIO control on the Raspberry Pi, specifically tailored to your needs with the BEVRLink Relay Hat. If you have any further questions or need more assistance, feel free to ask!