<acronym id="s8ci2"><small id="s8ci2"></small></acronym>
<rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
<acronym id="s8ci2"></acronym>
<acronym id="s8ci2"><center id="s8ci2"></center></acronym>

電子發燒友App

硬聲App

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
創作中心

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

3天內不再提示
電子發燒友網>電子資料下載>電子資料>在連接到STM32的LCD屏幕上顯示BLE傳感器讀數

在連接到STM32的LCD屏幕上顯示BLE傳感器讀數

2023-06-14 | zip | 0.00 MB | 次下載 | 免費

資料介紹

描述

藍牙 LE 項目的目的是讀取空氣質量傳感器數據并將其顯示在連接到 STM32 板的 LCD 顯示器上。Web 瀏覽器將讀取傳感器數據并使用 BleuIO 將其傳遞給 STM32 板。

一、簡介

該項目基于STM32 Nucleo-144 ,它使用 BleuIO控制LCD 顯示。

對于這個項目,我們需要兩個 BleuIO USB 加密狗,一個連接到 Nucleo 板,另一個連接到運行 Web 腳本的計算機和HibouAir – 空氣質量監測設備。當 BleuIO Dongle 連接到 Nucleo 板的 USB 端口時,STM32 將識別它并直接開始廣播。這允許計算機端口上的加密狗與網絡腳本連接。

通過電腦上的網頁腳本,我們可以從 HibouAir 掃描并獲取空氣質量傳感器數據。然后我們將這些數據發送到使用藍牙連接到 STM32 的 LCD 屏幕上。

在本示例中,我們使用了 STM32 Nucleo-144 開發板和 STM32H743ZI MCU(支持 STM32H743ZI micro mbed 的開發 Nucleo-144 系列 ARM? Cortex?-M7 MCU 32 位嵌入式評估板)。該開發板有一個 USB 主機,用于連接 BleuIO 加密狗。

如果要使用其他設置,則必須確保它支持 USB 主機,并注意 GPIO 設置可能不同,可能需要在 .ioc 文件中重新配置。

關于守則

項目源代碼可在 Github 上獲得。

https://github.com/smart-sensor-devices-ab/stm32_ble_sensor_lcd.git

克隆項目,或將其下載為 zip 文件并解壓縮到您的 STM32CubeIDE 工作區。

如果您將項目下載為 zip 文件,則需要將項目文件夾從“stm32_bleuio_lcd-master”重命名為“stm32_bleuio_lcd”

poYBAGNYujGAHG3iAAA5lM86hos585.jpg
?

SDA 連接到 Nucleo 板上的 PF0,將 SCL 連接到 PF1。

然后在 STM32Cube ioc 文件中設置 I2C2,如下所示。(確保根據 LCD 顯示要求將 I2C 速度頻率更改為 50 KHz。)

pYYBAGNYujSAJEhUAAAMP9SP5yI872.png
?
poYBAGNYujaAHKGmAAA1m3qD8Eg155.png
?
pYYBAGNYujiAC5AqAADEqDRQv9k945.jpg
?

在 USB_HOST\usb_host.c 中的 USBH_CDC_ReceiveCallback 函數中,我們將 CDC_RX_Buffer 復制到一個名為 dongle_response 的外部變量中,該變量可從 main.c 文件訪問。

void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef * phost) {
  if (phost == & hUsbHostFS) {
    // Handles the data recived from the USB CDC host, here just printing it out to UART
    rx_size = USBH_CDC_GetLastReceivedDataSize(phost);
    HAL_UART_Transmit( & huart3, CDC_RX_Buffer, rx_size, HAL_MAX_DELAY);

    // Copy buffer to external dongle_response buffer
    strcpy((char * ) dongle_response, (char * ) CDC_RX_Buffer);

    // Reset buffer and restart the callback function to receive more data
    memset(CDC_RX_Buffer, 0, RX_BUFF_SIZE);
    USBH_CDC_Receive(phost, CDC_RX_Buffer, RX_BUFF_SIZE);
  }

  return;
}

在 main.c 中,我們創建了一個簡單的解釋器,這樣我們就可以對從加密狗收到的數據做出反應。

void dongle_interpreter(uint8_t * input) {

  if (strlen((char * ) input) != 0) {
    if (strstr((char * ) input, "\r\nADVERTISING...") != NULL) {
      isAdvertising = true;
    }
    if (strstr((char * ) input, "\r\nADVERTISING STOPPED") != NULL) {
      isAdvertising = false;
    }
    if (strstr((char * ) input, "\r\nCONNECTED") != NULL) {
      isConnected = true;
      HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_SET);
    }
    if (strstr((char * ) input, "\r\nDISCONNECTED") != NULL) {
      isConnected = false;
      HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET);
    }

    if (strstr((char * ) input, "L=0") != NULL) {

      isLightBulbOn = false;
      //HAL_GPIO_WritePin(Lightbulb_GPIO_Port, Lightbulb_Pin, GPIO_PIN_RESET);
      lcd_clear();

      writeToDongle((uint8_t * ) DONGLE_SEND_LIGHT_OFF);

      uart_buf_len = sprintf(uart_tx_buf, "\r\nClear screen\r\n");
      HAL_UART_Transmit( & huart3, (uint8_t * ) uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);
    }

    if (strstr((char * ) input, "L=1") != NULL) {
      isLightBulbOn = true;
      writeToDongle((uint8_t * ) DONGLE_SEND_LIGHT_ON);

      lcd_clear();

      lcd_write(input);

    }

  }
  memset( & dongle_response, 0, RSP_SIZE);
}

我們將解釋器函數放在主循環中。

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) {
  /* USER CODE END WHILE */
  MX_USB_HOST_Process();

  /* USER CODE BEGIN 3 */
  // Simple handler for uart input
  handleUartInput(uartStatus);

  // Inteprets the dongle data
  dongle_interpreter(dongle_response);

  // Starts advertising as soon as the Dongle is ready.
  if (!isAdvertising && !isConnected && isBleuIOReady) {
    HAL_Delay(200);
    writeToDongle((uint8_t * ) DONGLE_CMD_AT_ADVSTART);
    isAdvertising = true;
  }
}
/* USER CODE END 3 */

使用示例項目

我們需要什么

作為現有項目導入

從 STM32CubeIDE 中選擇 File>Import…

pYYBAGNVlzGAOrdTAABTMPtN_vY766.png
?

然后選擇 General>Existing Projects into Workspace 然后點擊“Next >”

poYBAGNVlzOAbEAcAACCYdjUQ8w416.png
?

確保您在“選擇根目錄:”中選擇了您的工作區

您應該會看到項目“stm32_bleuio_SHT85_example”,選中它并單擊“完成”。

pYYBAGNVlzWAF9eHAACaAb8Lb0g612.png
?

運行示例

將代碼上傳到 STM32 并運行示例。連接到 STM32 的 USB 加密狗將自動開始廣播。

從網絡瀏覽器將傳感器數據發送到 LCD 屏幕

將 BleuIO 加密狗連接到計算機。運行 Web 腳本以連接到 STM32 上的另一個 BleuIO 加密狗。現在您可以將傳感器數據發送到 LCD 屏幕。

為了讓這個腳本工作,我們需要

創建一個名為 index.html 的簡單 Html 文件,該文件將用作腳本的前端。這個 Html 文件包含一些幫助連接的按鈕,從 HibouAir 讀取廣告數據以獲取空氣質量傳感器數據,并將此數據發送到連接到 stm32 的 LCD 屏幕。

html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link
      href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
      rel="stylesheet"
      integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
      crossorigin="anonymous"
    />
    <title>Bluetooth LE Air quality sensor data to LCD screentitle>
  head>
  <body class="mt-5">
    <div class="container mt-5">
      <img
        src="https://www.bleuio.com/blog/wp-content/themes/bleuio/images/logo.png"
      />
      <h1 class="mb-5">Bluetooth LE Air quality sensor data to LCD screenh1>

      <div class="row">
        <div class="col-md-4 pt-5">
          <button class="btn btn-success mb-2" id="connect">Connectbutton>
          <form method="post" id="sendDataForm" name="sendMsgForm" hidden>
            <div class="mb-3">
              <label for="sensorID" class="form-label">Sensor IDlabel>
              <input
                type="text"
                class="form-control"
                name="sensorID"
                id="sensorID"
                required
                maxlength="60"
                value="0578E0"
              />
            div>

            <button type="submit" class="btn btn-primary">Get Databutton>
          form>
          <br />
          <button class="btn btn-danger" id="clearScreen" disabled>
            Clear screen
          button>
        div>
        <div class="col-md-8">
          <img src="air_quality_lcd.jpg" class="img-fluid" />
        div>
      div>
    div>

    <script src="script.js">script>
  body>
html>

創建一個名為 script.js 的 js 文件并將其包含在 Html 文件的底部。這個 js 文件使用 BleuIO js 庫來編寫 AT 命令并與其他加密狗進行通信。

該腳本有一個按鈕可以連接到計算機上的 COM 端口。有一個文本字段,您可以在其中寫入空氣質量監測設備的傳感器 ID。連接后,腳本將嘗試從傳感器獲取廣告數據并將其轉換為有意義的數據。之后,它將這些數據發送到 STM32 板,然后顯示在 LCD 屏幕上。

import * as my_dongle from 'bleuio'
import 'regenerator-runtime/runtime'

const dongleToConnect = '[0]40:48:FD:E5:2F:17'
//const sensorID = '0578E0'
document.getElementById('connect').addEventListener('click', function() {
	my_dongle.at_connect()
	document.getElementById("clearScreen").disabled = false;
	document.getElementById("connect").disabled = true;
	document.getElementById("sendDataForm").hidden = false;
})

document.getElementById("sendDataForm").addEventListener("submit", function(event) {
	event.preventDefault()
	const sensorID = document.getElementById('sensorID').value
	getSensorData(sensorID)
	setInterval(function() {
		getSensorData(sensorID)
	}, 10000);


});

const getSensorData = ((sensorID) => {
	my_dongle.ati().then((data) => {
			//make central if not
			if (JSON.stringify(data).includes("Peripheral")) {
				console.log('peripheral')
				my_dongle.at_dual().then((x) => {
					console.log('central now')
				})
			}
		})
		.then(() => {
			// connect to dongle
			my_dongle.at_getconn().then((y) => {
					if (JSON.stringify(y).includes(dongleToConnect)) {
						console.log('already connected')
					} else {
						my_dongle.at_gapconnect(dongleToConnect).then(() => {
							console.log('connected successfully')
						})
					}
				})
				.then(async () => {
					return my_dongle.at_findscandata(sensorID, 6).then((sd) => {
						console.log('scandata', sd)
						let advData = sd[sd.length - 1].split(" ").pop()
						let positionOfID = advData.indexOf(sensorID);
						let tempHex = advData.substring(positionOfID + 14, positionOfID + 18)
						let temp = parseInt('0x' + tempHex.match(/../g).reverse().join('')) / 10;

						let co2Hex = advData.substring(positionOfID + 38, positionOfID + 42)
						let co2 = parseInt('0x' + co2Hex);
						//console.log(temp,co2)
						return {
							'CO2': co2,
							'Temp': temp,
						}
					})
				})
				.then((x) => {
					console.log(x.CO2)
					console.log(x.Temp)
					var theVal = "L=1 SENSOR ID " + sensorID + "    TEMPERATURE " + x.Temp + ' °c    CO2 ' + x.CO2 + ' ppm';
					console.log('Message Send 1 ')
					// send command to show data
					my_dongle.at_spssend(theVal).then(() => {
						console.log('Message Send ' + theVal)
					})
				})

		})
})

document.getElementById('clearScreen').addEventListener('click', function() {
	my_dongle.ati().then((data) => {
			//make central if not
			if (JSON.stringify(data).includes("Peripheral")) {
				console.log('peripheral')
				my_dongle.at_central().then((x) => {
					console.log('central now')
				})
			}
		})
		.then(() => {
			// connect to dongle
			my_dongle.at_getconn().then((y) => {
					if (JSON.stringify(y).includes(dongleToConnect)) {
						console.log('already connected')
					} else {
						my_dongle.at_gapconnect(dongleToConnect).then(() => {
							console.log('connected successfully')
						})
					}
				})
				.then(() => {
					// send command to clear the screen
					my_dongle.at_spssend('L=0').then(() => {
						console.log('Screen Cleared')
					})
				})

		})
})

要連接到 STM32 上的 BleuIO 加密狗,請確保 STM32 已通電并連接了 BleuIO 加密狗。

獲取 MAC 地址

按照步驟獲取連接到STM32的加密狗的MAC地址

- Open this site https://bleuio.com/web_terminal.html and click connect to dongle.
- Select the appropriate port to connect.
- Once it says connected, type ATI. This will show dongle information and current status.
- If the dongle is on peripheral role, set it to central by typing AT+CENTRAL
- Now do a gap scan by typing AT+GAPSCAN
- Once you see your dongle on the list ,stop the scan by pressing control+c
- Copy the ID and paste it into the script (script.js) line #4
?

運行網頁腳本

您將需要一個網絡捆綁程序。您可以使用parcel.js

安裝 parcel js 后,轉到 web 腳本的根目錄并輸入“parcel index.html” 。這將啟動您的開發環境。

pYYBAGNYukOAZYK9AAA2QUu69rw587.jpg
?

在瀏覽器上打開腳本。對于這個例子,我們打開http://localhost:1234

您可以輕松連接到加密狗并在 LCD 屏幕上查看空氣質量數據。響應將顯示在瀏覽器控制臺屏幕上。

網絡腳本看起來像這樣

poYBAGNYukWAZVLXAACK0oepQis173.png
?

輸出

信息將顯示在液晶顯示屏上。

pYYBAGNYukiAByg3AACVI30HeJk214.png
?

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

評論

查看更多

下載排行

本周

  1. 1山景DSP芯片AP8248A2數據手冊
  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開發指南
  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數字電路基礎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次下載  |  免費
亚洲欧美日韩精品久久_久久精品AⅤ无码中文_日本中文字幕有码在线播放_亚洲视频高清不卡在线观看
<acronym id="s8ci2"><small id="s8ci2"></small></acronym>
<rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
<acronym id="s8ci2"></acronym>
<acronym id="s8ci2"><center id="s8ci2"></center></acronym>