Ideas for an integrated system

I'm promised some people that I would post my set-up on these boards. My system is still in development (when isn't it?) but I'm also curious on getting some feedback and maybe more ideas on the best way to implement a home automation system.

Ultimately, I would like to have various sensors and actuators working on a wireless mesh network that has the ability to communicate through Ethernet, likely with an Android device. So far, I do have sensors and actuators (relays) talking to each other and working in conjunction, and I'm working on a "network bridge" that will translate between the wireless signals and Ethernet to allow my Android to talk to these devices as well. Inspiried by the JeeNode, I made my own based on the ATTiny84:

It's as simple as it looks. An ATTiny84 connected to an RFM12B transceiver. DigiKey carries the chip for ~$2 each while you can find the transceiver for around $6.

I also made a "programming/prototyping" shield that breaks out the ISCP connectors, a reset button, and a handful of solder holes that can be used to prototype. Here is a picture of my light sensor that I've created using this "shield."

I designed an actual "sensor" shield that gives you some room to add a few analog/digital sensors and one of these coincell batteries, just waiting to get them in the mail.

So right now, I have the above pictured board sitting in my window reading and sending the light level every minute. There is another base unit with a relay (shield also on the way) and a cannibalized cheap USB power adapter inside my light switch box, effectively creating dusk-to-dawn porch lights that also have the potential to be controlled through Ethernet (via RF).

I've found that while the transceivers aren't rated for 5V, they can run off of them. I don't assume they'll run forever, so the relay shield has an LDO regulator on it.

Here are the sketches, as an example for how simple these things are, for the light sensor and the relay:

/* TinyLight.ino
 * Small wireless sensor that will send out the data for a single light sensor every 65 seconds
 * and sleep the system in between.
 */
#include <JeeLib.h>

// Initializes an interrupt routine to allow for easy sleeping
ISR(WDT_vect) { Sleepy::watchdogEvent(); }

// The struct that will carry our packet
typedef struct {
  unsigned long id;
  int value;
} Payload;
 
Payload payload;

const int netID = 23; // The network ID
const int nodeID = 1; // The node ID
const unsigned long lightID = 0xA0000001; // id of our light sensor
const int lightPin = 0; // The pin that our sensor is connected to

void setup () {
  // Initialize our rf12 library
  rf12_initialize(nodeID, RF12_433MHZ, netID);
  rf12_sleep(0); // Put the node to sleep
  payload.id = lightID; // set the sensor id in our struct
}

void loop () { 
  payload.value = analogRead(lightPin); // get light level
  
  rf12_sleep(-1);     //wake up RF module
  while (!rf12_canSend()) // wait until we can send 
    rf12_recvDone();
  
  // Send our payload
  rf12_sendStart(0, &payload, sizeof payload); 
  rf12_sendWait(2);    //wait for RF to finish sending while in standby mode
  rf12_sleep(0);    //put RF module to sleep
  Sleepy::loseSomeTime(65000); // Put to sleep for 65 seconds
}
/* TinyRelay.ino
 * Listens for a certain light sensor ID. Uses the TinyRF header to abstract
 * the parsing of the rf12 signals and assign the value of the sensor that we
 * receive from the RF to a variable
 */
 
#include <JeeLib.h>
#include "TinyRF.h" // Simple library to 
#define LENGTH_OF_PAYLOAD 10

const int netID = 23; // The network ID
const int nodeID = 2; // The node ID

const int relayPin = 9; // drives the relay
const int rxPin = 3; // led to signify we received something

const unsigned long lightID = 0xA0000001; // id of the sensor we're looking for

int lightLevel=500; // keeps track of the the current light level
const int darkLimit = 600; // When this light level is reached, turn off
const int lightLimit = 300; // When this light level is reached, turn on

void setup() {
  pinMode(relayPin, OUTPUT);
  pinMode(rxPin, OUTPUT);
  rf12_initialize(nodeID, RF12_433MHZ, netID);
  /* Whenever we receive an update for our lightID, store the value in our
   * lightLevel variable */
  tinyrf_subscribe(lightID, &lightLevel);
  
}
 
void loop() {
  static int relayState = LOW;
    
  if (rf12_recvDone() && rf12_crc == 0) {
    digitalWrite(rxPin, HIGH);
    // send data to update any variables we've subscribed to
    tinyrf_checkinc(rf12_data, rf12_len);
    delay(50);
    digitalWrite(rxPin, LOW);

    if (lightLevel > darkLimit)
      relayState = LOW;
    else if (lightLevel < lightLimit)
      relayState = HIGH;
  }
  
  digitalWrite(relayPin, relayState);
}

This is the header that just abstracts some of the checking and allows me to "subscribe" a variable to updates for a certain sensor ID.

#ifndef TinyRF_h
#define TinyRF_h

#include <JeeLib.h>

#define rf_ids_match(A,B,C) (((uint16_t*)A)[0] == B[C].id)
#define MAX_SUBS 5

typedef struct {
  uint16_t id;
  int * var;
} Sub;

Sub subs[MAX_SUBS];
byte subCount=0;

void tinyrf_subscribe(uint16_t id, int *var) {
  subs[subCount].id = id;
  subs[subCount].var = var;
  subCount++;
}

void tinyrf_checkinc(volatile uint8_t *inc, int len) {
  if (len !=6) return;
  for (int i=0; i<subCount; i++) {
    if ( rf_ids_match(inc, subs, i) )
      *subs[i].var = ((int*)(inc+4))[0];
  }
}

#endif

Anyone have any insight on things I haven't considered? Maybe an angle that I am missing? Question? Comments? Emotional outbursts? If anyone is interested in the eagle files, I'm not shy about sharing those as well.

Nice job by the looks of it. The PCB looks very professional.

I've often thought about using the Jee stuff, are you happy with it? I gather you are using their code but your own modules.

Where does the magic ID number (0xA0000001) come from?


Rob

Graynomad:
Nice job by the looks of it. The PCB looks very professional.

I've often thought about using the Jee stuff, are you happy with it? I gather you are using their code but your own modules.

I just use it for the RFM library, I haven't actually used any devices or any of the Ports libraries. Otherwise, the library has worked very well and I have been running the dusk-to-dawn porch light for months now (on a single coincell using their sleep code) and have had no issues.

Where does the magic ID number (0xA0000001) come from?

Where any other magic number comes from, of course, right out of thin air! :wink:

I just have been assigning any "sensor ID" to an unsigned long number that can be recognized individually on the network.

Hi,

great board. I'm working on an Home Automation project that may fit yours requirements.

It has routing and bridging functionalities embeed in the network layer plus a binary p2p protocol an home automation ready to use logics.

Isn't include yet the drivers for the radio that you are using, but isn't hard attach new drivers.

The project is called Souliss, you can find details on this forum or on the project website.

Let me know if you are interested in.

Regards,
Dario.

veseo:
Hi,

great board. I'm working on an Home Automation project that may fit yours requirements.

It has routing and bridging functionalities embeed in the network layer plus a binary p2p protocol an home automation ready to use logics.

Isn't include yet the drivers for the radio that you are using, but isn't hard attach new drivers.

The project is called Souliss, you can find details on this forum or on the project website.

Let me know if you are interested in.

Regards,
Dario.

I would definitely be interested in integrating a framework like that with all my hardware. I noticed that it includes support for the ENC28J60. I've been looking into working with that, a 328P, and the transceiver to create the Ethernet to wireless bridge, so if there was support for these transceivers, then I wouldn't have to re-invent the wheel.

Looking at the documentation, however, it looks like the library uses > 700 bytes of RAM, which would be a problem because the Tinys only have 512.

Hi,

The minimum amount of RAM is 700 bytes, the maximum 2 kbytes. These values contains about 300 bytes consumed ny the standard Arduino bootloader.
Souliss is designed around the Atmega328, I've forget your tiny uC.

The main problem is the ENC28J60, because require a software TCP/IP stack. You need a full hardware Ethernet solution, like W5100.

Consider that in a communication stack most of your RAM is used in data buffer.

Regards,
Dario.

veseo:
Hi,

The minimum amount of RAM is 700 bytes, the maximum 2 kbytes. These values contains about 300 bytes consumed ny the standard Arduino bootloader.
Souliss is designed around the Atmega328, I've forget your tiny uC.

The main problem is the ENC28J60, because require a software TCP/IP stack. You need a full hardware Ethernet solution, like W5100.

Consider that in a communication stack most of your RAM is used in data buffer.

Regards,
Dario.

Well (typically) only one Ethernet/RF bridge would be needed, it's not tough to justify the added cost of the W5100,

I guess I'll have to continue developing the software if there is noway to get the code to fit with a tiny.

Yes, there is a plan for RAM reduction but it will not lower the use to fit a tiny.

Feel free to look at the code and reuse it.

Regards,
Dario.y

These values contains about 300 bytes consumed ny the standard Arduino bootloader.

Which must be released so it doesn't count does it?


Rob

Graynomad:

These values contains about 300 bytes consumed ny the standard Arduino bootloader.

Which must be released so it doesn't count does it?


Rob

I've just get the total Ram used statically some time ago, and added these 300 bytes.

I've read some where that Ram was used in the bootloader.

The best option is compile the code as required and look again for Ram used, because the values are related to the first release of Souliss.

Let me say that a software tcpip, as required by ENC28J60, needs at least 160 bytes only for the data buffer. So it is an hard challange place all the code in a 512 bytes uC

Regards,
Dario.

veseo:
Let me say that a software tcpip, as required by ENC28J60, needs at least 160 bytes only for the data buffer. So it is an hard challange place all the code in a 512 bytes uC

I have no plans to integrate the Ethernet modules with the 84s; those would be used with a 328. The 84s are just used as wireless nodes that can gather or respond to commands, such as switches and sensors.

This looks very interesting.
I'm looking for something very similar to this setup.

what kind of reliability/distance does this setup give you?

You mentioned the price of the chips, but where did you order the PCB from? and at what price?

qwerdy:
what kind of reliability/distance does this setup give you?

Pretty reliable and enough distance to cover my entire house and yard. I haven't done any tests to check the distance because it's being used in Home Automation products, but I might check to see how far I can get it just out of curiosity.

You mentioned the price of the chips, but where did you order the PCB from? and at what price?
Board was a custom design.

Arrch:
Board was a custom design.

That i got, but where do one order custom ones?
I would really like to have a couple of this to play around , and test with.

qwerdy:
That i got, but where do one order custom ones?
I would really like to have a couple of this to play around , and test with.

If you're asking for the name of a fab house where you can have custom boards made, then there are a bunch such as SeeedStudio, BatchPCB, etc.

If you're asking for where to buy these specific ones that I've made, then you can PM me with your info.