I finally got the package with the weather sensors in, and started testing the code, but there are things I don’t understand.
The datasheet says 1 pulse/sec = 2.4 km/h wind speed. But when I put the code in it say the wind speed is around 1.1 - 1.4 km/h. To check how many pulses came through I tried to attach my Extech multimeter and set it to measure Hz, and it returned around 5-6 Hz, should that not give something around 12-14.4 km/h wind speed?
This is the modified version of the code I use. To pull it HIGH I use a 10k resistor between pin 2 and 3v3.
`// Threshold values to consider a high/low transition
// You may want to / need to change these:
// 65535 * 0.8
const HIGH_THRESH = 39321;
// 65535 * .4
const LOW_THRESH = 26214;
// Variables to track pulse lengths
pulseLength <- 0;
pulseLow <- false;
function onBufferFull(buffer, length)
{
// process the buffer:
local bufferLength = length/2; // each sample is 2 bytes
local windSpeed;
for(local i = 0; i < bufferLength; i++)
{
pulseLength++;
// read the value
local dataPoint = buffer.readn('w');
if (pulseLow == true)
{
// if the last pulse was HIGH
if (dataPoint >= HIGH_THRESH)
{
// if we transitioned from high to low ...
// set the pulseLow variable
pulseLow = false;
}
}
else
{
// if last sample was LOW
if (dataPoint <= LOW_THRESH)
{
// and we've transitioned to high..
// calculate the wind speed
windSpeed = pulseLength / 1000.0 * 2.4; // in KPH
// do something with windSpeed??
// ...
// set the pulseHigh variable
pulseLow = true;
// reset the pulse counter
pulseLength = 0;
}
}
}
agent.send(“windSpeed”, windSpeed);
}
buffers <- [ blob(2000), blob(2000) ];
// configure and start the sampler (which runs in the background)
hardware.sampler.configure(hardware.pin2, 1000, buffers, onBufferFull);
hardware.sampler.start();`
And the values from high/low is from around 65407 when high to 0-100 when pulled low.
Anything that looks wrong here?