Pages: 1 2 [3] 4   Go Down
Author Topic: Reprogramming the AAG RS485 Weather Station  (Read 7726 times)
0 Members and 1 Guest are viewing this topic.
nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 129
Posts: 8601
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
so everything should go smoothly
He he.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
so everything should go smoothly
He he.

______
Rob

Yeah, that's the thought that went through my head, too. smiley
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13036
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley 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-grin
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. smiley
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
/*
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);
}
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13905
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17303
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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



Not likely. Hall effect sensors come in two varieties, those with a digital output and those with a analog output. Sounds like this weather station is using simple digital output hall sensors.

Lefty
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

They are Allegro 3144 which is now obsolete and replaced by the A1104. Unfortunately, like Lefty points out, they are digital devices, so no interpolation will be possible. Just from watching the wind vane while I had it up on a pole, the direction oscillated quite a bit. I don't know that wind direction is stable enough to warrant 5 degree resolution. Not Texas wind anyway. smiley We have a saying here, if you don't like the weather just wait 5 minutes.

That's an interesting idea though. If I ever decide to replace the circuit board, I could try linear Hall sensors.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13036
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I had a chance to play with the weather station and wrote this code to set up the ports and get wind direction.

Nice!


A suggestion and an idea.  Suggestion...

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

...very slightly simplifies displaying the wind...

Quote
 uint8_t d = make_wind(); // Sophomore humor.  Got to love it.  Hmm, I think I'll watch Shaun the Sheep tonight...
  d = match_wind(WD, d);
  Serial.println(windDirection[d]);


Idea... interpolating (guessing) the wind direction... By tracking the wind direction versus time, it is possible for the application to provide a guess at the exact wind direction.
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just finished modifying the board to include a 4K7 pull-up on the 1-wire pin. The DS1850 that I removed is obsolete too. The Chinese must have a stockpile of old parts. Or maybe they buy them up as they go obsolete.

I don't know if I'll put a temp sensor back inside the enclosure or not. It's useless for weather applications.

I removed 4 (of the 35!) LEDs just to give myself a little room to work. I may remove all of them. That will free up 6 I/O pins. Maybe I'll leave a couple as a warning to low flying birds or squirrels.  smiley
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
...very slightly simplifies displaying the wind...

So, if i don't get a match, I display "---"? That's a good idea. I think it's physically impossible to not have one of those patterns though. That would signal a problem with the circuit.

Quote
Idea... interpolating (guessing) the wind direction... By tracking the wind direction versus time, it is possible for the application to provide a guess at the exact wind direction.

That's an interesting idea. That would be helpful for displaying trends also. I'll work on that. I'll probably average wind speed over some period also.

Quote
Sophomore humor.  Got to love it.  Hmm, I think I'll watch Shaun the Sheep tonight...

Sometimes you get tired of meaningful function names and have to go with a little smile. smiley Makes life a treat!
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13036
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
We have a saying here, if you don't like the weather just wait 5 minutes.

Bah!  I grew up in the place that has the World's Record for the fastest temperature change.  Texas weather is slow and stable by comparison.   smiley-grin
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
We have a saying here, if you don't like the weather just wait 5 minutes.

Bah!  I grew up in the place that has the World's Record for the fastest temperature change.  Texas weather is slow and stable by comparison.   smiley-grin


Sounds like Gunnison. I used to have a house in Crested Butte and one day in Almont they measured -60! You had to keep your car battery indoors.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13905
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Quote
Idea... interpolating (guessing) the wind direction... By tracking the wind direction versus time, it is possible for the application to provide a guess at the exact wind direction.

That's an interesting idea. That would be helpful for displaying trends also. I'll work on that. I'll probably average wind speed over some period also.

Point of attention is if it alternates around 360 / 0 degrees,
The way I wouold approach it is count the number of times every individual sensor is triggered. There are 8 sensor so 8 counters, e.g. B00111111 means count[7]++ and count[6]++ . After a number of measurements a nice frequency diagram will come up from which the average can be derived.



Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: 1 2 [3] 4   Go Up
Jump to: