Reprogramming the AAG RS485 Weather Station

billcramer07:
The original Dallas 1-wire instrument used a DS2450 4 input A/D converter with 8 reed switches and rotating magnets to determine direction. Someone wrote a sketch to read the speed and direction with an Arduino. I am using it as part of my weather station. Find it here...

http://www.audon.co.uk/1-wire_weather.html

Maybe the new AAG instrument is using a similar method.

Your link didn't work for me. I believe the original 1-wire instrument switched resistors with its reed switches so as to get unique A/D readings for each direction. This one doesn't appear to be switching any resistors.

Yea the link is dead. I have the sketch and a schematic of the old wind instrument. I will post here.

Then if the rotor is pointing North, what would be the value of "reading"? If the rotor was pointing South, what would it be?

North = 0 and 4 on = 00010001
South = 4 and 0 on = 00010001

That's my point.

East of north = 0,1 and 4,5 = 00110011
West of south = 4,5 and 0,1 = 00110011

So you have better resolution but again, I don't see how you can tell the difference.

Unless I'm missing something here (it wouldn't be the first time :)) you have to remove one of the magnets.


Rob

I believe the original 1-wire instrument switched resistors with its reed switches so as to get unique A/D readings for each direction.

That would make a difference. Still I think removing a magnet would be easier. Maybe add a similar weight to keep the balance.


Rob

Graynomad:

I believe the original 1-wire instrument switched resistors with its reed switches so as to get unique A/D readings for each direction.

That would make a difference. Still I think removing a magnet would be easier. Maybe add a similar weight to keep the balance.


Rob

Very good. That's exactly what those inscrutable Chinese did. That gray thing that looks exactly like the other one is a dummy. Only one is a magnet.

I'm proud to say I figured it out before I actually verified it. Like Sherlock Holmes said, whenever you've exhausted all the possibilities, whatever is left, no matter how improbable, is the answer.

So maybe that's what the patent is for. :slight_smile:

He he, do I get a prize :slight_smile:


Rob

Graynomad:
He he, do I get a prize :slight_smile:


Rob

Sorry, no. :slight_smile: Good job, though!

The remaining mystery to me is why they went to such trouble to hide what they are doing. The dummy looks EXACTLY like the real magnet. It's like they had a big batch of defective ceramic magnets to use up. The rotor that operates the HE for wind speed does have two functional magnets and looks identical to the Wind direction rotor. Curiouser and curiouser.

I'm still left with the problem of reprograming the stock chip. Anyone with any suggestions about that please step in.

reprograming the stock chip

I'd buy a $20 programmer like this

from Pololu or someone (there are a few around) and make up a 6-way to 5-way cable.


Rob

Graynomad:

reprograming the stock chip

I'd buy a $20 programmer like this

http://www.pololu.com/catalog/product/1300

from Pololu or someone (there are a few around) and make up a 6-way to 5-way cable.


Rob

I might end up doing that but there's no reason why I can't use an Arduino for this project unless the manufacturer has burned the fuses to disable reprogramming.

EmilyJane:
The remaining mystery to me is why they went to such trouble to hide what they are doing. The dummy looks EXACTLY like the real magnet. It's like they had a big batch of defective ceramic magnets to use up. The rotor that operates the HE for wind speed does have two functional magnets and looks identical to the Wind direction rotor. Curiouser and curiouser.

Unlikely that they're hiding anything. Perhaps a counterweight? Provided for balance?

EmilyJane:
I'm still left with the problem of reprograming the stock chip. Anyone with any suggestions about that please step in.

Adafruit sells a little ISP programmer (usbtiny) that should do the job nicely. It's supported directly by avrdude.

BTW, the Bus Pirate that I mentioned yesterday also fulfills this purpose. Also supported by avrdude. Just sayin'...

Oh, and my earlier suggestion regarding position is based upon experience with my own AAG weather station. You really don't get a useful position until it moves.

buzzdavidson:

EmilyJane:
The remaining mystery to me is why they went to such trouble to hide what they are doing. The dummy looks EXACTLY like the real magnet. It's like they had a big batch of defective ceramic magnets to use up. The rotor that operates the HE for wind speed does have two functional magnets and looks identical to the Wind direction rotor. Curiouser and curiouser.

Unlikely that they're hiding anything. Perhaps a counterweight? Provided for balance?

EmilyJane:
I'm still left with the problem of reprograming the stock chip. Anyone with any suggestions about that please step in.

Adafruit sells a little ISP programmer (usbtiny) that should do the job nicely. It's supported directly by avrdude.

BTW, the Bus Pirate that I mentioned yesterday also fulfills this purpose. Also supported by avrdude. Just sayin'...

Oh, and my earlier suggestion regarding position is based upon experience with my own AAG weather station. You really don't get a useful position until it moves.

Those are all good suggestions. Thank you!

Well, I'm going to call it a night.

buzzdavidson:

EmilyJane:
The remaining mystery to me is why they went to such trouble to hide what they are doing. The dummy looks EXACTLY like the real magnet. It's like they had a big batch of defective ceramic magnets to use up. The rotor that operates the HE for wind speed does have two functional magnets and looks identical to the Wind direction rotor. Curiouser and curiouser.

Unlikely that they're hiding anything. Perhaps a counterweight? Provided for balance?

EmilyJane:
I'm still left with the problem of reprograming the stock chip. Anyone with any suggestions about that please step in.

Adafruit sells a little ISP programmer (usbtiny) that should do the job nicely. It's supported directly by avrdude.

BTW, the Bus Pirate that I mentioned yesterday also fulfills this purpose. Also supported by avrdude. Just sayin'...

Oh, and my earlier suggestion regarding position is based upon experience with my own AAG weather station. You really don't get a useful position until it moves.

I'm sure it's a counterweight as you suggest but it is made out of the same material that the magnet is made from. Maybe they are readily available from another process/product.

I finally got avrdude/ArduinoISP to talk to the WS but I'll probably order one of the Adafruit programmers to use in the future. The problem was I needed to over-ride the baud rate in avrdude. Coding Badly figured that one out.

The new AAG will be even easier to determine wind direction now that I realize that there is only one magnet. It will work when the vane is stopped as well.

I decided to go ahead and bump the clock frequency up to 16 MHz so as soon as a crystal arrives, I'll get back on this project. I'll be using a USBtinyisp and a USB/TTL serial interface instead of an Arduino for programming and communication also, so everything should go smoothly.

so everything should go smoothly

He he.


Rob

Graynomad:

so everything should go smoothly

He he.


Rob

Yeah, that's the thought that went through my head, too. :slight_smile:

Bah. You two are pessimists. What could possibly go wrong?

An old boss helped design and build the control system for a very large tank farm. While driving to the plant for the startup, he stopped at 7-Eleven and picked up a stack of job applications ... just in case things went poorly.

:slight_smile: Funny story.

If I didn't break anything and the schematic diagram is correct it really should go smoothly. With the FTDI bridge and a 16 MHz clock, it should look exactly like an Arduino NG with LEDs on every pin. :smiley:

Well, I've got an Arduino bootloader programmed into the AAG Atmega8 now and am just playing around with the on-board hardware. I'm programming it from the IDE through an FTDI USB/serial bridge with a 100nF capacitor from DTR to reset. The first thing I have noticed is that the schematic is wrong for P1, the photocell. On the schematic it should show R20 (3K0) and P1 reversed. The 3K0 resistor goes to Gnd and the photocell goes to +5 volts. If you're is playing along at home, you'll want to change your schematic. :slight_smile:

I had a chance to play with the weather station and wrote this code to set up the ports and get wind direction. I created an array of bytes to hold the 16 possible states of the Hall effects. Either one Hall effect is triggered or two are when the magnet is between two of them. The 16 states map into a string array that corresponds to the 16 directions.

Next I will get the 1-wire temperature working and wind speed and then it will be at the same point where I took it apart.

AAG wired the DS1850 directly into PD5 with no pull-up resistor so I'm going to re-wire it with one so I can have a proper 1-wire bus to extend outside the enclosure. I don't have too much flash so I'm going to have to work on the 1-wire code to make it as slim as possible.

/*
PC0-PC5 PD6-PD7 = Q1-Q8  Wind Direction
 PD5 = 1-Wire DS18B20
 PD4 = Q9 Wind Speed
 PD2 = DD RS485 Data Direction
 PD1 = TXD
 PD0 - RXD
 ADC7 = P1 Photocell Schematic wrong actually pulls up to 5V
 ADC6 = Voltmeter
 */

#define ADC6  6
#define ADC7  7

const char* windDirection[16] = { // strings for the 16 wind directions
  "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW",\
  "SW", "WSW", "W", "WNW", "NW", "NNW"};

uint8_t WD[16] =  { // Hall effect outputs for 16 wind vane positions
  B01111111, B00111111, B10111111, B10011111, B11011111, B11001111,\
  B11101111, B11100111, B11110111, B11110011, B11111011, B11111001,\
  B11111101, B11111100, B11111110, B01111110};


uint8_t match_wind(uint8_t* mask_array, uint8_t mask){ // match wind direction mask with array of possibles
  for (uint8_t i=0; i<16; i++)
    if (*mask_array++ == mask)
      return i; // return match which corresponds to string array index too
  return 16; // signal no match. 
}

uint8_t make_wind(void){ // build mask for wind direction
  uint8_t temp = PINC; // read Q1-Q6(PC0-PC5)
  temp &= B00111111; // clear bits 6 and 7
  temp |= (PIND & B11000000); // OR on Q7-Q8(PD6-PD7) bits
  return temp;
}

void setup() {
  Serial.begin(9600);
  DDRC &= B11000000; // PC0-PC5 = inputs (Wind Direction)
  PORTC |= B00111111; // switch on pull-up resistors
  DDRD &= B00001011; // PD4, PD5, PD6, PD7 = inputs (Wind Direction and Speed + 1-Wire) PD2 temporarily for RS485 disable
  PORTD |= B11110000; // switch on pull-up resistors
}

void loop(){ 
  int photocell = analogRead(ADC7);
  Serial.print(photocell, DEC);
  delay(1000);
  int voltmeter = analogRead(ADC6);
  Serial.print('\t');
  Serial.println(voltmeter, DEC);
  delay(1000);

  uint8_t d = make_wind(); // ;-)
  d = match_wind(WD, d);
  if (d < 16)
    Serial.println(windDirection[d]);
  else Serial.println("Invalid Direction");
  delay(1000);
}

Is it possible to read the strength of the hall sensors? (now I see only 0/1)

If so these could be used to interpolate between the values. The 16 wind directions are steps of 360/16 = 22.5, if interpolation is possible you may could get to 5 degrees accuracy