Author Topic: [SOLVED] RGB-Spark  (Read 6088 times)

bruceme

  • Newbie
  • *
  • Posts: 23
[SOLVED] RGB-Spark
« on: February 26, 2014, 04:17:51 pm »
I'm working on a DIY home automation. I'm using digisparks and NRF24L01+ to control my 12v MR16 lighting system.  This works great for simple LED lamps, run a relay or a transistor... easy!  side note: I'm using the digiX as the "server";  just started, will have updates later.

But it all gets more complicated with the accent RGB LED MR16 lamp from cheap RGB remote controlled laps.  I want to attach a NRF24L01+ to my digispark that will consume 4 pins, that only leaves two pins... 3 colors, 2 pins. So right away, there's a problem.

Attached is a picture of what I have and the board disassembled...  These lamps use an IR remote control to drive some simple controller that actually drives the LEDs.  The whole thing internally runs on 5vdc.

I see three ways this could go;

- Try to mimic the IR signal, or snip the sensor and send my own.
- Build my own board and steel the RGB LED
- Somehow tap into the sensors and send my own signals to the right traces on that board.

I'd love to hear anyone else's ideas, suggestions or success with IR spoofing with a digispark.

« Last Edit: February 27, 2014, 04:30:00 am by bruceme »

bruceme

  • Newbie
  • *
  • Posts: 23
Re: RGB-Spark
« Reply #1 on: February 26, 2014, 09:31:43 pm »

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: [SOLVED] RGB-Spark
« Reply #2 on: March 01, 2014, 01:51:14 am »
This might be of interest to your project: http://digistump.com/board/index.php/topic,1319.0.html

Very cool project - thanks for sharing it!

bruceme

  • Newbie
  • *
  • Posts: 23
Update: RGB-Spark
« Reply #3 on: March 08, 2014, 06:07:02 pm »
I have a really interesting update!

The project I linked above was a _HUGE_ help, but it wasn't enough.  He setup and drove the internal PWM to do the carrier wave, but effectively "bit-banged" the signal by turning the PWM (carrier) on/off.  Well, I removed the IR sensor (which filters the carrier) and drove P5 directly to the IR sense line using his bit-bang.

Oddly enough, it started doing something, but not what it was supposed to.  So I hacked and fiddled and right about when I was about to build a scope, I realized his diagrams show the signal lines inverted.  So I flipped the "high" and "lows" and pow!  it worked!

Here's the code that directly drives P5 (I borrowed from cht's code heavily, all of my success is his).  I did some basic cleanup, I also translated his "picture of a spreadsheet of commands" into a helpful command array with comments.


int pin = 5;

#define LEAD_MS 550
#define ZERO_MS 550
#define ONE_MS 1620
#define INIT_HIGH_MS 8800
#define INIT_LOW_MS 4200

unsigned char _ctCommands = 24;
unsigned char _commands[] = {
0x08,        // pale blue
0x10,        // green
0x18,        // aqua
0x20,        // dimmer
0x28,        // light blue
0x30,        // light green
0x48,        // violet
0x50,        // blue
0x58,        // purple
0x60,        // off
0x68,        // deep purple
0x70,        // dark blue
0x88,        // yellow
0x90,        // red
0x98,        // peach
0xA0,        // brighter
0xA8,        // salmon
0xB0,        // orange
0xC8,        // smooth
0xD0,        // white
0xD8,        // fade
0xE0,        // on
0xE8,        // strobe
0xF0};       // flash

void setup()
{
  pinMode(pin, OUTPUT); 

  Serial.begin(9600);
  Serial.println("start");
}

unsigned char idx = 0;

void loop()
{
  digitalWrite(pin, HIGH);

  unsigned char i;
 
    send_command(_commands[idx]);

    for (i=0;i<200;i++)
    {
      delayMicroseconds(2000);
    }

    idx++;
    if (idx > _ctCommands)
      idx = 0;
}

void send_command(unsigned char data)
{
  unsigned char i;

  command_init();

  unsigned char address = 0x00;

  send_ir_byte(address);
  send_ir_byte(address ^ 0xff);

  send_ir_byte(data);
  send_ir_byte(data ^ 0xff);

  send_bit(LEAD_MS, ZERO_MS); // stop-bit
}

int delays[] = {
  ZERO_MS, ONE_MS}; // hi-low

void send_ir_byte(unsigned char data)
{
  unsigned char i;

  for (i=0;i<8;i++) // MSB first
  {
    if ((data<<i) & 0x80)
    {
      send_bit_high();
    }
    else
    {
      send_bit_low();
    }
  } 
}

void send_bit_high()
{
  send_bit(LEAD_MS, ONE_MS);
}

void send_bit_low()
{
  send_bit(LEAD_MS, ZERO_MS);
}

void send_bit(int highMs, int lowMs)
{
  // 1.65ms
  digitalWrite(pin, LOW);
  delayMicroseconds(highMs);
  digitalWrite(pin, HIGH);
  delayMicroseconds(lowMs);
}

void command_init()
{
  send_bit(INIT_HIGH_MS, INIT_LOW_MS);
}


This used just one pin, so I have plenty of pins left to integrate the NRF24L01+
« Last Edit: March 08, 2014, 06:09:51 pm by bruceme »

bruceme

  • Newbie
  • *
  • Posts: 23
Re: [SOLVED] RGB-Spark
« Reply #4 on: March 08, 2014, 06:31:14 pm »
The illustration of how I modified the lamp.


bruceme

  • Newbie
  • *
  • Posts: 23
Re: [SOLVED] RGB-Spark
« Reply #5 on: March 08, 2014, 07:02:43 pm »
I summarized all this on my blog here

http://ubivis.blogspot.com/p/controlling-rgb-led-mr16-light-with.html

I will update it with my 2.4ghz transceiver update soon hopefully.