Hello, I am trying to implement your code on one of my projects but the wind speed seems to always be zero, do you know what the issue could be?
velzend:
I also bought a TX23 last friday. And had some time yesterday. But I think the communication is a little bit different then the TX20.
For the wind speed readings you will need a extra pause/ delay of appr. 2000mS.
I connected the DTR pin to a digital input and simply send a HIGH and LOW every 2000mS, does the trick.
The wind speed is a 12 bit value. You need to invert and endianness swap this bits.
The bit represents a value in units of 0.1 metre/sec. The 3 MSBs always are 000 so only 9 bits are used.
This value is max. 511 and with a simple calculation you get 51.1 meter per second or 183.96 km/h
This is the source from the updated version, this will light up a LED or in my example 8 old fashioned lightbulbs via a FETs.
Still needs some tweaking, and microdelay seems to be a problem, had this problem before a already had a work-a-round (see source)
Youtube: http://www.youtube.com/watch?v=vIQbHNrPSfg
#include <SoftPWM.h>
void setup();
void delay2(unsigned long ms);
void loop();
int collectdata(void);
void showdatasimple();
int dataPin = 12;
int bitlenght = -1;
char data[43];
String Wind_Direction;
uint8_t lightbulbs[8] = {2, 3, 4, 5, 6, 7, 8, 9};
void setup() {
Serial.begin(9600);
Serial.print("\n\nInitializing...\n");
Serial.print("Data Pin: ");
Serial.println(digitalRead(dataPin));
pinMode(dataPin, INPUT);
// Initialize
SoftPWMBegin();
for (int i = 0; i < 8; i++)
SoftPWMSet(lightbulbs[i], 0);
SoftPWMSetFadeTime(ALL, 500, 500);
}
void delay2(unsigned long ms){
unsigned long start = micros();
while (micros() - start <= ms);
}
void loop() {
collectdata();
}
int collectdata(void){
if (bitlenght <0){
bitlenght = 1230;//getbitlenght2() 1230;
}
pinMode(dataPin, OUTPUT);
digitalWrite(dataPin, HIGH);
delay(100);
digitalWrite(dataPin, LOW );
delay(500);
pinMode(dataPin, INPUT);
while(digitalRead(dataPin) == LOW){
}
while(digitalRead(dataPin) == HIGH){
}
while(digitalRead(dataPin) == LOW){
}
for (int i=0 ; i<42 ; i++){
data[i] = (digitalRead(dataPin) == LOW)? 48 : 49 ;
delay2(bitlenght);
}
showdatasimple();
return 0;
}
void showdatasimple(){
Serial.println("");
String Wind_Dir_PatternStr = "b";
String Wind_Dir_DescStr = "";
for (int i =8 ; i> 4 ; i--){
Wind_Dir_PatternStr += ((data[i] == 48)? 0 : 1);
}
Serial.print(Wind_Dir_PatternStr);
Serial.print(" = ");
if (Wind_Dir_PatternStr == "b0000") { Wind_Dir_DescStr="N"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[0], 255); }
if (Wind_Dir_PatternStr == "b0001") { Wind_Dir_DescStr="NNO"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[0], 255); }
if (Wind_Dir_PatternStr == "b0010") { Wind_Dir_DescStr="NO"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[1], 255); }
if (Wind_Dir_PatternStr == "b0011") { Wind_Dir_DescStr="ONO"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[2], 255);}
if (Wind_Dir_PatternStr == "b0100") { Wind_Dir_DescStr="O"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[2], 255);}
if (Wind_Dir_PatternStr == "b0101") { Wind_Dir_DescStr="OZO"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[2], 255);}
if (Wind_Dir_PatternStr == "b0110") { Wind_Dir_DescStr="ZO"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[3], 255);}
if (Wind_Dir_PatternStr == "b0111") { Wind_Dir_DescStr="ZZO"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[4], 255);}
if (Wind_Dir_PatternStr == "b1000") { Wind_Dir_DescStr="Z"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[4], 255);}
if (Wind_Dir_PatternStr == "b1001") { Wind_Dir_DescStr="ZZW"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[4], 255);}
if (Wind_Dir_PatternStr == "b1010") { Wind_Dir_DescStr="ZW"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[5], 255);}
if (Wind_Dir_PatternStr == "b1011") { Wind_Dir_DescStr="WZW"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[6], 255);}
if (Wind_Dir_PatternStr == "b1100") { Wind_Dir_DescStr="W"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[6], 255);}
if (Wind_Dir_PatternStr == "b1101") { Wind_Dir_DescStr="WNW"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[6], 255);}
if (Wind_Dir_PatternStr == "b1110") { Wind_Dir_DescStr="NW"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[7], 255);}
if (Wind_Dir_PatternStr == "b1111") { Wind_Dir_DescStr="NNW"; SoftPWMSet(ALL, 0); SoftPWMSet(lightbulbs[0], 255);}
Serial.println(Wind_Dir_DescStr);
Serial.println("");
//HEAD
for (int i =0 ; i< 5 ; i++){
Serial.print( ((data[i] == 48)? 0 : 1) );
}
Serial.print(" ");
//WINDDIR
for (int i =8 ; i> 4 ; i--){
Serial.print( ((data[i] == 48)? 0 : 1) );
}
Serial.print(" ");
//WIND SPEED
for (int i =17 ; i> 8 ; i--){
Serial.print( ((data[i] == 48)? 0 : 1) );
}
Serial.print(" ");
//WIND SPEED+3
for (int i =20 ; i> 17 ; i--){
Serial.print( ((data[i] == 48)? 0 : 1) );
}
Serial.print(" ");
//CC
for (int i =24 ; i> 20 ; i--){
Serial.print( ((data[i] == 48)? 0 : 1) );
}
Serial.print(" ");
//WIND DIR NEGATEIVE
for (int i =28 ; i> 24 ; i--){
Serial.print( ((data[i] == 48)? 0 : 1) );
}
Serial.print(" ");
//WIND SPEED NEGATIVE
for (int i =37 ; i> 28 ; i--){
Serial.print( ((data[i] == 48)? 0 : 1) );
}
Serial.print(" ");
//WIND SPEED NEGATIVE+3
for (int i =40 ; i> 37 ; i--){
Serial.print( ((data[i] == 48)? 0 : 1) );
}
}