Design patterns and system design

Hi all

I come from a programming background and am really new to this whole programming + electronics malarky. There are loads of different design patterns (not to mention books espousing them) giving your average coder and idea of how to structure their code.

For example, the Model-View-Controller (MVC) pattern is incredibly popular, particular when it comes to the web. It separates what the user sees and interacts with a.k.a. the UI (View) from the persisted data objects (Model). The final part, Controller, contains the remaining bits, e.g. business logic.

My question is whether design patterns exist when it comes to electronics/physical computing. There's the potential to build some pretty complex devices with the 'duinos, sensors, ethernet, wireless, computers etc. It'd be great to know what could and should live where.

As an example I'm planning to put together a couple of sensors to measure the electricity, gas and water usage in my house. I'm thinking that each sensor will be hooked up to a 'duino with a wireless shield. These sensor units will then talk to a base unit which I'll be able to interrogate with a computer (either using ethernet or wirelessly - 802.11). Ideally the PC <-> comms should be able to be achieved using a simple web browser.

I've read that some of the ethernet/wireless shields can act as web but servers but I'm wondering how much processing/serving I'll be able to do on the board. Would I be better off getting the base unit simply to interrogate the sensors, store the data (to an SD) and then have a Processing sketch talk to the base unit.

I hope all of that makes sense. As with most things I suspect that there's not a single answer but any advice will be very gratefully accepted.

Hi,
Well you allways try to design beatiful systems, but remember beauty is in the eye of the beholder. I beleive you recognise that from the software world.

The designs I like have a simple structure, if you have to add a lot of stuff around your design, there is probably a better way to do it.
My view is that beauty lies in minimalising and repeating simple structures.

Then remember, you hear a lot of rules, design this way or that way, but the truth is that it is more guidelines.
To make a beautiful design, you need to break one guideline, because following it would make your design ugly.

Then you make your end devices as simple possible. Don't put anything there that can be done at a higher level in the system.

Magnus

If you are measuring a few sensors and doing a simple web server I would be surprised
if a single Arduino could not handle it. You would not be parsing long strings or sending back a large amount text.

Another thing to consider is that for monitoring a simple sensor and transmitting the
data you probably do not need an Arduino. Radios that support protocols like Zigbee (which is used for sensor networks) usually have an embedded uC with digital I/O and
analog monitoring. The radio can be configured to periodically measure and transmit readings. Checkout the MaxStream XBee datasheet and the O'Reilly book "Making Things Talk". With a radios on the sensors all you need is a radio on your PC.

If you do decide you want an Arduino with a radio I make one with a socket for a MaxStream XBee --- Loading...

(* jcl *)

The plan is to also do some interpretation of the data, e.g. graphing, and serve up that interpreted data within an HTML page.

I'd also like to be able to store the data for quite some time without having to archive it to say a PC.

I'm wondering if I'd be able to use an SD card for both storing HTML pages (for inserting data into) and also for storing the data.

Jluciani > I was thinking about using an XBee but they seem quite pricey compared to say an FM TX/RX pair. I think that Wattson Energeno design and manufacture products and services to assist people to maximise the efficiency of their energy usage and energy generation both online uses FM to transmit from the sensor to the display unit. Would that mean that only a single sensor could be used...?

At $20 the XBee is pricey. It is extremely simple to use.
If your sensors are in close proximity you may be able
to use a single XBee to interface all of your sensors to a
single XBee.

How big are your webpages and how much data are you
planning store. Are you sure you can't store everything in
the ATmega? The new ATmega328 works in the ATmega168
socket and gives you an extra 16K of flash.

The SD card should not be a problem if you need that much
storage.

(* jcl *)

Sensors are gonna be a bit all over the place unfortunately and with at least 3 I'm keen to explore other possibilities.

Not sure how big the pages are but to give a rough idea this page is ~32k. Mine wouldn't be quite as text heavy but ideally I'd create them ahead of time and store them rather than have them created programmatically.

It looks like the ethernet shield will function as a webserver although I'm assuming that it doesn't have any more storage than the 'duino.

Having the page stored is what I do.

I created a little server application that serves a webpage and then outputs a submitted
string to an XBee attached to a USB port. The reply from the XBee is added to the webpage. The bulk of the page is stored. I programmatically add a few rows to a table.

The page I store is 250bytes (see the code below).

<html>
<head>
</head>
<body>
<h1>wiblocks XB2</h1>
<table>
<tr>
<td>
Send
<td>
<form  method=GET action="write">
<input TYPE=text name=q size=20 maxlength=255 value="">
<input type=submit name=btnG bgcolor=cyan VALUE="SEND">
</table>
</body>
</html>

Jcl, to be honest that's a lot less than I'm expecting to be outputting (hopefully I'll be able to productise this in the long run). There shouldn't be any issue about using an SD card to store HTML though should there....?

Are there any other storage solutions available, e.g. increased EEPROM sizes?

Jcl, to be honest that's a lot less than I'm expecting to be outputting (hopefully I'll be able to productise this in the long run).

That was just a simple example page. I would expect that your page size would be
a lot closer to the 2K-3K range rather than the 20K-30K range. If you start to
add images and graphs my estimate would be way off.

There shouldn't be any issue about using an SD card to store HTML though should there....?

I don't see any issues with using a SD card. IIRC there is an app-note and library
on the web.

Are there any other storage solutions available, e.g. increased EEPROM sizes?

You can increase EEPROM my changing an ATmega168 to an ATmega328.
You could also add an external EEPROM. If you are going to add an external
EEPROM I would use the SD card instead.

Using the SD card would give experience with that technology and easy expansion
options.

(* jcl *)