Skip to content

dmtr-makarenko/temp-sensor

Repository files navigation

GitHub Actions Workflow Status GitHub License Version

Temperature Reader

Overview

Temperature Reader is a sample Zephyr application that simulates reading temperatures and provides a basic serial interface for communicating with the device.

Prerequisites

Before you start building and running the application, make sure you have set up your development environment with all the required tools and dependencies for Zephyr. You also need to add nanopb to your workspace.

To add nanopb to your workspace, run these commands:

west config manifest.project-filter -- +nanopb
west update

Build

To build the application for a supported Zephyr board:

Make sure your Zephyr environment is set up correctly. Run this command, replacing <board_name> with your target board (for example, nucleo_f207zg):

west build -b <board_name> path/to/the/repo

Replace path/to/the/repo with the folder where the application is located.

Tip

If you have any issues during the build, please consult with the build workflow for this repo

Usage

The application supports two modes: text mode and binary mode. In text mode, you can interact with the device using simple commands. In binary mode, you use Protocol Buffers for more complex communication.

Text Mode

To use the device in text mode, you need a terminal application like minicom. Follow these steps:

  1. Connect to the device using minicom:
minicom -c on -D /dev/ttyACM0
  1. Use these commands to interact with the device:

    • help: Shows a list of available commands.
    • app read <sensor_id>: Reads data from a sensor.
    • app config : Configures a sensor with specific settings.
    • app enable <sensor_id>: Turns on the specified sensor.
    • app toggle: Switches the device to binary mode.
  2. Follow the instructions on the screen to read and set up sensor data.

Text mode demo

text-mode.mp4

Binary Mode

To use the device in binary mode, you send and receive messages using protobuf. Here’s how:

  1. Use protoc with the message.proto file to encode commands and send them to the device.

  2. Example commands:

  • To read temperature from sensor 0:
echo -e "type: ReadData read_data:{sensor_id: 0}" | protoc --encode=Request message.proto > /dev/ttyACM0
  • To get the response:
dd if=/dev/ttyACM0 bs=1 count=9 status=none | protoc --decode Response message.proto

Important

Please note that due to this approach's limitations, you must know the amount of data to read beforehand (note count=9 above), greatly impacting its usefulness.

Binary mode demo

bin-mode.mp4