GPIO Tutorial: Part1 - IO
Node-RED is a powerful flow-based development tool for visual programming that simplifies the creation of automation tasks and IoT applications. One of its key features is importing and exporting flows using JSON files, allowing users to share and reuse code easily.
GPIO Sample Code
The provided code for KIWI310 is a collection of flows designed to enhance your comprehension of node operations on the KIWI boards. The GPIO header on the KIWI boards boasts 21 HAT Numbers that can be independently configured as output or input. Additionally, the header accommodates one dedicated channel for SPI, one for I2C and two channels to PWM, extending the board's versatility in accommodating various interfacing and control functionalities.
Import Sample Code Steps
- Before proceeding, ensure that Node-RED is installed and running on your system (accompanying posts Linux and Windows). Open your web browser and navigate to the Node-RED dashboard by entering the local host address in the URL bar http://localhost:1880 or http://127.0.0.1:1880
- Click on the three horizontal bars in the upper-right corner to reveal a dropdown menu, and select "Import" to access the import options.
- You'll be prompted to paste the JSON code directly or upload a file in the import dialog. Choose the "Select a file to import" option and find the JSON file previously downloaded from the KIWI310's Node-RED official package.
https://www.npmjs.com/package/node-red-contrib-kiwi310?activeTab=code
- After selecting the JSON file, Node-RED will preview the imported flow on the screen. Click the Deploy button on the upper right-hand side to run the flows.
KIWI board GPIO Output
When GPIO pins are configured as an output on the KIWI boards, they become versatile tools for controlling external devices such as LEDs, motors, or relays.
- For a basic LED demonstration, connect the longer leg (anode) of the LED to a 330ohms resistor to GPIO 26 and the shorter leg (cathode) to the ground (GND) pin. This uncomplicated setup showcases the KIWI boards' GPIO output functionality, illustrating how it can effectively control connected components through its GPIO output capabilities.
On the GPIO flow, verify that the Set GPIO Mode Node designates GPIO 26 as the output. For more information, consult KIWI310's middleware documentation, which is available on Github.
- To implement the sample code for periodically blinking the LED, activate the interval function in the injection node.
- To configure and read the status, use the nodes "Get GPIO Config" and "Get GPIO Mode," and the data will be shown in the debug section.
KIWI board GPIO Input
KIWI boards' GPIO pins configured as inputs are potent tools for interacting with external sensors, buttons, or other digital signals.
To illustrate this, a basic setup is established by connecting one push-button pin to GPIO 16, using a pull-up resistor, and connecting the other pin to the ground (GND). Employing pull-up and pull-down resistor configurations aids in ensuring the logical state of the digital input, as detailed in our accompanying post.
Why KIWI board Solutions?
The versatility of KIWI boards allows developers and enthusiasts to harness a spectrum of functionalities, including GPIO input and output, PWM, I2C, and SPI capabilities. This versatility empowers the creation of responsive and interactive projects that can be precisely tailored to meet specific requirements. Whether reading data from sensors, controlling actuators, or communicating with other devices through advanced protocols, the GPIO features on KIWI boards provide a robust foundation for building dynamic and customized applications, making them an ideal choice for a wide range of projects and experiments.
About KIWI board
KIWI board is a complete solution provider, supporting all aspects of your project, from hardware to software to system integration, to keep your application running securely, reliably, and at peak performance. KIWI board builds its products for high reliability, performance, security, scalability, and versatility. So, customers can expect a long lifespan, quickly adapt to evolving system requirements, and adopt future technologies as they emerge.
Next steps
Ready to talk about your projects with a KIWI board expert? Contact us
Want to hear more from KIWI board? for our newsletterSign up
Or request a quotation