Updated: Wireless file transfer between two arduinos [code added]

Hello all,
At present, I'm working on a datalogger which will be installed under the water surface (roughly 1 - 5 meters deep as a buoy). The system will log temperature at first, but later a host of other sensory inputs are available.

The logging part is done and works, the first field test was a success for the first 8 hours, after that the sensors got water in the housing and ceased functioning. Lessons learned from the prototype are now being worked out.

One thing we found that the first idea we had to allow the buoy to come up to the surface and simply replace the microSD card and submerge the whole lot again, wasn't going to work well with lids being too tight or big diver gloves trying to pick a small mSD card from it holder :)... Although still very much viable, I'm looking into a wireless way to retrieve the logged data.

The file that gets written and appended every hour is a simply text document set in CSV form, it is stored on a microSD card ranging from 1 - 4Gb. Normal file size is somewhere between a couple of Kb up to a couple of 100Kb.

I've tried using a 433Mhz transmitter and receiver but at 2000bps things were agonizingly slow, taking up to 4 hours to send 500Kb which isn't what I want.

I'm now looking into using a 2.4Ghz device, more specific the RFM73 from HopeRF but I'm open to other ideas. The transfer-rate looks good, but does anyone have experience in using these modules as a data transfer device?

The location where the system will work are fresh- and saltwater lakes/seas so I expect minimal interference from 2.4Ghz devices plus the fact that the whole lot is submerged. The idea is that a diver will make magnetic contact between the buoy and data retrieval device, the distance between the two transceivers is max 50cm with little to no water in between as both transceivers are kept in an isolated, plastic container (buoy).

I'm reading into the radiohead library now but asking myself what the best way of transferring would be, bit for bit, just like with the 433Mhz sketch I use or would it be better, since I'll need to swap SPI slaves, to read a number of bytes from the file, store it in SRAM of the arduino, open the RFM73 and have it send out?

If there are other devices that may suit my needs, I'm open to suggestions.

Sparkfun has a buying RF guide : Wireless Buying Guide - SparkFun Electronics
But the RFM73 seems fine. According to the RadioHead library page, it is like the nRF24L01.
RadioHead: RadioHead Packet Radio library for embedded microprocessors

I think about 28 bytes is the maximum to transmit at once. So I suggest to read 28 bytes from the SD card, and transmit them in one package.

There are also fast tranceivers for 433MHz. You might want to keep that in mind when there is still a layer of water between the buoy and the receiver and the 2.4GHz is having troubles to get through that.

Thanks for the info

My biggest hurdle, or at least one of them, is to keep track of where I am in the SD card file as I'm switching between SD card spi and transceiver spi I guess..

That is automatically done.
Every function of the SD library enables the SPI for the SD card, and disables it before the function returns.

It is like this:

  • enable the chip select for the SPI device.
  • do a single SPI.transfer or do many things on the SPI bus.
  • disable the chip select for the SPI device.

Every library that use the SPI is written like that. So you can use many SPI devices, and they don't get tangled into each other.

OK, good to know. I'll go and tinker a lot once I get the modules in.

Thanks.

So, after much tinkering and getting help form the dutch part of the forum, I wired everything up and ran the example sketches of the RFM73, no problemo, at least that works :).

After I added the SDcards, the examples would still run smooth as well as trying to serial print the data file on the SDcard.

Then I got help with the reading of a part of the file and put that data into an array and have the array sent by the RFM73, that didn't work.
I tried using the u_int8_t element in the sketch as I thought that was the problem but it wasn't, at least not that it helped.

So, below is my sketch, with help from the dutch part of the forum. I've translated the comments to make it more readable.

// Test-data.ino
#include <SdFat.h>
#include <SPI.h>
#include <RH_NRF24.h>

RH_NRF24 nrf24(8, 7);

SdFat sd;
SdFile myFile;

const int chipSelect = 10;

void setup() {
Serial.begin(57600);
  while (!Serial) 
    ; // wait for serial port to connect. Needed for Leonardo only
  if (!nrf24.init())
  Serial.println("init failed");
  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
  if (!nrf24.setChannel(1))
  Serial.println("setChannel failed");
  if (!nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm))
  Serial.println("setRF failed");    
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();

  // open the file for reading:
  if (!myFile.open("datatest.csv", O_READ)) {
    sd.errorHalt("File read failed!");
	}

char   buffer[29];     // read buffer
int8_t c = myFile.read();   // read first character
uint8_t i = 0;         // buffer index to 0
while (c != -1) {     // As long as there is no eof
   buffer[i] = c;      // character in the transmit buffer
   i++;
   if (i == 28) {  
      //
      // buffer full
      //
      buffer[i] = '\0';
      //
      // write buffer
      //
      //digitalWrite(chipSelect, HIGH);
      nrf24.send((uint8_t*)buffer, (uint8_t)sizeof(buffer)); //transmit buffer
      //Serial.print(buffer); 
      nrf24.waitPacketSent(); //wait for the transmitter to be finished
      // Now wait for a reply
      uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN]; //deterine length of buffer
      uint8_t len = sizeof(buf);//length of the buffer
      // and start again
      //
      //digitalWrite(chipSelect, LOW);
      i = 0;
   }
   //
   // next read
   //
   c = myFile.read();
}
//
// write the last piece
//
if (i != 0) {
   //
   // there's still something in the buffer
   //
   buffer[i] = '\0';
   nrf24.send((uint8_t*)buffer, (uint8_t)sizeof(buffer)); //transmit buffer
   //Serial.print(buffer);
}
}
void loop() {

}

Now the serial.print part works, the array or at least the file itself is displayed on the serial monitor. I'm going to get a spectrum analyzer in to see if the transmitter itself transmits something at all.

Any help appreciated.