maxinbjohn / zephyrproject-rtos-relay

Relay module support in zephyr

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.. zephyr:code-sample:: relay
   :name: Relay
   :relevant-api: gpio_interface

   Control a Relay using the GPIO API.

Overview

A relay is an electromagnetic switch operated by a relatively small electric current that can turn on or off a much larger electric current.

This Relay sample turns a relay on and off forever using the :ref:`GPIO API <gpio_api>`.

The source code shows how to:

  1. Get a pin specification from the :ref:`devicetree <dt-guide>` as a :c:struct:`gpio_dt_spec`
  2. Configure the GPIO pin as an output
  3. Toggle the pin forever

Requirements

Your board must:

  1. Have a Relay connected via a GPIO pin

Building and Running

Build and flash Relay as follows, changing longan_nano for your board:

.. zephyr-app-commands::
   :zephyr-app: samples/basic/relay
   :board: longan_nano
   :goals: build flash
   :compact:

After flashing, the Relay will switch on and off in 5 seconds. If a runtime error occurs, the sample exits without printing to the console.

About

Relay module support in zephyr

License:Apache License 2.0


Languages

Language:C 78.2%Language:CMake 21.8%