hi,
please can debug code? stuck on simple working code stoped working now. use library: https://github.com/maniacbug/rf24 nrf24l01 recevier , next 1 transmitter:
please can debug code? stuck on simple working code stoped working now. use library: https://github.com/maniacbug/rf24 nrf24l01 recevier , next 1 transmitter:
code: [select]
// http://www.bajdi.com
// sending struct nrf24l01 module
// data sent reading of 2 analog pins
// data received analog reading of 2 pins on other arduino
#include <spi.h>
#include "nrf24l01.h"
#include "rf24.h"
typedef struct{
float humd;
float temp;
float pres_t;
float pres_p;
float volt;
}b_t;
b_t server;
rf24 radio(6,5); // uint8_t _cepin, uint8_t _cspin
const uint64_t pipe = 0xe8e8f0f0e1ll;
void setup()
{
serial.begin(9600);
radio.begin();
radio.openreadingpipe(0,pipe);
radio.startlistening();
//radio.printdetails();
}
void loop(void) {
if( radio.available()) {
bool done = false;
while (!done) {
radio.read( &server, sizeof(server) );
}
}
// serial print received data
serial.print("server.humd = ");
serial.println(server.humd);
serial.print("server.temp = ");
serial.println(server.temp);
serial.print("server.volt = ");
serial.println(server.volt);
delay(5000);
}
code: [select]
#include <wire.h>
#include <spi.h>
#include "nrf24l01.h"
#include "rf24.h"
#include "dht.h"
#include <sfe_bmp180.h>
rf24 radio(6,5); // ce,csn pins
#define dhtpin 2
#define dhttype dht22
#define altitude -22.81 // settings menu item
dht dht(dhtpin, dhttype);
sfe_bmp180 pressure;
const uint64_t pipe = 0xe8e8f0f0e1ll;
typedef struct{
float humd;
float temp;
float pres_t;
float pres_p;
float volt;
}b_t;
b_t server;
float readvcc() {
//long result;
// read 1.1v reference against avcc
admux = _bv(refs0) | _bv(mux3) | _bv(mux2) | _bv(mux1);
delay(4); // wait vref settle
adcsra |= _bv(adsc); // convert
while (bit_is_set(adcsra,adsc));
long result = adcl;
result |= adch<<8;
result = (1126400l / result) / 1000; // back-calculate avcc in mv
return result;
}
void setup(void) {
serial.begin(9600);
radio.begin();
radio.setretries(15, 15);
radio.openwritingpipe(pipe);
radio.stoplistening();
radio.printdetails();
dht.begin();
pressure.begin();
}
void loop(void) {
char status;
double t,p,p0;
server.volt = readvcc();
server.humd = dht.readhumidity(); // humidity dht22
server.temp = dht.readtemperature(); // temperature dht22
status = pressure.starttemperature();
if (status != 0) {
delay(status);
status = pressure.gettemperature(t);
if (status != 0) {
server.pres_t = (t,2); // temperature bmp180
status = pressure.startpressure(3);
if (status != 0) {
delay(status);
status = pressure.getpressure(p,t);
if (status != 0) {
server.pres_p = p; // pressure bmp180
}
}
}
}
serial.println(server.humd);
serial.println(server.temp);
serial.println(server.pres_t);
serial.println(server.pres_p);
serial.println(server.volt,2);
radio.write(&server, sizeof(server));
delay(5000);
}
code: [select]
void loop(void) {
if( radio.available()) {
bool done = false;
while (!done) {
radio.read( &server, sizeof(server) );
}
}
...
this while loop ends when "done" true. when "done" true? can't find in code, loop forever, reading nrf24, if there isn't data read.
try removing while() , "done".
here whole code receiver:
code: [select]
// http://www.bajdi.com
// sending struct nrf24l01 module
// data sent reading of 2 analog pins
// data received analog reading of 2 pins on other arduino
#include <spi.h>
#include "nrf24l01.h"
#include "rf24.h"
typedef struct{
float humd;
float temp;
float pres_t;
float pres_p;
float volt;
}b_t;
b_t server;
rf24 radio(6,5); // uint8_t _cepin, uint8_t _cspin
const uint64_t pipe = 0xe8e8f0f0e1ll;
void setup()
{
serial.begin(9600);
radio.begin();
radio.openreadingpipe(0,pipe);
radio.startlistening();
//radio.printdetails();
}
void loop(void) {
if( radio.available()) {
radio.read( &server, sizeof(server) );
}
// serial print received data
serial.print("server.humd = ");
serial.println(server.humd);
serial.print("server.temp = ");
serial.println(server.temp);
serial.print("server.volt = ");
serial.println(server.volt);
delay(5000);
}
Arduino Forum > Using Arduino > Programming Questions > NRF24L01 issue, please check my code.
arduino
Comments
Post a Comment