Pages: [1] 2 3 4   Go Down
Author Topic: Reprogramming the AAG RS485 Weather Station  (Read 7719 times)
0 Members and 1 Guest are viewing this topic.
Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am resuming the discussion started here:
http://arduino.cc/forum/index.php/topic,71206.msg530634.html#msg530634

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

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

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 129
Posts: 8596
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Quote
5-pin programming header already on the PCB
Curious, the standard ISP header is 6 pins.

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

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

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

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

Here is a schematic of the weather station.


* AAG WS Schematic.jpg (527.25 KB, 2624x1883 - viewed 107 times.)
Logged

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 129
Posts: 8596
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley

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
« Last Edit: September 06, 2011, 07:38:11 pm by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Seattle, WA
Offline Offline
Full Member
***
Karma: 1
Posts: 174
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 129
Posts: 8596
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley

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

Quote
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
« Last Edit: September 06, 2011, 08:54:28 pm by Graynomad » 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

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.

Code:
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$
« Last Edit: September 06, 2011, 09:45:02 pm by EmilyJane » Logged

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 222
Posts: 13857
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
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 ...
Logged

Rob Tillaart

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

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

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.


* magnets.jpg (309.05 KB, 2048x1536 - viewed 58 times.)
Logged

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 129
Posts: 8596
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Seattle, WA
Offline Offline
Full Member
***
Karma: 1
Posts: 174
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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.



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


Where does "reading" come from?
Logged

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 129
Posts: 8596
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

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