🛠 Using GPIOs on the KNOT Gateway HL9

MikroTik KNOT Gateway HL9 · debutant · Apprenez à configurer et lire les entrées-sorties GPIO pour connecter des capteurs simples ou des actionneurs.

Objectives

This tutorial guides you through using the General Purpose Input/Output (GPIO) pins on the KNOT Gateway HL9. By the end, you will know how to configure a pin as an input to read a logical state (0 or 1) and as an output to control a simple component. This is the foundation for integrating physical sensors into your IoT gateway.

Required Equipment

Steps

  1. Pin Identification: Although physical pins vary by revision, GPIOs are generally accessible via the RouterOS interface. Connect to the board via SSH or WinBox.
  2. GPIO Interface Configuration: In RouterOS, navigate to Interface > GPIO. If no GPIO interface is visible, create one or ensure the driver is active. Note the desired pin index (e.g., gpio1).
  3. Input Configuration: To read a signal, configure the pin as an input. In the SSH terminal, use the following command to set the direction and enable internal pull-up if available:
/interface gpio set [find name=gpio1] direction=input pull-mode=up
  1. Reading State: Once the sensor is connected (between the pin and GND), check the state in real-time:
/interface gpio print where name=gpio1

The value attribute will display low (0) or high (1).

  1. Output Configuration: To drive an LED, change the direction to output and set the initial state:
/interface gpio set [find name=gpio2] direction=output
/interface gpio set [find name=gpio2] value=high

Verification

Ensure the read value changes when you press the button or trigger the sensor. For output, visually confirm the LED lights up. Use interface gpio monitor to observe changes live.

Further Reading

Explore integration with MQTT to publish GPIO states to a remote broker, or use RouterOS scripts to trigger automatic actions based on state changes.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials