HS1527 for JeeNodes
Posted: March 10th, 2010 | Author: admin | Filed under: Uncategorized | 2 Comments »I’ll extend this post as I find some time …
// This example sends commands to wireless switches in the hs1527 format on 433 Mhz.
// 2009-02-21 <jcw@equi4.com> http://opensource.org/licenses/mit-license.php
// 2010-03-10 <poem.michael@oiu.ch> http://opensource.org/licenses/mit-license.php
// $Id$
// 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 ?
// I've tested the code with a RFM12B build for the 433MHz band and an 16.4mm
// whip antenna. It works quit over a distance.
// Devices tested: SITE - Model RCS-K08
#include <Ports.h>
#include <RF12.h>
//min 270 - max 650 -> smaller intervall = less power usage therfore
#define pulseLength0 300
#define pulseLength1 900 //pulseLength * 3
#define pulseLengthS 6300 //pulseLength * 31
// 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);
}
// Sends a single bit in hs1527 definition
static void hs1527_bit(boolean data) {
if(data)
ookPulse(pulseLength0, pulseLength1);//1
else
ookPulse(pulseLength1, pulseLength0);//0
}
// Sends the whole bit tram in hs1527 definition
static void hs1527_tram(long device_nr, boolean on, int channel) {
for(int a = 5; a > 0; a--) { // minimal 3 successive trams are required
ookPulse(pulseLength0, pulseLengthS); //sync
for(int b = 19; b > -1; b--)
hs1527_bit((device_nr >> b) & 0b1); //device nr
hs1527_bit(on); //on - off
for(int b = 2; b > -1; b--)
hs1527_bit((channel >> b) & 0b1); //channel
}
}
void setup() {
Serial.begin(57600);
Serial.println("\n[hs1527_demo]");
rf12_initialize(0, RF12_433MHZ);
}
void loop() {
hs1527_tram(992363, 0, 4); //channel 4 on
delay(1000);
hs1527_tram(992363, 1, 4); //channel 4 off
delay(1000);
}
