C is for Colin

That's good enough for me!

Saturday, January 29, 2011

Arduino and RFM22


I've put together a simple RFM22 library based on the sample code at sparkfun and some google-translate assisted reading at http://www.3e-club.ru/view_full.php?id=19&name=rfm22. I've used this with the now-retired RFM22 purchased from http://www.sparkfun.com/products/9581, configured to operate at 434 MHz.

The replacement model at http://www.sparkfun.com/products/10153 should work more or less the same, but I won't know for certain until I have burned through my remaining 6 radios.

The device operates at 3.3v, as opposed to the 5v that most Arduinos seem to operate at. I used the diagram from http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206874649/1 to set up SPI to talk back and forth to the device, operating from the apparently correct assumption that if it works for one SPI 3.3v to 5v system it will work for another. I haven't done anything too serious with this, but with both radios on the same board I can tell one to listen, push data into the FIFO of the second and trigger a TX, and be told by an interrupt that the first has gotten data. Soon I'll have a second avr to run with the second radio from another board, and start playing with how much data I can push back and forth, and from what range.

A few tricks I have learned from playing with this: SDN (shutdown) must be dealt with. If you leave it unconnected and 'floating', it will intermittently work and stop working, including allowing corrupt data to flow back and forth to the main board. For several weeks I did battle with a single register on all the radios I had soldered up which would subtract one from the top 4 bits I would write in... Very frustrating.

RX_ANT, TX_ANT appear to be unnecessary, making for an easier time of soldering the thing up. Same goes for the GPIO (general purpose I/O) contacts – I am sure some projects can make excellent use of them, but thus far leaving them alone has served me well.

From the datasheet, my connections:
RFM22 pinsArduino pinsNotes
GNDGND
VCC3.3v
SDOdigital 12in SPI terms, SDO is also called MISO - no voltage divider needed since 3.3v is high enough for the arduino to read HIGH
SDIdigital 11in SPI terms, SDI is also called MOSI
SCKdigital 13
NSELany other digital pin, I used 9 for one, and 10 for the other
NIRQany IRQ pin, I used digital 3
SDNGNDthis sets the device to stay on until power has been lost

I'd be happy to offer the code for people to play with, but all I can say at this point is that it works for me, with two radios on the same board with no antennas. The code can be found on github. Simply create a folder called RFM22 in your arduino libraries folder with the files in the repo, and try the following code:

#include <SPI.h>
#include <RFM22.h>

rfm22 radio1(10); // radio 1 with NSEL on pin 10
rfm22 radio2(9);  // radio 2 with NSEL on pin 9

void setup() {
  Serial.begin(9600);
  rfm22::initSPI();

  radio1.init();
  radio2.init();
}
void sendByte(uint8_t data) {
  // move to ready
  radio2.write(0x07, 0x01);

  // reset fifo
  radio2.resetFIFO();

  //write data (bursted, but it is only one byte) to the FIFO reg
  radio2.write(0x7F, data);
  
  //move to TX mode to send
  radio2.write(0x07, 0x09);
  
  //wait until sent...

  //move to ready
}
void readyToRecieve() {
  // move to ready state
  radio1.write(0x07, 0x01);
  
  // clear existing interrupts
  radio1.readAndClearInterrupts();
  
  // set up interrupt to list to
  attachInterrupt(1, radio1_int, LOW);//1 is digital pin 3
  radio1.setInterrupt(RFM_INT_PKVALID, RFM_INT_PKVALID);
  
  // clear out the fifo
  radio1.resetFIFO();

  // move to read mode
  radio1.write(0x07, 0x05);
}
char data_recieved = 1;
void radio1_int() {
  data_recieved = 1;
}
void loop() {
  if (data_recieved) {
    // reset the flag
    data_recieved = 0;
    
    // Print the last recieved chunk (one byte)
    Serial.println(radio1.read(0x7F), DEC);
    
    // Tell the listener to be ready
    readyToRecieve();
    delay(50);
  }
  // Send the next chunk
  sendByte(i++);
  delay(1000);
}


Hopefully in the near future I'll putting this together, along with a second assembly so two devices can be demonstrated to talk over the air. And hopefully I won't let this blog sit ignore for another two years again...

EDIT: Made a copying error in the sample code which prevented it from compiling or making sense - it should work now...

Sunday, April 5, 2009

Changes

Briefly, since I apparently stopped posting, I:
  • Applied to work at five places,
  • Wrote two iPhone apps (neither of which is on the store - just for me and mine)
  • Got two interviews, and two job offers,
  • Took one of them! And so now,
  • Signed paperwork to moving to a new apartment.
There's more, certainly, but those are the major points. I'm playing with GWT all day, and working up minor changes to the apps I've done as time permits. I've also got a GWT dynamic i18n library going, but that is a story for another day...

Monday, November 3, 2008

Worth it's Weight in Salt

The phrase is well known, and has its origins in a time when salt was very valuable - wages were even paid with it. I wasn't raised eating a lot of it, so I don't really have much of a taste for it.

I recently visited my younger sister at her college, and made her pancakes after her early morning class. That is, I attempted to make pancakes -- Karen and I bought flour, eggs, milk, and syrup, but forgot the salt and sugar. From experience, I knew the sugar to be a minor loss, but I had never made pancakes without any salt. I had assumed that the salt provided a bit of flavor, and helped out by adding a little iodine to the diet.

This assumption proved faulty - all the pancakes came out as flat as a, well, pancake. No, that's not right - they were even more flat than that. They were edible, and even tasty with a bit of fake maple syrup, but it just wasn't quite right.

Having made bread before, I know that salt is important to help limit the growth of yeast, but I've successfully skipped it before out of laziness. And I've boiled pasta, where the salt is explicitly optional.

Pancakes though – not an option. We asked around, and managed to find someone with coarsely ground sea salt - it looked weird, but with just a pinch of that mixed into the remaining batter, all was well.

Mmmmmm, pancakes....

Tuesday, October 21, 2008

Cooper Vision Rebate

As one of many who wear tiny transparent bits of gel in front of my cornea, I don't like paying more than I have to. Contact lenses are relatively expensive as it is, and my optometrist recommended that I switch to a new brand that would keep my eyes a little more comfortable.

New brand of contacts? Better for my eyes? Whats the catch?

We'll, its more expensive. And you have to change them more frequently - every two weeks instead of once a month. But the manufacturer, Cooper Vision, wanted people to give them a chance, and so they offered a rebate as an incentive - $30 for the contacts, and $20 for the fact that this is the first Cooper Vision product I tried.

Packed up the form, the box tops, and mailed it -- the check will arrive within 6 to 8 weeks, right?

Fast forward about 6 weeks - I just received a postcard indicating that "Unfortunately, [they] could not honor [my] request due to the following reason: Invalid Box Top". Calling the number yielded the same result - something was apparently wrong with with the box tops I sent in.

I counted them a dozen times before I sealed the envelope to eliminate this exact problem. I called several more times, trying different buttons until I talked to a real person...

...And it turns out there was nothing wrong with my rebate form. The guy on the phone said he just needed to validate the form, and I was done. I'll receive the check in about 4 weeks.

That's nice. My question: if they got my form, and punched it in 2 weeks ago, why did they tell me it was invalid, and then fix it so easily? Was it fine, and they just throw up an extra barrier to see who they can get to ignore it? Or did I screw up, and the decided to just be nice to me?

Rebates are a great way to make people think that they are getting a better deal than they are. And by making people put together the forms, and collect the lids, they hope that people will forget, or get lazy. It seems likely that this was another attempt to make life trickier for those after their rebate has already been sent in.

Fifty bucks is great, but it almost doesn't seem worth it for the effort. Or maybe that's the point. Me, I live like a college student. Gimme.

Sunday, October 12, 2008

Time to start scaring wireless users again...

For those who don't pay attention to the IT/Security news, WPA-PSK has taken another hit.

For those who don't know me, I have spent too much time working with wireless technology, and tend to indicate that the sky is falling, or that evil monkeys are going to steal our kidneys.

I tell people to make sure they have encryption (and WEP doesn't count) on their wireless routers, or people can find a way to nab their personal information from a distance. I've been told that I seem to enjoy scaring people. It might be true.

But with the new advances in using graphics cards to speed up the cracking process make it possible for someone with too much time on their hands to take down a home network. Products have even been released using this technology that help you, uh, recover your forgotten WPA password. Doing a bit of number crunching reveals that about 50% of the home networks out there can be cracked with about 3k USD of gear in about a week. While this doesn't quite make it as bad as the WEP situation, where a hacker could casually watch everything you type with about a minute of effort, it does mean that a geek with an expensive gaming rig can take apart a small business network and listen in on, well, anything they feel like.

There are still ways to protect yourself, or at least minimize your risk of being vulnerable to this, listed here from simple to safest:
  • Change your SSID (network name) to something non-standard - Using a simple SSID puts you in that 50% up easily hackable networks.
  • Use long, high entropy passwords - anything in English has very low entropy, so if you want it to be secure but memorable, make it an entire sentence. Or two. And change it once a month.
  • Use WPA-enterprise - either create a bunch of certificates and pass them out, or make everyone use their own password to log on (PEAP or TTLS).
  • Use a VPN, and live with the network performance hit.
For my own part, my wireless network has a nonstandard name and a long (but plain English) password. I would imagine that in the near future I will take some time to start tightening things up a bit - more on that later if I find a neat and tidy way to pull it off.