吴忠躺衫网络科技有限公司

電子發(fā)燒友App

硬聲App

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示
創(chuàng)作
電子發(fā)燒友網(wǎng)>電子資料下載>電子資料>用于Arduino的BGT60雷達傳感器

用于Arduino的BGT60雷達傳感器

2022-10-26 | zip | 0.02 MB | 次下載 | 免費

資料介紹

描述

在本教程結束時,您將能夠檢測運動及其方向,并根據(jù)檢測到的運動觸發(fā)中斷。

BGT60LTR11AIP 防護罩

我們的防護罩使用 60GHz 雷達技術來檢測 7m 范圍內的運動及其方向。它提供僅 20x6.25mm 的小尺寸和低功耗,為許多應用創(chuàng)造了創(chuàng)新、直觀的傳感功能。小型運動傳感器集成天線并在內部處理原始雷達信號,無需任何外部微控制器即可操作設備。

pYYBAGNX-4qAMWG-AADDij3Ub4o746.png
雷達 BGT60 引腳分配
?

僅使用四個引腳就可以非常輕松地與防護罩連接:

  • 接地
  • 輸入電壓 (1.5V - 5V)
  • P out (= 運動方向)
  • T out (= 運動檢測)

帶有 GND 和 Vin(1.5V 至 5V)的電源可以連接到微控制器引腳 Vcc 和 GND。相位檢測輸出 (P out) 引腳表示方向,而目標檢測輸出 (T out) 引腳表示雷達傳感器檢測到的運動。BGT60 可以輕松插入 Arduino MKR1000 板的接頭(Vcc、GND、T out - A1 和 P out - A2)

?

用于 Arduino 的英飛凌 60GHz 庫

我們?yōu)?60GHz 雷達屏蔽開發(fā)的庫稱為“radar-bgt60”。使用 Arduino IDE,通過 Sketch -> Include library -> Library Manager 安裝 Radar 庫。雷達庫包括八個基本 API 函數(shù),我們稍后會在各種示例中使用它們。

  • Bgt60() - Arduino Bgt60 對象的構造函數(shù)
  • ~Bgt60() - Arduino Bgt60 對象的析構函數(shù)
  • init() - 初始化 Bgt60 類對象
  • deinit() - 取消初始化 Bgt60 類對象
  • getMotion() - 讀出目標檢測引腳
  • getDirection() - 讀出相位檢測引腳
  • enableInterrupt() - 啟用硬件中斷
  • disableInterrupt() - 禁用硬件中斷

在我們的Arduino API 描述中找到更多詳細信息

要將草圖上傳到您的板上,您必須先選擇所需的平臺。在此示例中,我們使用 Arduino MKR1000 板。轉到工具 -> 董事會 -> 董事會經理。在那里你搜索你的“Arduino MKR1000”,你會找到需要安裝的包“Arduino SAMD Boards”。

poYBAGNX-5CAb4z7AABrXgGLvb8234.png
?

為了現(xiàn)在上傳草圖,您還必須選擇正確的 COM 端口有一個非常簡單的方法可以做到這一點。拔下連接的 Arduino,然后檢查Tool -> Port下可用的 COM-Ports 現(xiàn)在連接您的 Arduino 并再次檢查端口。現(xiàn)在你應該看到一個新的,以前沒有的。這是正確的,請選擇它。

運動

在第一個簡單示例中,我們想使用 getMotion() 函數(shù)來識別傳感器環(huán)境中的運動。從文件 -> 示例 -> 雷達-bgt60 -> 運動檢測中獲取代碼。

/*!
 * \name        motionDetection
 * \author      Infineon Technologies AG
 * \copyright   2021 Infineon Technologies AG
 * \brief       This example detects the motion of an object
 * \details     This example demonstrates how to detect a moving object while the
 *              BGT60LTR11AIP shield is connected to Arduino compatible
 *              boards using polling method.
 *
 *              Connection details:
 *              --------------------------------------------------
 *              Pin on shield   Connected to pin on Arduino
 *              --------------------------------------------------
 *              TD                  depends on Arduino board
 *              PD                  depends on Arduino board
 *              GND                 GND
 *              Vin                 VCC (3.3V or 5V - depends on Arduino board)
 *              --------------------------------------------------
 *
 *              Decoding on-board LED output of BGT60LTR11AIP shield:
 * 
 *              - Red LED indicates the output of direction of motion once target is detected (PD)
 *              ---------------------------------------------
 *              LED    State    Output explanation
 *              ---------------------------------------------
 *              Red     ON       Departing target
 *                      OFF      Approaching target
 *              ---------------------------------------------
 *
 *              - Green LED indicates the output of target in motion detection (TD)
 *              ---------------------------------------------
 *              LED    State    Output explanation
 *              ---------------------------------------------
 *              Green    ON       Moving target detected
 *                       OFF      No target detected
 *              ---------------------------------------------
 *
 * SPDX-License-Identifier: MIT
 */

#include 
/* Include library main header */
#include 
/* Include Arduino platform header */
#include 

/*
* In case no supported platform is defined, the
* PD and TD pin will be set to the values below.
*/
#ifndef TD
#define TD  15
#endif

#ifndef PD
#define PD  16
#endif

/* Create radar object with following arguments:
 *  TD : Target Detect Pin
 *  PD : Phase Detect Pin */
Bgt60Ino radarShield(TD, PD);

/* Begin setup function - takes care of initializations and executes only once post reset */
void setup()
{
    /* Set the baud rate for sending messages to the serial monitor */
    Serial.begin(9600);
    // Configures the GPIO pins to input mode
    Error_t init_status = radarShield.init();
    /* Check if the initialization was successful */
    if (OK != init_status) {
        Serial.println("Init failed.");
    }
    else {
        Serial.println("Init successful.");
    }
}

/* Begin loop function - this part of code is executed continuously until external termination */
void loop()
{
    /* Initialize the variable to NO_MOTION to be able to record new events */
    Bgt60::Motion_t motion = Bgt60::NO_MOTION;

   /* The getMotion() API does two things:
        1. Returns the success or failure to detect moving object as a message of type Error_t.
           Any value other than OK indicates failure
        2. Sets recent event in "motion" variable. Events can be: NO_MOTION or MOTION */
    Error_t err = radarShield.getMotion(motion);

    /* Check if API execution is successful */
    if(err == OK)
    {
        /* Cases based on value set in motion variable */
        switch (motion)
        {
            /* Variable "motion" is set to MOTION when moving target is detected */
            case Bgt60::MOTION:
                Serial.println("Target in motion detected!");
                break;
            /*  Variable "motion" is set to NO_MOTION when moving target is not present */
            case Bgt60::NO_MOTION:
                Serial.println("No target in motion detected.");
                break;
        }
    }
    /*  API execution returned error */
    else {
        Serial.println("Error occurred!");
    }

    /* Reducing the frequency of the measurements */
    delay(500);
}

沒有注釋,代碼只有 50 行。在我們逐步討論之后,我們將上傳示例。

#include 
#include 
#include 

首先,我們包含了來自 Arduino 的主庫和用于 BGT60 雷達傳感器的庫。

#ifndef TD
#define TD  15
#endif

#ifndef PD
#define PD  16
#endif

Bgt60Ino radarShield(TD, PD);

if 條件檢查是否定義了 TD 和 PD。它們代表我們的引腳相位檢測和硬件的目標檢測。在我們的例子中,它們已經設置好了,因為我們之前定義了支持的平臺 Arduino MKR1000。如果我們選擇另一個微控制器(不是來自 Arduino),這一步是指定未知引腳的必要步驟。行“Bgt60Ino radarShield(TD, PD);” 使用教練用兩個針創(chuàng)建一個雷達對象。

void setup()
{
    Serial.begin(9600);
    // Configures the GPIO pins to input mode
    Error_t init_status = radarShield.init();
    if (OK != init_status) {
        Serial.println("Init failed.");
    }
    else {
        Serial.println("Init successful.");
    }
}

在函數(shù)“setup”中是我們程序的初始化。當我們上傳草圖時它只執(zhí)行一次。“Serial.begin()”函數(shù)設置波特率,它定義了向監(jiān)視器發(fā)送消息的傳輸速度。現(xiàn)在我們使用庫的 API 函數(shù)之一“intit()”來初始化之前的 Bgt60 類對象“radarShield”。因此,引腳將設置為輸入模式。如果初始化成功,函數(shù)返回“OK”。為了以用戶身份查看初始化是否有效,我們打印 init 函數(shù)的結果。

void loop()
{
    Bgt60::Motion_t motion = Bgt60::NO_MOTION;

    Error_t err = radarShield.getMotion(motion);

“l(fā)oop()”函數(shù)是代碼的一部分,它一遍又一遍地重復。首先,我們拒絕變量“運動”以保存檢測到的運動。有兩種可能的狀態(tài)。一開始我們將其設置為“Bgt60::NO_MOTION”。

在下一行中,我們在“radarShield”對象上使用函數(shù)“getMotion()”。該函數(shù)的傳遞參數(shù)是運動變量。當傳感器檢測到運動時,該函數(shù)將變量設置為“Bgt60::MOTION” . 如果整個函數(shù)成功,“OK”將保存在“Error_t”變量中。

if(err == OK)
    {
        switch (motion)
        {
            case Bgt60::MOTION:
                Serial.println("Target in motion detected!");
                break;
            case Bgt60::NO_MOTION:
                Serial.println("No target in motion detected.");
                break;
        }
    }
    else {
        Serial.println("Error occurred!");
    }
    delay(500);
}

在最后一部分,我們檢查函數(shù)是否成功。在這種情況下,如果變量“motion”是“Bgt60::MOTION”或“Bgt60::NO_MOTION”,我們將啟動 switch case 條件并打印解決方案。最后我們開始一個延遲,它代表兩個循環(huán)段落之間的暫停。

pYYBAGNX-5KATxMyAAA2UShhZ2U458.png
工具欄
?

現(xiàn)在我們了解了整個代碼并準備上傳它。如果到目前為止還沒有完成,您可以編譯按鈕 1 上的代碼。使用 2 將草圖上傳到板上。要查看我們打印的內容以及傳感器是否檢測到運動,您必須在 3 上打開顯示器。

當周圍的一切完全靜止時,您可以在監(jiān)視器上讀取“未檢測到運動中的目標”。但是,如果您在距離傳感器 5 米的范圍內有運動,您的輸出就是“檢測到運動中的目標!”。

方向

在成功檢測到運動之后,我們還想知道這個運動的方向。因此,庫、對象創(chuàng)建和設置功能完全相同。

Bgt60::Direction_t direction = Bgt60::NO_DIR;

Error_t err = radarShield.getDirection(direction);

循環(huán)中的代碼也和之前類似,但現(xiàn)在我們?yōu)榉较蜃觥?/font>首先我們需要一個變量來存儲方向。其次,我們使用 API 函數(shù)“getDirection()”。

if (err == OK)
{
    switch (direction)
    {
        case Bgt60::APPROACHING:
            Serial.println("Target is approaching!");
            break;
        case Bgt60::DEPARTING:
            Serial.println("Target is departing!");
            break;
        case Bgt60::NO_DIR:
            Serial.println("Direction cannot be determined since no motion was detected!");
            break;
    }
}
else{
Serial.println("Error occurred!");
}

方向變量有三種可能的狀態(tài)。我們有兩個不同的方向:接近和離開。也有可能,我們根本沒有運動,因此沒有方向。如果 API 函數(shù)有效,它會為錯誤變量返回“O??K”。只有當它成功時,我們才會開始一個 switch-case 條件,我們在離開、接近和無方向之間做出決定。每次延遲后都會打印當前狀態(tài)。

poYBAGNX-5WAKQuSAACR9Lzzthw603.png
可能的監(jiān)視器輸出方向檢測
?

可能的監(jiān)視器輸出在上圖中。要創(chuàng)建它,您首先將手移向傳感器,然后再移開。

打斷

作為最后一個例子,讓我們展示如何使用中斷功能。當您啟用中斷時,處理器會停止其當前活動并保存其狀態(tài)。相反,它同時執(zhí)行一個稱為中斷服務程序 (ISR) 的功能。在我們的示例中,當檢測到的運動或方向的狀態(tài)發(fā)生變化時會觸發(fā)中斷。因此,代碼中的庫和對象創(chuàng)建仍然與上兩個示例中的相同。

init_status = radarShield.enableInterrupt(cBackFunct);

if (OK != init_status)
    Serial.println("Interrupt init failed.");
else
    Serial.println("Interrupt init successful.");
}

在 setup 函數(shù)中,我們像以前一樣設置波特率并初始化我們的對象。此外,我們現(xiàn)在激活中斷。函數(shù)“enableInterrupt()”打開硬件中斷。“cBackFunct”函數(shù)從中斷開始。此外,我們得到一個狀態(tài)變量,我們可以使用它檢查啟用中斷的 API 函數(shù)是否有效。

/* Definition and initialization of the interrupt active flag */
volatile static bool intActive = false;

/* User defined callback function */
void cBackFunct(void)
{
    if ( ! intActive ) {

        /* Set the interrupt active flag to avoid parallel execution of this function multiple times. */
        intActive = true;

        /* Create variables to store the state of the motion as well as the direction */
        Bgt60::Motion_t motion = Bgt60::NO_MOTION;
        Bgt60::Direction_t direction = Bgt60::NO_DIR;

        /* Now check what happend, first check if a motion was detected or is
not detected anymore */
        Error_t err = radarShield.getMotion(motion);

        /* Check if API execution is successful */
        if(OK == err)
        {
            /* In case motion is detected */
            if(Bgt60::MOTION == motion){
                Serial.println("Target in motion was detected!");

                /* Check the direction of the detected motion */
                err = radarShield.getDirection(direction);
                if(OK == err)
                {
                    /* In case the target is approaching */
                    if(Bgt60::APPROACHING == direction){
                        Serial.println("The target is approaching!");
                    }
                    /* In case the target is departing */
                    else{
                        Serial.println("The target is departing!");
                    }
                }
            /* API execution returned error */
            else{
                Serial.println("Error has occurred during the determination of the direction!");
            }
        }
        /* No motion is detected */
        else{
            Serial.println("No target in motion detected!");
        }
    }
    /* API execution returned errord */
    else {
        Serial.println("Error has occurred during the determination of the direction!");
    }

    Serial.println("\n--------------------------------------\n");

    /* Release the interrupt active flag to allow a new call of this callback function. */
    intActive = false;
    }
}

“cBackFunct”代表中斷服務程序(ISR)。我們將它寫在 setup 函數(shù)之前的單獨函數(shù)中。還。我們有一個局部變量,它是中斷的活動標志。因此,它在 ISR 開始時設置為活動,在函數(shù)結束時設置為非活動。為避免多次并行執(zhí)行此函數(shù),“cBackFunct”檢查活動標志之前是否處于非活動狀態(tài)。該函數(shù)中的其他所有內容都類似于方向檢測。我們首先使用已知函數(shù)來檢查運動,然后分離運動的兩個方向。我們打印相應的運動狀態(tài)和方向。之后,我們打印一個視覺邊框以保持概覽。

void loop()
{
    // Here you can do something else in parallel while waiting for an interrupt.
    delay(1000);
}

在我們的循環(huán)函數(shù)中,我們現(xiàn)在只有延遲。我們可以在那里放置任何代碼,這些代碼應該在沒有發(fā)生運動或方向變化的情況下執(zhí)行。為了更容易理解中斷的工作方式,您也可以在循環(huán)中打印一些內容。

poYBAGNX-5iARMpqAABwjzGHWPw709.jpg
?

監(jiān)視器輸出在每個邊界后發(fā)生變化。這是因為我們只有在發(fā)生變化時才開始中斷。打印輸出之間的時間不再像以前那樣有規(guī)律,現(xiàn)在取決于中斷。

如果我們不再需要中斷,例如一段時間后,我們可以使用函數(shù)“disableInterrupt()”禁用它。之后只有我們在循環(huán)中的代碼會被執(zhí)行。


下載該資料的人也在下載 下載該資料的人還在閱讀
更多 >

評論

查看更多

下載排行

本周

  1. 1山景DSP芯片AP8248A2數(shù)據(jù)手冊
  2. 1.06 MB  |  532次下載  |  免費
  3. 2RK3399完整板原理圖(支持平板,盒子VR)
  4. 3.28 MB  |  339次下載  |  免費
  5. 3TC358743XBG評估板參考手冊
  6. 1.36 MB  |  330次下載  |  免費
  7. 4DFM軟件使用教程
  8. 0.84 MB  |  295次下載  |  免費
  9. 5元宇宙深度解析—未來的未來-風口還是泡沫
  10. 6.40 MB  |  227次下載  |  免費
  11. 6迪文DGUS開發(fā)指南
  12. 31.67 MB  |  194次下載  |  免費
  13. 7元宇宙底層硬件系列報告
  14. 13.42 MB  |  182次下載  |  免費
  15. 8FP5207XR-G1中文應用手冊
  16. 1.09 MB  |  178次下載  |  免費

本月

  1. 1OrCAD10.5下載OrCAD10.5中文版軟件
  2. 0.00 MB  |  234315次下載  |  免費
  3. 2555集成電路應用800例(新編版)
  4. 0.00 MB  |  33566次下載  |  免費
  5. 3接口電路圖大全
  6. 未知  |  30323次下載  |  免費
  7. 4開關電源設計實例指南
  8. 未知  |  21549次下載  |  免費
  9. 5電氣工程師手冊免費下載(新編第二版pdf電子書)
  10. 0.00 MB  |  15349次下載  |  免費
  11. 6數(shù)字電路基礎pdf(下載)
  12. 未知  |  13750次下載  |  免費
  13. 7電子制作實例集錦 下載
  14. 未知  |  8113次下載  |  免費
  15. 8《LED驅動電路設計》 溫德爾著
  16. 0.00 MB  |  6656次下載  |  免費

總榜

  1. 1matlab軟件下載入口
  2. 未知  |  935054次下載  |  免費
  3. 2protel99se軟件下載(可英文版轉中文版)
  4. 78.1 MB  |  537798次下載  |  免費
  5. 3MATLAB 7.1 下載 (含軟件介紹)
  6. 未知  |  420027次下載  |  免費
  7. 4OrCAD10.5下載OrCAD10.5中文版軟件
  8. 0.00 MB  |  234315次下載  |  免費
  9. 5Altium DXP2002下載入口
  10. 未知  |  233046次下載  |  免費
  11. 6電路仿真軟件multisim 10.0免費下載
  12. 340992  |  191187次下載  |  免費
  13. 7十天學會AVR單片機與C語言視頻教程 下載
  14. 158M  |  183279次下載  |  免費
  15. 8proe5.0野火版下載(中文版免費下載)
  16. 未知  |  138040次下載  |  免費
大发888娱乐城下载lm0| 裕昌太阳城户型图| KK百家乐娱乐城 | 沁水县| 哪个百家乐官网玩法平台信誉好 | 大发888娱乐出纳柜台| 网上二八杠| 百家乐官网澳门色子| 太阳神百家乐官网的玩法技巧和规则| 星河百家乐现金网| 百家乐娱乐网网| 博士娱乐| 澳门百家乐官网必杀技| 利博百家乐官网的玩法技巧和规则 | 百家乐官网的打法技巧| 广州百家乐官网赌城| 百家乐筹码盒| 大发扑克网址| 百家乐官网对保| 菲律宾百家乐游戏| 新葡京百家乐的玩法技巧和规则| 凯斯娱乐城| 百家乐官网任你博娱乐平台| 澳门百家乐怎赌才能赚钱| 大发888秘籍| 百家乐官网注册优惠平台| 澳门百家乐投注法| 百家乐视频游戏冲值| 貔喜脉动棋牌下载| 百家乐官网赌场方法| 广州百家乐赌场| 澳门金沙赌场| 澳门百家乐官网赌技巧| 专业的百家乐玩家| 含山县| 网上百家乐追杀| 大发888真人斗地主| 太阳城百家乐官网杀猪吗| 百家乐佛泰阁| 合山市| 百家乐视频官网|