EDIT: I ended up fixing the code, I made a stupid typo >.<. I corrected the code in the post below in case anyone wanted to use it now or in the future.
I am trying to get a duemilanove to send data from a sensor to the arduino mega. I have connected both transievers with the proper spi pins for each board. The reg_read works when run on both devices. However when i try my code, the sender has proper output on serial, but the reciever has wierd output. Its just a bunch of exclamation marks:
! ! ! ! !! ! ! ! ! !! ! ! !!! !! !! ! ! ! ! ! ! ! ! ! ! !! !! !!! ! ! ! ! ! ! !!! ! ! ! !! !! ! ! ! ! ! ! ! ! !! ! ! !! ! ! !! ! ! !! ! !!! !! !! !!! ! ! ! !! !! ! !! ! !! !! ! !! !!! ! ! ! ! !! ! ! ! ! ! !! ! ! !! !! ! ! ! !! ! !! !! ! ! ! !! ! ! !! !! ! ! ! ! ! !! !! ! ! !!! ! ! ! !! ! ! ! ! ! ! ! ! ! ! !! ! !! ! ! !! ! !! !! ! !! !! !! ! ! !! ! !! ! ! ! ! !! ! !! ! ! !! ! ! !! !! !!! ! ! ! !! !! ! !! ! ! !! ! !! ! !! ! !! !! !!! ! !! !! ! !! ! !! ! !! ! ! !!! ! ! ! ! ! ! ! ! ! !! ! !! ! ! ! ! !! !! ! ! !! ! !! !! ! ! ! ! ! ! ! ! !! ! ! ! ! ! ! ! !! ! ! !! !! ! !! ! !! ! ! !! !! ! !! !! ! ! ! ! ! !! !! ! ! !! !! !! ! ! ! !! ! !! ! ! !! ! ! ! ! !! !! !! ! ! !! ! ! !! ! !! ! ! !! ! ! !! ! ! ! !! !! ! ! ! ! ! !! ! !! ! ! !! ! ! ! !! ! ! !! !!! !! !! !! !! !! ! ! ! !! ! !
Sender (Duemilanove):
/*Client
NANO 328:
MISO -> 12
MOSI -> 11
SCK -> 13
CE -> 8
CSN -> 7
GND -> GND
VCC -> 3.3v
*/
#include <SPI.h>
#include <Mirf.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <nRF24L01.h>
#include "DHT.h"
#define DHTPIN 2 // what pin we're connected to
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT11 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
DHT dht(DHTPIN, DHTTYPE);
// converts a float into a char
// and sends it via nRF24L01
void transmitf( float v)
{
byte c;
char buf[10];
dtostrf(v,9,3,buf);
for( int i=0 ; i<8 ; i++ )
{
c = buf[i];
Mirf.send(&c);
while( Mirf.isSending() ) ;
}
}
// sends a string via the nRF24L01
void transmit(const char *string)
{
byte c;
for( int i=0 ; string[i]!=0x00 ; i++ )
{
c = string[i];
Mirf.send(&c);
while( Mirf.isSending() ) ;
}
}
// send a CR/LF sequence via the nRF24L01
void transmitlf(void)
{
byte c;
c = '\r';
Mirf.send(&c);
while( Mirf.isSending() ) ;
c = '\n';
Mirf.send(&c);
while( Mirf.isSending() ) ;
}
void setup()
{
Mirf.cePin = 8;
Mirf.csnPin = 7;
// init the transceiver
Mirf.spi = &MirfHardwareSpi; // ad this
Mirf.init();
// we transmit only a single byte each time
Mirf.payload = 1;
// selecting a channel which is not too noisy
Mirf.channel = 90;
Mirf.config();
// Set 1MHz data rate
Mirf.configRegister(RF_SETUP,0x06);
// Set address - this one must match the
// address the receiver is using!
Mirf.setTADDR((byte *)"send1");
Serial.begin(9600);
dht.begin();
}
void loop()
{
float v01,v02;
// read in some values
v01 = dht.readHumidity();
v02 = dht.readTemperature();
// transmit a fixed token
transmit(" : ");
// transmit the first value
transmit(v01);
transmit(" % ");
// transmit a separator
transmit(" : ");
// transmit a second token
transmit(v02);
transmit(" C ");
// transmit a CR/LF for the PC
// software to sync to
transmitlf();
Serial.println(v01);
// ... just take your time
delay(100);
}
Reciever (Mega 1280):
/*Server
MEGA 2560:
MISO -> 50
MOSI -> 51
SCK -> 52
CE -> 8
CSN -> 7
GND -> GND
VCC -> 3.3v
*/
#include <SPI.h>
#include <Mirf.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <nRF24L01.h>
void setup()
{
Serial.begin(57600);
Mirf.cePin = 8;
Mirf.csnPin = 7;
Mirf.spi = &MirfHardwareSpi; // ad this
Mirf.init();
// name the receiving channel - must match tranmitter setting!
Mirf.setRADDR((byte *)"send1");
// just a single byte is transmitted
Mirf.payload = 1;
// we use channel 90 as it is outside of WLAN bands
// or channels used by wireless surveillance cameras
Mirf.channel = 90;
// now config the device....
Mirf.config();
// Set 1MHz data rate - this increases the range slightly
Mirf.configRegister(RF_SETUP,0x06);
Serial.println("Starting");
}
void loop()
{
byte c;
// is there any data pending?
if( Mirf.dataReady() )
{
// well, get it
Mirf.getData(&c);
// ... and write it out to the PC
Serial.print(c);
}
}