0

I am a novice Arduino user trying to measure the frequency output of my HTF3228LF humidity sensor using the library FreqCount on my Arduino Teensy LC.

My circuit connects the output of my sensor to a voltage divider to cut the HIGH voltage from 5V to 2.5V, and feeds that signal into a unity gain buffer to successfully drive pin13's LED on my Teensy LC board.

I noticed a strange issue when trying to follow the FreqCount example script where FreqCount.available() only returns 0. Removing the if statement checking whether FreqCount is availabe seems to fix the issue, but I haven't been able to find mention of this issue anywhere else. Any help would be appreciated.

The following is my code

/*
 * testFreqCount.ino
 * 
 * The purpose of this script is to test the FreqCount library and to make sure
 * it doesn't interrupt the running of the rest of the program like pulseIn() does
 */
#include <LiquidCrystal.h>
#include <FreqCount.h>

// Setting up pins
LiquidCrystal lcd(18,19,20,21,22,23);

// Setting RH reading
unsigned long RH;

// Setting timing
unsigned long currentTime;
int waitTimeDisplay = 500;
unsigned long lastProcDisplay = 0;

///////////////////////////////////////////////
// Helper functions
///////////////////////////////////////////////
float readHumidityHTF3228LF() {
    // This function requires that the user
    // attach their frequency to pin 13 by 
    // default and requires no further input
    // USAGE: readHumidityHTF3228LF()
    // OUTPUT: unsigned long RH
    unsigned long frequencyH;
    //if(FreqCount.available()){                    <----------- Problematic
    frequencyH = FreqCount.read();
    //}
    return (-1*(frequencyH - 9595))/14.8;//relative humidity
}


///////////////////////////////////////////////
// Actual code
///////////////////////////////////////////////
void setup(){
  Serial.begin(57600);
  FreqCount.begin(1000);
  lcd.begin(16,2);
  currentTime = millis();
  RH = readHumidityHTF3228LF();
  lcd.setCursor(0,0);
  lcd.print(currentTime);
  lcd.setCursor(0,1);
  lcd.print(String(RH) + "%");
}

void loop(){
  currentTime = millis();
  RH = readHumidityHTF3228LF();
  if((currentTime - lastProcDisplay) >= waitTimeDisplay){
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(currentTime);
    lcd.setCursor(0,1);
    lcd.print(String(RH) + "%");
    lastProcDisplay = currentTime;
  }
}
Velvel
  • 3,591
  • 3
  • 12
  • 30
  • From https://www.pjrc.com/teensy/td_libs_FreqMeasure.html On the LC, Pin 16 is what to use for frequency (and it needs to be a digital input with H~3.3v). Your comment lines // This function requires that the user // attach their frequency to pin 13 by // default and requires no further input - suggests that you are using the wrong pin. – DrG Feb 12 '23 at 19:40

0 Answers0