RFM12B OOK

Has anyone had luck using the RFM12B as on OOK transmitter?

I've been trying to replicate the following OOK pattern as captured from my OOK plug transmitter. I captured this output using an OOK receiver hooked up to the scope. 

I've been using the RF12_onoff(1) and RF12_onoff(0) to turn the RFM12B on and off but I cant seem to get the received output OOK signal to match what I'm telling it to do. 

I think the issue is something to do with SPI delays etc. Has anyone else had any luck? It looks like JCW from JeeLavs has managed to control FS20 and kaku plugs. My plug is a unbranded http://www.posatech.net/Product_view.asp?ID=2165&CateID=149&SmallCateID=110 

 

Here is my code based on JeeLib example

 

/// @dir kaku_demo
/// This example sends commands to the KlikAanKlikUit units via OOK at 433 Mhz.
// 2009-02-21 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

// Note that 868 MHz RFM12B's can send 433 MHz just fine, even though the RF
// circuitry is presumably not optimized for that band. Maybe the range will
// be limited, or maybe it's just because 868 is nearly a multiple of 433 ?

#include <JeeLib.h>
#include <util/parity.h>

// Turn transmitter on or off, but also apply asymmetric correction and account
// for 25 us SPI overhead to end up with the proper on-the-air pulse widths.
// With thanks to JGJ Veken for his help in getting these values right.
static void ookPulse(int on, int off) {
  rf12_onOff(1);
  delayMicroseconds(on + 150);
  rf12_onOff(0);
  delayMicroseconds(off - 200);
}

//http://www.posatech.net/Product_view.asp?ID=2165&CateID=149&SmallCateID=110
static void POSA_Plug(byte plugNo) {
  if (plugNo==1)
  {
    ookPulse(200,400);
    okkPulse(200,400);
   
    okkPulse(400,200);
    okkPulse(400,200);
    okkPulse(400,200);
   
    okkPulse(200,400);
    okkPulse(200,400);
    okkPulse(200,400);
  }
   
    delay(11); // approximate
  }

void setup() {
  Serial.begin(57600);
  Serial.println("\n[POSA Plug Demo]");

  rf12_initialize(0, RF12_433MHZ);
}

void loop() { 
  Serial.println("on");
  POSA_Plug(1);
  delay(2000);

}

MartinR's picture

Re: RFM12B OOK

I suppose the obvious question is what does the output of the OOK receiver look like when you run the above code and how does it differ from what you expected?

MartinR's picture

Re: RFM12B OOK

Are all the calls to okkPulse typos that should be ookPulse?

If so then one problem is that you are calling the function with off=200 but then you subtract 200 in the function so there is no off time and you immediately turn the transmitter back on.

glyn.hudson's picture

Re: RFM12B OOK

Ah yes! Well spotted, I copied and pasted my old code before I compiled and uploaded it on another laptop. 

The output did not look anything like what I was asking for. Well, sometimes I got a pulse of the correct width mixed in amongst lots of extra switching. 

Just wondering if I was missing something 

MartinR's picture

Re: RFM12B OOK

I decided to have a look at this myself as I've been considering doing the same thing for some time.

The main problem with Glyn's code, as I said above is the  "delayMicroseconds(off - 200);" line which obviously prevents off pulses of 200µs or less. I looked into why this was and found that the transmitter takes about 230µs to turn on using JeeLib.

This is in line with the spec if the synthesizer is turned off but it can be reduced to about 100µs if you leave the synthesizer turned on. This can be done by changing...

void rf12_onOff (uint8_t value) {
    rf12_xfer(value ? RF_XMITTER_ON : RF_IDLE_MODE);
}

to..

void rf12_onOff (uint8_t value) {
    rf12_xfer(value ? RF_XMITTER_ON : 0x821d);
}

in RF12.cpp

Alternatively this code does the same thing without using JeeLib at all.

#include <SPI.h>

#define RFMSELPIN 10

void setup()
{
  Serial.begin(57600);
  Serial.println("\n[POSA Plug Demo]");

  pinMode (RFMSELPIN, OUTPUT);
  digitalWrite(RFMSELPIN,HIGH);

  // start the SPI library:
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(0);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  // initialise RFM12
  delay(200); // wait for RFM12 POR
  rfm_write(0x0000); // clear SPI
  rfm_write(0xCA83); // non-sensitive reset
  rfm_write(0x80D7); // 433MHz band
  rfm_write(0xA640); // set frequency to 434.0000MHz (adjust to suit device)
  rfm_write(0x9850); // max power
  rfm_write(0x821d); // Turn on crystal and synthesizer
}

void loop()
{
   Serial.println("on");
   POSA_Plug(1);
   delay(2000);
}

void ookPulse(int on, int off)
{
  rfm_write(0x823d);
  delayMicroseconds(on+3);
  rfm_write(0x821d);
  delayMicroseconds(off-43);
}

void POSA_Plug(byte plugNo)
{
  if (plugNo==1)
  {
    ookPulse(200,400);
    ookPulse(200,400);

    ookPulse(400,200);
    ookPulse(400,200);
    ookPulse(400,200);
   
    ookPulse(200,400);
    ookPulse(200,400);
    ookPulse(200,400);
  }
   
  delay(11); // approximate
}

// write a command to the RFM12
word rfm_write(word cmd)
{
  word result;
 
  digitalWrite(RFMSELPIN,LOW);
  result=(SPI.transfer(cmd>>8)<<8) | SPI.transfer(cmd & 0xff);
  digitalWrite(RFMSELPIN,HIGH);
  return result;
}
  
And here's the output of an OOK receiver with the above code running on an emonTx...
 

glyn.hudson's picture

Re: RFM12B OOK

Awesome, good work this looks promising. Will give it a go next time I'm in the lab next week 

MartinR's picture

Re: RFM12B OOK

code edited - missed off   pinMode (RFMSELPIN, OUTPUT); - duh!

boelle's picture

Re: RFM12B OOK

could this maybe mean that control of conrad valves would be possible from within emoncms? just started a new thread and found this

glyn.hudson's picture

Re: RFM12B OOK

I believe OOK transmission is not possible with RFM69CW. I've recently been playing about with controlling LightWaveRF OOK plugs and relays using ook transmitter on emonpi (or raspberrypi). Recently posted a blog with info and video.

Would be possible to control other ook devices with correct protocol.

http://openenergymonitor.blogspot.co.uk/2015/11/remote-control-of-lightw...

boelle's picture

Re: RFM12B OOK

what about the RFM23 and RFM12 series? loads of those still arround, and you can still order them if you buy enough

will try and google info and post links, first one is here:

http://www.mike-stirling.com/2013/02/implementing-the-elv-fht-protocol-w...

http://jeelabs.org/2009/12/14/better-fs20-transmissions/

boelle's picture

Re: RFM12B OOK

did the links shine any new light on the matter?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.