Preparing for Xmas…

What? Well somebody has to 😳

Apart from the G35 addressable RGB lights, I’m going to use some of these “Meteor Shower/Rain” LED lights in our porch – I had a play with them here. I have 4 lots of 8 x 30cm tubes so that should be enough to dangle in a small area.

Each set of 8 tubes seems to need no more than 250mA to drive it so powering all of this isn’t a big deal. What I do need to do is drill a hole into the loft space to bring out the 5V supply – that doesn’t seem to be a big deal (once I’ve been up there and found some leccy to use). I can’t say I really want to be going outside to switch them on and off though (or going up in the loft for that matter). I’ve been interested in radio devices for a while (I’ve bought various kinds but never really got anywhere with them) and it is an obvious solution – just hit a web page from phone/tablet/pc to turn the lights on and off.

I’ve had a fair few things now from Ciseco and their stuff seems to be very well though out. I have a URF Radio Module, a slice of radio (for raspberry pi) and an SRF Shield (the last two being part of a Kickstarter campaign). So, after a bit of research I decided to go for their RFμ-328 board and the developer board designed for it.

They’re very easy to use and the developer board seems very well though out to me – it’s a steal at £3.99 too!

Ciseco RFu-328 Developer Board

Ciseco RFu-328 Developer Board

For this application, I need (say) a 2A USB wall wart to drive the controller board and the lights (that gives plenty of headroom). The RFu-328 needs 3.3V so a voltage regulator is required. I decided to use on of my favourite logic-level N-channel MOSFET chips to switch ground for the LEDS and apart from that, a screw terminal and an LED to show on/off when testing that’s about it.

Finished board

Finished board

Luckily, Ciseco also sell a really good looking and great value case which I’ve housed the whole thing in.

I decided to use their LLAP protocol and library – maybe that’s abuse rather than use, but what the hell. The code was simple to generate and works really well (it is simple, so it should).

//////////////////////////////////////////////////////////////////////////
// LLAP N-Channel MOSFET Controller for XMAS Lighting
//
// Written for RFu-328
// Uses the Ciseco LLAPSerial library
//
//////////////////////////////////////////////////////////////////////////

#include <LLAPSerial.h>
#define DEVICEID "XM"    // LLAP device ID
#define RADIO_SELECT 8
#define PWR_PIN 6
int state = 0;
bool valid = false;

void setup() {
  Serial.begin(115200);
  pinMode(RADIO_SELECT, OUTPUT);  // switch on the radio
  digitalWrite(RADIO_SELECT, HIGH);
  delay(1000);                    // allow the radio to start
  pinMode(PWR_PIN, OUTPUT);
  digitalWrite(PWR_PIN, LOW);

/*  
  // One off commands to set device id then we can
  // program this device in the presence of others
  enterCommandMode();
  sendCommand("ATMYXM");
  sendCommand("ATAC");
  sendCommand("ATWR");
  sendCommand("ATDN");
*/

  LLAP.init(DEVICEID);
  LLAP.sendMessage(F("STARTED"));
}

void loop() {
  // Wait for message and act on it
  if (LLAP.bMsgReceived) {
    valid = false;
    LLAP.bMsgReceived = false;
    if (LLAP.sMessage == "ON-------") {
      state = 1;
      digitalWrite(PWR_PIN, state);
      valid = true;
    } else if (LLAP.sMessage == "OFF------") {
      state = 0;
      digitalWrite(PWR_PIN, state);
      valid = true;
    } else if (LLAP.sMessage == "TOGGLE---") {
      state = 1-state;
      digitalWrite(PWR_PIN, state);
      valid = true;
    } else if (LLAP.sMessage == "STATUS---") {
      valid = true;
    }
    
    if ( valid ) {
      LLAP.sendInt("STATUS", state);
    } else {
      LLAP.sendMessage("ERROR");
    }
    // Small delay to give the message time to get out
    delay(20);
  }
}

/*
The following code is taken from:
http://openmicros.org/index.php/component/kunena/10-ciseco-support/8009-changing-settings-of-srf-on-urf-rf-question?Itemid=0
*/

uint8_t enterCommandMode()
{
  Serial.print("+++");
  delay(500);
  while (Serial.available()) Serial.read();  // flush serial in - get rid of anything received before the +++ was accepted
  delay(500);
  return checkOK(500);
}

uint8_t sendCommand(char* lpszCommand)
{
  Serial.print(lpszCommand);
  Serial.write('\r');
  return checkOK(100);
}

uint8_t checkOK(int timeout)
{
  static uint32_t time = millis();
  while (millis() - time < timeout)
  {
    if (Serial.available() >= 3)
    {
      if (Serial.read() != 'O') continue;
      if (Serial.read() != 'K') continue;
      if (Serial.read() != '\r') continue;
      return 1;
    }
  }
  return 0;
}

I’ll get around to putting that on GitHub at some point. Also need to write a simple web interface for the raspberry pi with slice of radio that will look after all of my RFu-328 devices (I have plans, big plans, for multiple sensors and much more automation around the place).

So, apart from all the physical bits (small things like leccy, drilling holes, putting up hooks to hang the lights on 🙄 this counts as “job nearly jobbed” 😆

All that’s left for now is the “action” shot 🙂

Festive Fun!

Festive Fun!

The “black box” (upper-middle on the right) is the Ciseco project box with everything in. As well as being able to control it remotely it’s all possible (and necessary) to program it remotely too. I’m very impressed with this Ciseco stuff, I suspect it’s going to be damaging my credit card over the next few months 🙂

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*