Go Down

Topic: Anemometer sensor TX23 IT+ (Read 1 time) previous topic - next topic

Theviking

Hi guys,

I 'm trying to read wind direction and wind intensity on an anemometer which send me a datagram on only one wire.
So basically I'm sure of my hardware connexion because I can read the wind direction perfectly and the protocol is respected.

My only reference for the protocol is that : http://www.john.geek.nz/2012/08/la-crosse-tx23u-anemometer-communication-protocol/#more-2271

I checked several times my program and compare with some forum and it seems that I have a classic problem like other people. The wind intensity datagram is 00000000 even if I make the sensor move.

My program is quite similar with this one : http://forum.arduino.cc/index.php?topic=62753.0

One guy explained that he corrected the problem by putting a 2sec delay between the kind of request and the reading part to let the time to the sensor to calculate wind intensity.

But for me it doesn't work even if the rest is OK.

Your idea would be really helpfull. Sorry for my english.


Shadow24

Hello,

I noticed this post looks old, and have found mixed info. on the Internet. Does anyone know if there is a working library or samples to get both the wind speed and direction working consistently?

I'm new to Arduino programming and was trying to avoid trying to figure out how to write "bitbang" code to try and read the signaling if it's already been done.

Thanks,

Shadow

groundFungus

#2
Oct 25, 2016, 04:32 pm Last Edit: Oct 25, 2016, 04:37 pm by groundfungus
This is the function that I wrote to read my tx23 sensor.   Reads every 5 seconds, works well.  Used info from this site https://www.john.geek.nz/2012/08/la-crosse-tx23u-anemometer-communication-protocol/

Code: [Select]

// these are global variables.  I really should make most local but.....

const byte windPin = 7;

char *windDirTxt[] = {
  "N  ","NNE","NE ","ENE","E  ","ESE","SE ","SSE","S  ","SSW","SW ","WSW","W  ","WNW","NW ","NNW"};
long datagram;
byte datagramBits = 23;
unsigned int bitWide;
unsigned int halfBitWide;
byte windDirNbl;
float windSpdF;
const float mps2mph = 2.236936;

// get wind speed and direction
void getWind()
{
  static unsigned long windReadTimer = 0;
  static byte windReadIndex = 0;
  static unsigned long getWindTimer = 0;
  unsigned long getWindInterval = 5000;
  if(currMillis - getWindTimer > getWindInterval)
  {
    getWindTimer = currMillis;
    float lastwindSpd = windSpdF;
    byte lastwindDir = windDirNbl;
    pinMode(windPin, OUTPUT);
    digitalWrite(windPin, LOW);
    delay(500);
    digitalWrite(windPin, HIGH);
    pinMode(windPin, INPUT);
    while(digitalRead(windPin) == LOW);  // wait for datagram start
    unsigned int twiceBitWide = pulseIn(windPin, HIGH, 100000);  // get bit width
    bitWide = twiceBitWide / 2;
    halfBitWide = twiceBitWide / 4;
    delayMicroseconds(halfBitWide);
    windReadIndex = 0;
    while(windReadIndex < datagramBits)
    {
      if(micros() - windReadTimer > bitWide)
      {
        windReadTimer = micros();
        bitWrite(datagram, windReadIndex, digitalRead(windPin));
        windReadIndex++;
      }
    }
    for(int n = 0; n < 4; n++)
    {
      bitWrite(windDirNbl, n, bitRead(datagram, n + 3));
    }
    int windSpd = 0;
    for(int n = 0; n < 12; n++)
    {
      bitWrite(windSpd, n, bitRead(datagram, n + 7));
    }
    windSpdF = windSpd / 10.00;
    windSpdF *= mps2mph;
    if(windSpdF > 90.0)
    {
       windSpdF = lastwindSpd;
    }
    byte ckSum = 0;
    byte fNbl, sNbl, tNbl;
    for(int n = 0; n < 4; n++)
    {
      bitWrite(ckSum, n, bitRead(datagram, n + 19));
    }

    fNbl = windSpd & 0x000F;
    sNbl = (windSpd >> 4) & 0x000F;
    tNbl = (windSpd >> 8) & 0x000F;
    byte sumOfAll = (windDirNbl + fNbl + sNbl + tNbl) & 0x0F;
    if(ckSum == sumOfAll)
    {
      //Serial.println("***  CHECKSUM PASS  ***");
    }
    else
    {    
      //Serial.println("***  CHECKSUM FAIL  ***");
    }
  }  
}

Go Up