Gamebuino Home Automation Demo

Show us your Gamebuino clone or the last module you made.

Gamebuino Home Automation Demo

Postby Myndale » Tue Jul 14, 2015 8:09 am

Quick little demo I wrote over lunch to control a Watts Clever power adapter using a Gamebuino with a standard 434MHz ASK transmitter chip:



It's a reasonably cheap solution to the problem of high-voltage control, the transmitter is usually around $5 and the adapters start at $10. The main problem with any RF hack is that legislation (and thus hardware) will differ across countries, so while this can be made to work with other types of adapter you'll need to modify the code to send the appropriate signals. I used a logic analyser to capture the signal for this adapter but you could also use any of the numerous IR capture/playback libraries normally used for TV remotes.

These are still cheap and nasty devices, so a little common sense should always prevail. While safer than plugging directly into a 240V relay I still wouldn't plug an oven in and head on down to the pub! ;)

Gamebuino code:

Code: Select all
// GBAUTO - Gamebuino Home Automation
// by Myndale (simbuino@ppl-pilot.com)
//
// This demo enables Gamebuino control of  Watts Clever RF power adapters
// (see https://www.wattsclever.com/au/products/easy-off-sockets).
// It requires a standard 434MHz ASK transmitter chip with the data pin tied to the Gamebuino's I2C SDA pin (analog 4).


#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

#define TX A4
#define DATA_PORT PORTC
#define DATA_BIT (1 << 4)

#define ON 0
#define OFF 1

const char * commands[][2] =
{
  {"0011001011111101110111100", "0011001011111101110101100"},             
  {"0011001011111101110111000", "0011001011111101110101000"},             
  {"0011001011111101110110100", "0011001011111101110100100"},             
  {"0011001011111101110110010", "0011001011111101110100010"}                 
};

boolean states[] = {false, false, false, false};

void titleScreen()
{
  gb.titleScreen(F("Gamebuino Automation"));
}

// the setup routine runs once when Gamebuino starts up
void setup(){
  gb.begin();
  pinMode(TX, OUTPUT);
  titleScreen();
}

// the loop routine runs over and over again forever
void loop() {
  if(gb.update())  {
    if(gb.buttons.pressed(BTN_C))
        titleScreen();
    if (gb.buttons.pressed(BTN_UP)) states[0] ^= true, transmit(0);
    if (gb.buttons.pressed(BTN_LEFT)) states[1] ^= true, transmit(1);
    if (gb.buttons.pressed(BTN_RIGHT)) states[2] ^= true, transmit(2);
    if (gb.buttons.pressed(BTN_DOWN)) states[3] ^= true, states[0] = states[1] = states[2] = states[3], transmit(3);
    drawButton(42,  9, F(" 1 "), states[0]);
    drawButton(27, 24, F(" 2 "), states[1]);
    drawButton(57, 24, F(" 3 "), states[2]);
    drawButton(42, 39, F("All"), states[3]);
  }
}

void drawButton(const byte x, const byte y, const __FlashStringHelper * text, boolean state)
{
  gb.display.setColor(state ? BLACK : WHITE);
  gb.display.fillCircle(x, y, 8);
  gb.display.setColor(BLACK);
  gb.display.drawCircle(x, y, 8);
  gb.display.cursorX = x - 5;
  gb.display.cursorY = y - 2;
  gb.display.setColor(INVERT);
  gb.display.println(text);
}

void delayUs(volatile unsigned uS) {
  while (--uS) {
    __asm__ __volatile__ (
      "nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop \n nop"
    );
  }
}


void zero() {
  DATA_PORT |= DATA_BIT;
  delayUs(117);
  DATA_PORT ^= DATA_BIT;
  delayUs(489);
}

void one() {
  DATA_PORT |= DATA_BIT;
  delayUs(425);
  DATA_PORT ^= DATA_BIT;
  delayUs(181);
}

void transmit(const byte channel)
{
  const char * signal = commands[channel][states[channel] ? ON : OFF];
  noInterrupts();
  for (int i=0; i<5; i++)
  {
    const char * c = signal;
    while (*c)
    {
      if (*c++=='1')
        one();
      else
        zero();
    }
    delayUs(4237);
  }
  interrupts();
  if (states[channel])
    gb.sound.playOK();
  else
    gb.sound.playCancel();
}
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am

Re: Gamebuino Home Automation Demo

Postby Sorunome » Tue Jul 14, 2015 9:31 am

Haha, that is quite awesome, i love it!
User avatar
Sorunome
 
Posts: 629
Joined: Sun Mar 01, 2015 1:58 pm

Re: Gamebuino Home Automation Demo

Postby rodot » Tue Jul 14, 2015 10:10 am

For sure it's awesome, I shared it on Gamebuino's Facebook page, I hope you don't mind :)
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Gamebuino Home Automation Demo

Postby steevemadison » Fri Jul 17, 2015 1:23 pm

nice application for the gamebuino , i trying to adapt this code for my ac outlet , it's a different code
(i'm a very noob at this arduino world) , here what i get from from my remote

chipset HS2260A

Decimal: 5517763 (24Bit)
Binary: 010101000011000111000011
Tri-State: FFF0010F1001
PulseLength: 347 microseconds Protocol: 1
Raw data: 10856,316,1096,1068,404,312,1100,1036,400,308,1108,1028,404,308,1104,308,1104,308,1104,304,1100,1020,408,1016,404,300,1104,296,1104,304,1112,1012,404,1016,404,1016,400,304,1104,304,1104,304,1108,296,1112,1012,404,1012,408,

Decimal: 5517760 (24Bit)
Binary: 010101000011000111000000
Tri-State: FFF0010F1000
PulseLength: 346 microseconds Protocol: 1
Raw data: 10744,332,1064,1048,376,328,1072,1040,384,324,1072,1052,388,316,1064,328,1072,324,1064,328,1068,1044,380,1044,380,324,1072,328,1068,324,1068,1048,384,1048,396,1044,384,324,1096,316,1088,316,1088,324,1084,324,1088,320,1084,

Decimal: 5554636 (24Bit)
Binary: 010101001100000111001100
Tri-State: FFF0100F1010
PulseLength: 347 microseconds Protocol: 1
Raw data: 10880,260,1808,12,100,536,1108,984,396,300,1104,992,396,300,1108,292,1104,1012,400,1020,404,300,1104,308,1100,312,1096,316,148,20,312,2616,164,32,404,36,424,60,112,64,416,2612,564,1236,448,380,1188,360,1180,

Decimal: 5554624 (24Bit)
Binary: 010101001100000111000000
Tri-State: FFF0100F1000
PulseLength: 344 microseconds Protocol: 1
Raw data: 10732,316,1088,1092,400,332,1104,1104,404,340,1108,1096,404,336,1116,440,1300,1664,500,1864,540,596,1384,576,1416,636,1756,544,1132,348,1144,1144,416,1144,416,1148,420,344,1148,344,1148,348,1152,348,1148,344,1148,356,1152,

Decimal: 5508592 (24Bit)
Binary: 010101000000110111110000
Tri-State: FFF0001F1100
PulseLength: 372 microseconds Protocol: 1
Raw data: 11580,404,1164,1296,420,400,1164,1292,428,404,1176,1316,428,400,1184,392,1188,392,1180,400,1180,460,1248,452,1244,472,464,472,468,1644,480,508,1288,1724,496,1784,512,1788,524,1840,544,1860,1204,400,1208,400,1208,404,1208,

Decimal: 5508544 (24Bit)
Binary: 010101000000110111000000
Tri-State: FFF0001F1000
PulseLength: 377 microseconds Protocol: 1
Raw data: 11328,360,1140,1200,420,364,1144,1152,420,348,1140,1164,412,356,1132,352,1136,348,1132,332,1124,348,1124,348,1136,1140,416,1148,412,348,1128,1132,408,1132,408,1136,412,336,1116,336,1120,332,1112,332,1116,336,1112,336,1108,

will it be difficult to adapt to your code ???
steevemadison
 
Posts: 1
Joined: Fri Jul 17, 2015 1:19 pm

Re: Gamebuino Home Automation Demo

Postby Myndale » Sat Jul 25, 2015 11:54 pm

steevemadison wrote:will it be difficult to adapt to your code ???


Not at all, all you need to do is create an array with the raw value arrays you captured and change my transmit() function to call the IRRemote library function instead.
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am


Return to Hardware Gallery

Who is online

Users browsing this forum: No registered users and 15 guests

cron