Monday 29 July 2013

Weather Guy


The picture shows a little Weather Station based around an ATmega328. What makes this one interesting is that it gets its weather data from Yahoo! Weather rather than a bunch of sensors. What's interesting about that (to paraphrase Dr Johnson) is that it can be done at all on an 8-bit microcontroller.

The hardware components of this system are not worth drawing a circuit diagram for:
  • Basic ATmega328 with 16MHz crystal and 22pF balancing capacitors (you know the score)
  • An ENC28J60 ethernet module (e.g., from eBay)
  • An ST7735 TFT display with SD-card (e.g., from Adafruit)
  • Stripboard, connectors, etc.
  • Err, that's it!
The software is where the real action lies. This baby (a 600+ line sketch!) crams in the following libraries:
The restrictions of the AVR chip steered the implementation in interesting directions:
  • All string constants stored in flash, using either F() or PSTR().
  • Using the TFT screen for debugging rather than Serial (saves 128 bytes RAM).
  • Graphics downloaded from Yahoo! in advance, converted into bitmaps and stored on a cheap SD card.
  • Buffer-sharing between the XML parser and reading from the SD-card. (In particular, most SD-card libraries require their own 512-byte buffer for output, see this earlier post.)
  • Reclamation of some flash on the AVR using Optiboot.
  • Displaying wind-direction without using transcendental functions (i.e., sin, cos) used the nice trick of successive rotations. (This is apparently due to the legendary Marvin Minsky, in hakmem 149.)
There is almost no free space left on the chip: just under 200 bytes of RAM (which I guess is needed for the stack) and 512 bytes of flash!

Here's another picture showing forecast data:


3 comments:

  1. Hey, I'm at the moment looking around how to use ST7735 TFT display with SD-card, can you please help or just give an usefull link how to simple implement a code for avr atmega328p just for use this display?
    When i search i found lots of tuturials and code for arduino, but i want to work only with avr...
    Thanks from now, simple reply to this post and thanks :)

    ReplyDelete
    Replies
    1. Convert the Adafruit libraries from C++ to C: pretty easy I reckon.

      You can find lots of C libraries for SD cards, check out Petit FatFs. It also provides an SPI implementation which you can re-use to support your converted Adafruit_GFX library.

      More info on available choices here: http://programmablehardware.blogspot.ie/2013/07/accessing-sd-cards-from-microcontrollers.html

      Delete
    2. Really thanks for your fast reply, the idea of translate adafruit libraries as good! I started this job, but after another search i found this amazing work.. that includes adafruit libraries already translated:
      http://people.ece.cornell.edu/land/courses/ece4760/FinalProjects/s2012/bth44_pb334/bth44_pb334/index.html

      Delete