Reprogramming the AAG RS485 Weather Station

I am resuming the discussion started here:

since this is probably a more appropriate place to continue it.

Basically, I'd like to replace the code in the AAG RS485 Weather Station because the suppliers haven't done a very good job exploiting its potential and they aren't very responsive to communication so they're not likely to improve it on their own. In their defense, they buy it preassembled from a Chinese supplier and they may not have a lot of control over it. Regardless, it's a nice piece of hardware and by definition "I own it" because I can take it apart and reprogram it. :slight_smile:

I've spent a little while figuring out the communication protocol and having done so, I have decided it can be improved. As it comes from the supplier, it has a half duplex RS485 transceiver chip for communication but uses a proprietary protocol that doesn't use the standard RS485 slave addressing method or as it is referred to in the Atmega literature, Multi-processor Communication mode (MPCM). I intend to change that as well as some other things that I consider are shortcomings.

It is a descendent of the 1-wire Dallas weather station, which AAG still make. One of the advantages of 1-wire is the ease by which networks of sensors can be wired, typically with cat5 cable. Sometimes when these networks get lengthy or "branchy" they aren't as reliable to communicate with. RS485 solves some of those problems but adds some of its own. For example, it doesn't easily provide a way to utilize existing 1-wire sensors.

It would be nice to be able to extend the 1-wire bus that currently exists inside the weather station (WS). There is a DS18S20 temperature chip inside that is virtually useless for outside temperature because the sealed enclosure heats up to over 140 degrees F on a sunny day. There is a feed-thru right by the chip that I will use to extend the 1-wire buss outside the enclosure. That way it can be used for ambient temperature and what ever other 1-wire sensors one might already have an want to use close to the WS.

I disassembled my WS this morning to try to get an idea just how hard it's going to be to "fix". The PCB is easy to remove with two connectors for communication and power. It's a 4 wire system, all though you wouldn't guess from the RJ45 that AAG connects with. They have +5VDC, +12VDC, and RS485 A and B wired to the connector but only +12VDC and RS485 are used. The logic part of the circuit draws very little current and regulates the +12 to +5 on board with a TO-92 style three terminal regulator. The +12 is used to power the 35 LEDS that one may or may not want to keep. I'm going to forget about the LEDS and I initially intend to reduce the Vcc to 3.3VDC.

The RS485 transceiver is accessible enough to put in a Hi-Z state so that I can initially program the Atmega8L with the Arduino boot loader. Currently, I think that will be the easiest way to start.

I broke the needle tip on my soldering iron so it will be a couple of days before I can start soldering on leads for the USB-serial interface. It has a 5-pin programming header already on the PCB.

As mentioned earlier, the processor is an Atmega8L and the clock is crystal controlled at 3.686MHz. I'll need some guidance about how to handle the initial reprogramming based on this clock speed. I'd like to end up with an 8MHz clock. The crystal is a through-hole.

Coding Badly and Graynomad have given me some good advice about how to proceed and I hope they and others keep doing that! :slight_smile:

crystal controlled at 3.686MHz. I'll need some guidance about how to handle the initial reprogramming based on this clock speed.

I'd replace the Xtal with a 16Mhz version as I doubt there's a bootloader set for 3.686. Maybe you can recompile one of the existing loaders though.

5-pin programming header already on the PCB

Curious, the standard ISP header is 6 pins.


Rob

Graynomad:

crystal controlled at 3.686MHz. I'll need some guidance about how to handle the initial reprogramming based on this clock speed.

I'd replace the Xtal with a 16Mhz version as I doubt there's a bootloader set for 3.686. Maybe you can recompile one of the existing loaders though.

Curious, the standard ISP header is 6 pins.


Rob

I had first thought I might want to leave the original crystal in and run the thing off 3V3 but after thinking it through, I won't be adding any 3V3 peripherals inside the case after all so I might as well make it 16MHz as you suggest. Since it's a through-hole crystal, it won't be a problem to replace.

The header is a single row with the normal pins minus +5V. Nothing these people do is standard. :slight_smile:

Looking at the data sheet for the Atmega8 under serial programming, it states that "If the device is clocked by the Internal Oscillator, it is no need to connect a clock source to the XTAL1 pin". When using an Arduino to program a target processor, is the target somehow placed in internal oscillator mode for programming?

Here is a schematic of the weather station.

I can't believe they have a patent on that simple circuit, that has to be a joke, doesn't it? Or am I missing something?

No wait, I see the clever bit, they have the current limiting resisters in the middle of the LEDs :slight_smile:

Anyway it looks easy enough to hack, for that matter you could use an Arduino (mini or some such) or make your own board.


Rob

Apparently it's the "atmage8" that provides the patent-able magic. (heh. see what I did there?)

Oh, I wasn't aware that you could patent a typo, in that case I'd better get busy with my applications because I can hardly type more than three words without erras :slight_smile:

And just to prove it, here's an unedited version of the above

Oh, I wasn;t aware that you could patent a typo, in that case I'd better bet busy with my applicaions because I can hadrly type more than three words without weerors.


Rob

Yeah, the whole patent thing is pretty funny. It's a Chinese patent so it may in fact be for the typo.

Anyway, I've got it open and I've soldered some leads to the TX/RX and RS485 enable pins so if I'm successful getting an Arduino bootloader into it, I can talk to it.

I've also hooked it up to an Arduino like it describes in the Arduinoisp sketch with the three LEDs and I've pulled the reset line up with a 150 Ohm resistor.

This is what I get when I run AVRDUDE.

pro:~ ejp$ avrdude -P /dev/cu.usbmodem621  -c arduino -p m8 -v -v

avrdude: Version 5.8cvs, compiled on Jan 15 2010 at 17:27:01
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/usr/local/CrossPack-AVR-20100115/etc/avrdude.conf"
         User configuration file is "/Users/ejp/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/cu.usbmodem621
         Using Programmer              : arduino
         AVR Part                      : ATMEGA8
         Chip Erase delay              : 10000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom         4    20   128    0 no        512    4      0  9000  9000 0xff 0xff
           flash         33    10    64    0 yes      8192   64    128  4500  4500 0xff 0x00
           lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 3
         Firmware Version: 3.3
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: Expected signature for ATMEGA8 is 1E 93 07
         Double check chip, or use -F to override this check.

avrdude done.  Thank you.

pro:~ ejp$

I can't believe they have a patent on that simple circuit, that has to be a joke, doesn't it? Or am I missing something?

In fact you can patent very much, the real question is if it will hold in court (that differs per country). One of the fuzziest criteria is (in my words) "that there must be something innovative not obvious for the skilled person". So a resistor in the middle may be innovative, but any electrical engineer can think of this as a solution, so it will probably won't hold in court. And of course if you find prior art, a (public) schematic that does the same with a verifyable older date, the patent is gone ...

As you can see from the schematic, there are 8 Hall effect devices going to inputs to the Atmega. The data sheet identifies them as open drain switches so even though they are attached to what we might normally assume are analog inputs they must be being used as digital inputs with internal pull-ups enabled.

On the circuit board the Hall effects are arranged on about a 25mm circle with 45 degrees between them. Above them rotates the little circuit board, whose picture I've attached, that is mounted to the end of the shaft that the vane rotates. Those little gray things will just fit between two of the Hall devices or will line up over two of the devices as the shaft rotates. I presume that when a magnet is between two of the Hall devices, both are switched on.

Now, the question is, how does one compute the direction of the vane pointer? The weather station reports 1 of 16 unique positions.

First question, why have 8 if they are spaced at 45 degrees, surely that means 4 of them are redundant?

Apart from that just read the value as a byte and have a switch statement to get the direction.

switch (reading)
0x12:
// north
0x23:
// north west

A bit ugly but will work.

Or have a loop that shifts and tests the reading's LSB.


Rob

EmilyJane:
Now, the question is, how does one compute the direction of the vane pointer? The weather station reports 1 of 16 unique positions.

You'll need to define one of the 'positions' as North - obviously this is installation dependent. The rest is basic trigonometry. Determining current position and direction of travel is most likely similar to handling rotary encoders.

Graynomad:
First question, why have 8 if they are spaced at 45 degrees, surely that means 4 of them are redundant?


Rob

I don't understand why you say 4 are redundant. How would you get 16 unique directions with only four switches? I see that 24 = 16 but I don't see that that helps.

Graynomad:
switch (reading)
0x12:
// north
0x23:
// north west

Where does "reading" come from?

I was thinking that with the HE sensors at 45 degrees they are effectively operating in pairs as you would always have both opposites on at the same time.

Would that not be the case?

I can see that if the magnet actuates adjacent pairs when it's in the centre that would double the resolution, but I still can't see the point in having sensors directly opposite each other.

"reading" is the value read from the IO port that these sensors are on. In this case PORTC, so

byte reading;

reading = PINC;
switch (reading)
0x12:
// north
0x23:
// north west

maybe "direction" is a better name.


Rob

So, if I number the HEs 0-7 like in the attached drawing and they are wired to PC0-PC7 for purposes of this discussion and the top of the drawing is North. Let's also assume that an activated HE has a value of "1", regardless of how we would accomplish that.

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

hall effects.jpg

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.

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