One of the latest additions to Cosa is a new light-weight class for Manchester Phase Encoding (MPE) with Transmitter and Receiver for RF433 (supported by all Cosa targets; ATmega328, 168, 1284, 1280, 2560, ATtinyX4, X5). The classes are interrupt driven; timer interrupt for transmitter and external interrupt (change mode) for receiver pulse sequence detection. Below is a snippet for the demo sketches; CosaMPEsender
#include "Cosa/MPE.hh"
#include "Cosa/Watchdog.hh"
MPE::Transmitter tx(Board::D9);
void setup()
{
Watchdog::begin();
tx.begin();
}
void loop()
{
static uint8_t msg[16] = { 0 };
tx.send(&msg, sizeof(msg));
msg[0] += 1;
Watchdog::delay(16);
}
CosaMPEreceiver.
#include "Cosa/MPE.hh"
#include "Cosa/IOStream/Driver/UART.hh"
#include "Cosa/Trace.hh"
#include "Cosa/Watchdog.hh"
#include "Cosa/RTC.hh"
MPE::Receiver rx;
void setup()
{
uart.begin(9600);
trace.begin(&uart, PSTR("CosaMPEreceiver: started"));
Watchdog::begin();
RTC::begin();
rx.begin();
}
void loop()
{
static uint8_t nr = 0;
static uint16_t count = 0;
static uint16_t timeouts = 0;
static uint16_t errors = 0;
static uint16_t drops = 0;
uint8_t buf[MPE::PAYLOAD_MAX];
int n = rx.recv(buf, sizeof(buf), 1000);
if (n > 0) {
count += 1;
if (buf[0] != nr) {
drops += 1;
errors += 1;
nr = buf[0];
}
nr += 1;
if (count % 100) return;
...
} else if (n == 0)
timeouts += 1;
else
errors += 1;
}
For more details see.
- Github GitHub - mikaelpatel/Cosa: An Object-Oriented Platform for Arduino/AVR
- MPE.hh https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/MPE.hh
- Example sketch CosaMPEsender https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaMPEsender/CosaMPEsender.ino
- Example sketch CosaMPEreceiver https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaMPEreceiver/CosaMPEreceiver.ino
- Blog http://cosa-arduino.blogspot.se/
- On-line documentation http://dl.dropboxusercontent.com/u/993383/Cosa/doc/html/index.html
Cheers!