🛠 Using GPIOs on the KNOT Gateway HL9
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
- A powered KNOT Gateway HL9 (PoE or DC 12-57V).
- SSH access to the board (via RouterOS v7 interface).
- A simple push-button or digital sensor (e.g., motion detector).
- A pull-up resistor (10 kΩ) if your sensor lacks one.
- Connection wires (dupont).
Steps
- Pin Identification: Although physical pins vary by revision, GPIOs are generally accessible via the RouterOS interface. Connect to the board via SSH or WinBox.
- 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). - 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
- 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).
- 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
gnss-position-tracking.pyPython-Bashble-advertising-sensor.inoRouterOS-Scriptlte-failover-monitor.pyPython-Bashnand-storage-cleanup.pyPython-Bashpoe-power-status.inoRouterOS-Scriptrouteros-mqtt-telemetry.inoRouterOS Script