sharix
Posts: 200
Joined: Thu Feb 16, 2012 11:29 am
Location: Slovenia

Measuring frequency

Thu Jul 05, 2012 8:59 am

Hello, I ordered a HH10D humidity sensor (click link for datasheet), I thought it used I2C for output but then I found out it outputs frequency.
So how could I read this with the GPIO port?

godFather89
Posts: 150
Joined: Fri May 18, 2012 9:40 am
Location: Timisoara, RO

Re: Measuring frequency

Thu Jul 05, 2012 9:18 am

Features:
I2C interface
2.7-3.3V Input
It has an I2C interface so you can use I2C.

sharix
Posts: 200
Joined: Thu Feb 16, 2012 11:29 am
Location: Slovenia

Re: Measuring frequency

Thu Jul 05, 2012 9:20 am

But as I understand it, you use I2C only to read the calibration values. Maybe I'm wrong

User avatar
leon_heller
Posts: 89
Joined: Wed May 02, 2012 4:10 pm
Location: St. Leonards-on-Sea, E. Sussex, UK.

Re: Measuring frequency

Thu Jul 05, 2012 9:23 am

You need to measure the frequency. I2C is only used for calibration.
Leon Heller
G1HSM

godFather89
Posts: 150
Joined: Fri May 18, 2012 9:40 am
Location: Timisoara, RO

Re: Measuring frequency

Thu Jul 05, 2012 9:34 am

Yes, you are right. I didn't pay much attention.
Measuring frequency with RPi it's a (pretty) hard task. You could use a timer/counter with input set to a GPIO pin (not sure if possible) or you could poll the GPIO (or use interrupts) and determine the frequency. Either way, I would get a different sensor since it's too much trouble. There are lots of I2C/SPI sensors out there.

You could also use some uC (AVR - tiny, mega; PICs) to measure the frequency and output the data in a more useful format for RPi (I2C, serial, etc.).

Another way would be to use an external parallel counter. You connect the output pin of the sensor to the input of the counter and the reset and data pins to the RPi. On the RPi side, when you want to get a read, you reset and enable the counter, wait a period of time (100ms, 500ms, 1sec) and read the value. Knowing the number of impulses in a period of time, you can compute the frequency. Depending on the time period you choose, you need to compute the max count value for the counter (max output frequency is 10KHz).
Ex:
1 sec means 10000 impulses max, so the counter has to be at least 14 bit (16384).
100 msec means 1000 impulses max, so the counter has to be at least 10 bit (1024).

sharix
Posts: 200
Joined: Thu Feb 16, 2012 11:29 am
Location: Slovenia

Re: Measuring frequency

Fri Jul 20, 2012 1:24 pm

Could you recommend a counter suitable for this?
Would DS1372 be ok? http://docs-europe.electrocomponents.co ... ab8a28.pdf

User avatar
Gert van Loo
Posts: 2482
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Measuring frequency

Fri Jul 20, 2012 8:39 pm

No, that does not have an input for an external signal.
Also you can not use the XTAL-input to measure your signal as you then loose your reference clock.

Thanks for pointing me to that IC because I might need it in a project where I need to divide
down a known clock frequency to a lower value.

Mister_C
Posts: 22
Joined: Mon Jun 25, 2012 8:53 pm

Re: Measuring frequency

Tue Jul 24, 2012 9:26 pm

sharix / Gert,
If you're OK with a binary divider then a 4024B Binary counter might be another suitable choice. Feed the input frequency to pin 1 and tap the most suitable output pin (1/2 - 1/128) for a simple frequency division.
For instance, 40kHz (ultrasound receiver) input, pin 5 is 1/32 division giving 1.25kHz output.
Cost well under a pound each.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Measuring frequency

Tue Jul 24, 2012 10:00 pm

shame there does not seem to be an east to use I2C frequency counter readily available - I've encountered a similar sticking point myself. If you wanted to substitute one problem for another you could use the pulses to trigger a monostable multivibrator and then smooth the result as if it were pwm and somehow measure the resulting voltage level - but like another poster said, its a world of hurt.
Ostendo ignarus addo scientia.

User avatar
Gert van Loo
Posts: 2482
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Measuring frequency

Wed Jul 25, 2012 7:08 pm

I would grab one of the new 6 pin or 8 pin microcontrollers for this.
They all have a timer, I2C interface and an external X-tal.
But you have to write the SW for it to set it up, read the timer and reply to
I2C slave reads. On the other hand you can do a lot of other nifty things then.
Like measure multiple times and average the result.
Measure the period (good for slow signals).
Some have a ADC so you can use it as a tiny slow, small signal scope.

-- Gert

sharix
Posts: 200
Joined: Thu Feb 16, 2012 11:29 am
Location: Slovenia

Re: Measuring frequency

Wed Jul 25, 2012 7:22 pm

I went one step further and got a DK-duino.

User avatar
HermannSW
Posts: 1390
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Measuring frequency

Mon Jul 25, 2016 12:30 am

> You could also use some uC (AVR - tiny, mega; PICs) to measure the frequency
> and output the data in a more useful format for RPi (I2C, serial, etc.).
>
A (12$) Arduino Due can measure frequencies (and duties) up to 42MHz with the help of timer counter based tc_lib. A Raspberry Pi Zero can generate up to 28MHz test frequency for that:
viewtopic.php?f=63&t=155083&p=1013680#p1013680

Hermann.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
joan
Posts: 14179
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Measuring frequency

Mon Jul 25, 2016 4:48 am

The post is 4 years old.

pigpio has no problem in reading frequencies in the range generated by that sensor (5-10kHz).

Return to “Automation, sensing and robotics”