tf
Published © Apache-2.0

{ radar-occupancy-sensor

A simple Matter occupancy sensor based on the nRF5340 DK / nRF7002 DK and the S2GO RADAR BGT60LTR11...

IntermediateFull instructions provided3.14159265359 hours1,159

Things used in this project

Hardware components

nRF5340 Development Kit
Nordic Semiconductor nRF5340 Development Kit
×1
nRF7002 Development Kit
Nordic Semiconductor nRF7002 Development Kit
×1
S2GO RADAR BGT60LTR11
Infineon S2GO RADAR BGT60LTR11
×1
8 Channel Bi-Directional Logic Level Converter Module
A logic level converter module is required for connecting the SGO RADAR BGT60LTR11 sensor to the nRF7002 DK ...
×1
AMS1117 5V to 3.3V Step-Down Regulator Module
Optional: When using a 5V power supply (e.g., via USB) for the nRF7002 DK to provide 3.3V for the SGO RADAR BGT60LTR11 sensor ...
×1
nRF52840 Dongle
Nordic Semiconductor nRF52840 Dongle
Optional: As radio co-processor for testing with OTBR ...
×1
Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
Optional: For testing with OTBR ...
×1
Echo Show (2nd Gen)
Amazon Alexa Echo Show (2nd Gen)
Not required, but used for testing ...
×1

Software apps and online services

nRF Connect SDK
Nordic Semiconductor nRF Connect SDK
VS Code
Microsoft VS Code
CHIP Tool
ZAP tool
OpenThread Border Router
Optional, for testing ...
Amazon Alexa
Not required, just for testing/demonstration ...
Home Assistant
Home Assistant
Optional, for testing ...

Hand tools and fabrication machines

Multimeter &&/|| USB Meter

Story

Read more

Schematics

Wiring (nRF5340 DK)

Wiring (nRF7002 DK)

Code

BGT60.h

C Header File
/*
 * BGT60.h
 *
 * Simple 'driver'/access class for the Infineon BGT60LTR11 Radar Shield2Go
 *    
 * Copyright (c) 2023 dxcfl
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#pragma once

#include <zephyr/kernel.h>

class BGT60
{

public:
    static BGT60 &Instance()
    {
        static BGT60 instance;
        return instance;
    };

    static void Init();
    static bool IsReady();
    static uint64_t GetLastTdTime();
    static bool GetLastPd();
    static bool GetTd();
    static bool GetPd();
};

BGT60.cpp

C/C++
/*
 * BGT60.cpp
 *
 * Simple 'driver'/access class for the Infineon BGT60LTR11 Radar Shield2Go
 *    
 * Copyright (c) 2023 dxcfl
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>

#include "BGT60.h"

#define TD_NODE DT_ALIAS(targetd)
#define PD_NODE DT_ALIAS(phased)
static const struct gpio_dt_spec td = GPIO_DT_SPEC_GET(TD_NODE, gpios);
static const struct gpio_dt_spec pd = GPIO_DT_SPEC_GET(PD_NODE, gpios);

static bool ready = false;
static uint64_t last_td_time = 0;
static bool last_pd = false;

static struct gpio_callback td_cb_data;

void td_activated(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
    uint64_t now = k_uptime_get();
    bool pd_pin = gpio_pin_get_dt(&pd);
    last_td_time = now;
    last_pd = pd_pin;
}

void BGT60::Init()
{
    int ret;
    
    printk("BGT60: Init ...\n\r");

    if (!device_is_ready(td.port))
    {
        printk("BGT60: Target detection port (TD) not available ...\n\r");
        return;
    }

    if (!device_is_ready(pd.port))
    {
        printk("BGT60: Phase detection port (PD) not available ...\n\r");
        return;
    }

    ret = gpio_pin_configure_dt(&td, GPIO_INPUT);
    if (ret < 0)
    {
        printk("BGT60: Target detection port (TD) not available for input ...\n\r");
        return;
    }

    ret = gpio_pin_configure_dt(&pd, GPIO_INPUT);
    if (ret < 0)
    {
        printk("BGT60: Phase detection port (PD) not available for input ...\n\r");
        return;
    }

    ret = gpio_pin_interrupt_configure_dt(&td, GPIO_INT_EDGE_TO_ACTIVE);
    if (ret < 0)
    {
        printk("BGT60: Could not configure ISR for TD ...\n\r");
        return;
    }

    gpio_init_callback(&td_cb_data, td_activated, BIT(td.pin));
    gpio_add_callback(td.port, &td_cb_data);

    ready = true;
}

bool BGT60::IsReady()
{
    return ready;
}

uint64_t BGT60::GetLastTdTime()
{
    return last_td_time;
}

bool BGT60::GetLastPd()
{
    return last_pd;
}

bool BGT60::GetTd() {
    return gpio_pin_get_dt(&td);
}

bool BGT60::GetPd() {
    return gpio_pin_get_dt(&pd);
}

Github

Credits

tf

tf

15 projects • 3 followers

Comments