ESP32上AD8232 ECG传感器和Firebase集成的问题[已关闭]

vulvrdjw  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(60)

已关闭。此问题需要更多focused。目前不接受回答。
**要改进此问题吗?**更新此问题,使其仅针对editing this post的一个问题。

4天前关闭。
Improve this question

**问题:**我面临的问题是ECG传感器读数一直显示为0,发送到Firebase的数据不准确。我已经检查了连接,它们似乎是正确的。
其他信息:

  • 我已验证ECG传感器是否接收到正确的电源电压。
  • 我还检查了导联脱落检测引脚(leadOffPin 1和leadOffPin 2),它们似乎工作正常。
  • 已成功建立与Firebase的Wi-Fi连接。
  • 具体问题:**
  1. ECG传感器无法提供有效读数的可能原因是什么?如何解决此问题?
    1.如何确保发送到Firebase的数据准确地代表ECG传感器读数?
    1.在将ECG传感器与ESP 32和Firebase集成时,是否有我应该注意的常见陷阱或最佳实践?
    这里是半码
#include <WiFi.h>
#include <FirebaseESP32.h>
#include <Wire.h>
#include <Arduino.h>

const int sensorPin = 14;
const int leadOffPin1 = 22;
const int leadOffPin2 = 23;
const char* ssid = "PROFESSOR";
const char* password = "star2star";
FirebaseConfig firebaseConfig;
FirebaseAuth firebaseAuth;
FirebaseData firebaseData;

#define REPORTING_PERIOD_MS 1000

#define Buzzer 25

uint32_t tsLastReport = 0;
volatile int ecgValue = 0;

void sensorTask(void *pvParameters) {
  for (;;) {
    // Check if either of the lead-off detection pins are indicating a lead-off condition
    if (digitalRead(leadOffPin1) == 1 || digitalRead(leadOffPin2) == 1) {
      Serial.println("0"); // If lead-off is detected, print "0" to the Serial Plotter
      delay(500); // Wait for a while before the next check
    } else {
      // Read the ECG sensor value
      int ecgValue = analogRead(sensorPin);
      Serial.println(ecgValue); // Print the ECG sensor value to the Serial Plotter
      delay(400); // Delay for stability and to match the rate of lead-off checks
    }

    // Check if it's time to send data to Firebase based on a time interval
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
      // Send the ECG sensor value to Firebase under the path "/ECG/ECGVALUES"
      Firebase.setInt(firebaseData, "/ECG/ECGVALUES", ecgValue);
      Serial.println("ecg sent"); // Print a message indicating that the ECG data was sent
    }

    delay(10); // Small delay to control the loop speed
  }
}

void setup() {
  Serial.begin(9600); // Initialize serial communication with a baud rate of 9600.

  pinMode(leadOffPin1, INPUT); // Set leadOffPin1 as an input pin.
  pinMode(leadOffPin2, INPUT); // Set leadOffPin2 as an input pin.

  WiFi.begin(ssid, password); // Connect to the Wi-Fi network with the specified SSID and password.

  while (WiFi.status() != WL_CONNECTED) {
    delay(500); // Wait for the Wi-Fi connection to establish. Checks every 500 milliseconds.
  }

  firebaseConfig.host = "ckd-web-interface-default-rtdb.firebaseio.com"; // Set the Firebase host URL.
  firebaseConfig.api_key = "AIzaSyAhelk_39kII2gWBtqYZvf0BLbpb6VLkaE"; // Set the Firebase API key.
  firebaseAuth.user.email = "[email protected]";  // Set the Firebase authentication email.
  firebaseAuth.user.password = "1234567"; // Set the Firebase authentication password.

  Firebase.begin(&firebaseConfig, &firebaseAuth); // Initialize the Firebase connection.
  Firebase.reconnectNetwork(true); // Reconnect to the Firebase network if the connection is lost.

  xTaskCreatePinnedToCore(sensorTask, "SensorTask", 10000, NULL, 1, NULL, 0); // Create a separate task named "SensorTask" with specified parameters.
}

字符串

7cwmlq89

7cwmlq891#

您的代码在使用WiFi的同时从GPIO 14读取模拟值。
GPIO 14位于ADC 2上,当WiFi处于活动状态时,ADC 2不可用。
来自ESP 32的GPIO文档:
ADC 2:使用Wi-Fi时,ADC 2引脚无法使用。因此,如果您在使用Wi-Fi时无法从ADC 2 GPIO获取值,您可以考虑使用ADC 1 GPIO,这应该可以解决您的问题。
ADC 2引脚为0、2、4、12、13、14、15、25、26和27。使用WiFi时不要尝试从这些引脚读取模拟值。ADC 1引脚为32至39。请使用其中一个引脚。
您询问了如何解决此问题:您可以随时从ADC 2引脚读取模拟值,但当您发现获得意外值时,可以尝试将引脚连接到已知值并查看是否有效。如果无效,则您知道analogRead()未按预期工作。
阅读文档也是一个很好的开始。

相关问题