RFM12 wireless transmission

Holidays are a good time to make some LED blinking. This time I’m going to do a wireless transmission using RFM12 modules from two BugOne boards.

On the hardware side, the first board is powered using the AVR programmer and has no connection with the computer. In the mean time the second board is powered and connected to the computer using a USB-Serial cable (Nokia CA-42).

Both boards use theĀ RFM12 library developed by dasLabor, and skeleton files from the BugOne project on Github.

The first board is setup to send “Hello world!” messages every 500 ms, while the second is setup as a RFM12 sniffer. Code for the first BugOne is based on the app_noapp_skeleton from BugOne project files. Modifications made to main.c are available below.

#include "bugOne.h"

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <string.h>

#include "avr_compat.h"
#include "config.h"
#include "rfm12.h"
#include "board.h"

int main(void) {
	drive(LED1);
	set_output(LED1);
	rfm12_init();
	sei();

	uint8_t *msg = "Hello world!";
	while (1) {
		set_output(LED1);
		rfm12_tx(12, 1, msg);
		rfm12_tick();
		clr_output(LED1);
		_delay_ms(500);
	}
}

The code lights the LED1 from BugOne during “Hello world!” message is pushed to the RFM12 stack. However, the message is really transmitted on rfm12_tick() call. A 500 ms delay is done before repeating.

The second board is programmed using the RFM12 sniffer project from BugOne’s git. On the computer pyserial is required. The program (below) is a modified version of hexdump.py. It is programmed in Python 2 (I did not tested it in Python 3) and prints raw messages instead of BugOne’s protocol messages.

#!/usr/bin/python2
#-*- coding: utf-8 -*-

import rfm12

import sys
device = "/dev/ttyUSB0"
baudrate = 38400
if len(sys.argv) >= 2:
	device = sys.argv[1]
if len(sys.argv) >= 3:
	baudrate = int(sys.argv[2])

sniffer = rfm12.SnifferSerial(device)

while True:
	message = sniffer.waitForMessage()
	if message:
		print str(message)
		print >>sys.stderr, [hex(ord(i)) for i in message]
		sys.stdout.flush()
	else:
		sys.stdout.write(".")
		sys.stdout.flush()

String is displayed on stdout while hex version of the string is displayed on stderr.

Each message received by the sniffer toggles its LED2 (blue) which then blinks every 500 ms. LED blinking for message transmission on first board is barely visible (red LED, use full screen video).

One more LED blinking.

Leave a Reply

Your email address will not be published. Required fields are marked *