Hi..
I want to send my pulse counting form a magnetic pickup coil sensor.
Here's my code:
In nrf24_server:
// nrf24_server.pde
#include <SPI.h>
#include <RH_NRF24.h>
// Singleton instance of the radio driver
//RH_NRF24 nrf24;
RH_NRF24 nrf24(10, 7); // use this to be electrically compatible with Mirf
// RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin
// RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini
volatile unsigned long count;
void setup()
{
Serial.begin(9600);
noInterrupts();
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 4;
bitSet(TCCR1B,WGM12);
bitSet(TIMSK1,OCIE1A);
bitSet(TCCR1B,CS12);
bitSet(TCCR1B,CS11);
interrupts();
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");
}
ISR(TIMER1_COMPA_vect)
{
count++;
}
void loop()
{
if (nrf24.available())
{
// Should be a message for us now
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (nrf24.recv(buf, &len))
{
// NRF24::printBuffer("request: ", buf, len);
Serial.print("got request: ");
Serial.println((char*)buf);
// Send a reply
int data = count;
nrf24.send((uint8_t*)&data, sizeof(data));
nrf24.waitPacketSent();
Serial.println("Sent a reply");
}
else
{
Serial.println("recv failed");
}
}
}
in nrf24_client:
// nrf24_client.pde
#include <SPI.h>
#include <RH_NRF24.h>
// Singleton instance of the radio driver
//RH_NRF24 nrf24;
RH_NRF24 nrf24(10, 7); // use this to be electrically compatible with Mirf
// RH_NRF24 nrf24(8, 10);// For Leonardo, need explicit SS pin
// RH_NRF24 nrf24(8, 7); // For RFM73 on Anarduino Mini
void setup()
{
Serial.begin(9600);
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");
}
void loop()
{
Serial.println("Sending to nrf24_server");
// Send a message to nrf24_server
uint8_t data[] = "Hello World!";
nrf24.send(data, sizeof(data));
nrf24.waitPacketSent();
// Now wait for a reply
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (nrf24.waitAvailableTimeout(500))
{
// Should be a reply message for us now
if (nrf24.recv(buf, &len))
{
Serial.print("pulsa air: ");
unsigned long pulsa = *((unsigned long*)buf);
Serial.println(pulsa);
}
else
{
Serial.println("recv failed");
}
}
else
{
Serial.println("No reply, is nrf24_server running?");
}
delay(400);
}
when I compile the server there is an error compiling:
Arduino: nightly (Windows 8), Board: "Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"
RadioHead\RH_ASK.cpp.o: In function `__vector_11':
C:\Program Files (x86)\arduino-nightly\libraries\RadioHead/RH_ASK.cpp:492: multiple definition of `__vector_11'
nrf24_server.cpp.o:C:\Program Files (x86)\arduino-nightly/nrf24_server.ino:37: first defined here
in which line should I change. Thank You
Regards,
Handy M