SOFTWARE
2024-01-24 821 View

GPIO Tutorial: Part 1

Node-RED, a powerful flow-based development tool for visual programming, 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 serves as a collection of flows designed to enhance your comprehension of node operations on the KIWIboardS. The GPIO header on the KIWIboards 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


  • 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.

KIWIboard GPIO Output


When GPIO pins are configured as an output on the KIWIboards, 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 GPIO output functionality of the KIWIboards, 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.

  • For configuring and reading the status, use the nodes "Get GPIO Config" and "Get GPIO Mode," the data will be shown in the debug section.

KIWIboard GPIO Input


KIWIboards' GPIO pins configured as inputs are potent tools for interacting with external sensors, buttons, or other digital signals.

To illustrate this, establish a basic setup 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 KIWIboard Solutions?


The versatility of KIWIboards 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 KIWIboards provide a robust foundation for building dynamic and customized applications, making them an ideal choice for a wide range of projects and experiments.

About KIWIboard


KIWIboard 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. KIWIboard 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 KIWIboard expert? Contact us

Want to hear more from KIWIboard?  for our newsletterSign up

Or request a quotation