Automatic Blood Pressure Monitor - An Inside Look



ESP32 Code used in Arduino IDE to take readings from the HX710 ADC based pressure sensor below. This just streams the data to serial (USB) interface for display on serial monitor/plotter.

/**********************************************************************
  Filename    : ESP32_blood_pressure
  Description : Take HX710 ADC data from pressure sensor
                Users visit the site to view the image data ESP32 camera.
  Author      : Tinker Foundry
**********************************************************************/
// References:
// https://swharden.com/blog/2022-11-14-hx710b-arduino/
// https://www.electronicscomp.com/datasheet/hx710b-ic-datasheet.pdf

#include <WiFi.h>

const char* ssid     = "xxxxxx";     // input your wifi name
const char* password = "xxxxxx";    // input your wifi passwords

const int HX_OUT_PIN = 12; // input from HX710 ADC chip - serial input
const int HX_SCK_PIN = 13; // clock output to the HX710 ADC chip
#define DAC_CH1 25

enum HX_MODE { NONE, DIFF_10Hz, TEMP_40Hz, DIFF_40Hz};
const byte HX_MODE = DIFF_10Hz;

void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  Serial.println();

  WiFi.begin(ssid, password);
  while (WiFi.isConnected() != true) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  Serial.print(WiFi.localIP());
  Serial.println("' to connect");

  // set-up pins for the HX710B ADC interface
  // HX710 uses a specific serialization scheme
  // We need to send an output pulse clock, and for each pulse we receive 1 bit of data
  // 24 bits of data +
  pinMode(HX_SCK_PIN, OUTPUT);
  pinMode(HX_OUT_PIN, INPUT);
  digitalWrite(HX_SCK_PIN, LOW);
  delay(10);
}

// Main loop
void loop() {
  unsigned long pressure;
  // read from ADC and write out to serial interface
  pressure = readHX();
  Serial.println(pressure);
  //dacWrite(DAC_CH1, int(pressure));
  //Serial.println(readHX());
  // 16777215 is when the adc saturates...
  //
  //delay(5);
}

// function to read HX710 output
unsigned long readHX()
{
  unsigned long Count;
  unsigned char i;
  int pinval;

  Count  = 0;
  pinval = 0;

  digitalWrite(HX_SCK_PIN, LOW);

  // wait for the previous reading to finish
  while (digitalRead(HX_OUT_PIN)) {}
  delayMicroseconds(2);

  for (i=0; i < 24; i++)
  {
    digitalWrite(HX_SCK_PIN, HIGH);
    delayMicroseconds(1); // guarantee minimum timing
   
    Count = Count << 1; // shift left to build 24 bit number one cycle at a time
   
    digitalWrite(HX_SCK_PIN, LOW);
    delayMicroseconds(1); // guarantee minimum timing

    pinval = digitalRead(HX_OUT_PIN);
    if (pinval)
    {
      Count++; // if input was 1, increment
    }
  }

  // cycle the clock 1 more time for 10Hz samping mode
  digitalWrite(HX_SCK_PIN, HIGH);
  delayMicroseconds(1); // guarantee minimum timing  
  digitalWrite(HX_SCK_PIN, LOW);
  delayMicroseconds(1); // guarantee minimum timing

  Count = Count^0x800000; // need this to flip msb

  return Count;
}

Comments

Popular posts from this blog

ESP32 Based Pulse-Oximeter using MAX30102

ESP32 Web Sockets - Transferring Image Raw Data

Heart Rate Measurement with ESP32 and Pulse Oximeter Module using FFT