Hi, I'm using your library for a simple Arduino to Raspberry Pi project. The Arduino transmits temperature sensor data to the Raspberry and the Raspberry prints "Got data!" when data is received.
Arduino code here:
**#include
include "nRF24L01.h"
include "RF24.h"
include
include
include
SFE_BMP180 pressure;
define ALTITUDE 886.0 // Altitude of SparkFun's HQ in Boulder, CO. in meters
//for nrf24 debug
int serial_putc( char c, FILE * )
{
Serial.write( c );
return c;
}
if (pressure.begin())
Serial.println("BMP180 init success");
else
{
// Oops, something went wrong, this is usually a connection problem,
// see the comments at the top of this sketch for the proper connections.
Serial.println("BMP180 init fail\n\n");
while (1); // Pause forever.
}
}
void loop() {
//Get temperature from sensor
//Get temperature from sensor
float temperature = getTemperature();
// Assign temperature to payload, here am sending it as string
dtostrf(temperature, 2, 2, SendPayload);
//add a tag
strcat(SendPayload, " : Temperature"); // add first string
//send a heartbeat
radio.stopListening();
Serial.println("Transmitting data");
bool ok = radio.write(&SendPayload, strlen(SendPayload));
if (ok == false)
{
Serial.println("Transmission failed");
}
else
{
Serial.println("Success");
}
radio.startListening();
Serial.println(SendPayload);
// slow down a bit
delay(1000);
}
// Getting temperature from DS18S20
float getTemperature() {
char status;
double T;
status = pressure.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);
// Retrieve the completed temperature measurement:
// Note that the measurement is stored in the variable T.
// Function returns 1 if successful, 0 if failure.
status = pressure.getTemperature(T);
if (status != 0)
{
// Print out the measurement:
Serial.print("temperature: ");
Serial.print(T, 2);
Serial.print(" deg C, ");
Serial.print((9.0 / 5.0)*T + 32.0, 2);
Serial.println(" deg F");
// Start a pressure measurement:
// The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.
}
}
return T;
}**
Raspberry Pi code here (derived from your test.js code):
Hello, sorry I have fallen very behind on this library! I see you already closed this, hopefully you found a solution otherwise please accept my apologies (and feel free to reopen).
Hi, I'm using your library for a simple Arduino to Raspberry Pi project. The Arduino transmits temperature sensor data to the Raspberry and the Raspberry prints "Got data!" when data is received. Arduino code here: **#include
include "nRF24L01.h"
include "RF24.h"
include
include
include
SFE_BMP180 pressure;
define ALTITUDE 886.0 // Altitude of SparkFun's HQ in Boulder, CO. in meters
//for nrf24 debug int serial_putc( char c, FILE * ) { Serial.write( c ); return c; }
//for nrf24 debug void printf_begin(void) { fdevopen( &serial_putc, 0 ); }
//nRF24 set the pin 9 to CE and 10 to CSN/SS // Cables are: // SS -> 10 // MOSI -> 11 // MISO -> 12 // SCK -> 13
RF24 radio(7, 8);
//we only need a write pipe, but am planning to use it later const uint64_t pipes = 0xF0F0F0F0E1LL;
// here we can send up to 30 chars char SendPayload[31] = "Demo String";
//int ledPin = 5;
void setup(void) { Serial.begin(57600); //Debug
printf_begin(); //nRF24 configurations radio.begin(); radio.setChannel(0x4c); radio.setAutoAck(1); radio.setRetries(15, 15); radio.setDataRate(RF24_250KBPS); radio.setPayloadSize(32); radio.openWritingPipe(pipes); radio.startListening(); radio.printDetails(); //for Debugging
if (pressure.begin()) Serial.println("BMP180 init success"); else { // Oops, something went wrong, this is usually a connection problem, // see the comments at the top of this sketch for the proper connections.
} }
void loop() { //Get temperature from sensor //Get temperature from sensor float temperature = getTemperature(); // Assign temperature to payload, here am sending it as string dtostrf(temperature, 2, 2, SendPayload);
//add a tag strcat(SendPayload, " : Temperature"); // add first string
//send a heartbeat radio.stopListening(); Serial.println("Transmitting data"); bool ok = radio.write(&SendPayload, strlen(SendPayload)); if (ok == false) { Serial.println("Transmission failed"); } else { Serial.println("Success"); } radio.startListening(); Serial.println(SendPayload);
// slow down a bit delay(1000); }
// Getting temperature from DS18S20
float getTemperature() { char status; double T;
status = pressure.startTemperature(); if (status != 0) { // Wait for the measurement to complete: delay(status);
} return T; }**
Raspberry Pi code here (derived from your test.js code):
`var NRF24 = require("./index"), spiDev = "/dev/spidev0.0", cePin = 24, //var ce = require("./gpio").connect(cePin) pipes = 0xF0F0F0F0E1;
var stream = require('stream'), util = require('util'); function CountStream(ms) { stream.Readable.call(this); this._n = 0; } util.inherits(CountStream, stream.Readable); CountStream.prototype._read = function () { console.log("Piping out", this._n); var b = new Buffer(4); b.writeUInt32BE(this._n++, 0); this.push(b); };
var nrf = NRF24.connect(spiDev, cePin); //nrf._debug = true; nrf.channel(0x4c).transmitPower('PA_MAX').dataRate('250kbps').crcBytes(0).autoRetransmit({count:15, delay:15}).begin(function () { nrf.printDetails(); console.log("Receiving mode"); var rx = nrf.openPipe('rx', pipes); rx.on('data', function (d) { console.log("Got data!"); }); });`
Output is as follows on the Raspberry Pi: Receiving mode SPI device: /dev/spidev0.0 CE GPIO: 24 IRQ GPIO: undefined STATUS: 0x0 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0 RX_ADDR_P0–1: 0x0000000000 0x0000000000 RX_ADDR_P2–5: 0x00 0x00 0x00 0x00 TX_ADDR: 0x0000000000 RX_PW_P0–5: 0x0 0x0 0x0 0x0 0x0 0x0 EN_AA: 0x00 EN_RXADDR: 0x00 RF_CH: 0x0 RF_SETUP: 0x00 CONFIG: 0x00 DYNPD/FEATURE: 0x00 0x00 Data Rate: 1Mbps Model: nRF24L01 CRC Length: Disabled PA Power: PA_MIN
And the program does not proceed from there. As you can see, none of the defined values are reflected here