Showing posts with label ethernet. Show all posts
Showing posts with label ethernet. Show all posts

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:


Friday, 14 December 2012

Ethernet!

Sure Electronics sells a cheap ($10) SPI Ethernet module based on the ENC28J60 controller. This is a different controller to the one in the Arduino Ethernet shield so isn't supported out-of-the-box by the Arduino IDE. (Interestingly it has no hardwired MAC address: you supply your own, the thinking presumably being that the odds of picking one already on your home LAN are effectively zero.)


I soldered a 6-way male connector to the small connector at the opposite end of the board from the RJ11 socket and stuck it in a breadboard for testing. Since this is an SPI device, only four connections are needed to the Arduino, besides power:

ArduinoSPIENC28J60
12MISOData Out
11MOSIData In
13SCLKClock
8CSChip Select

Luckily there is no shortage of libraries for it! I counted at least four during my search but settled on two. The first I found was by one Doctor Monk and worked pretty well, the only problem being that it only provides a web-server, not a general TCP/IP stack. 

The next one was EtherCard from JeeLabs which is downloadable at GitHub. Although it modestly claims to be a work-in-progress, it ships with fully 15 examples demonstrating everything from DHCP and DNS to Twitter and Pachube. The only gotcha I found with it was that its examples use pin 8 on the Arduino for Chip Select and I had been using pin 10 previously for this.