Wireless Temperature Meter

Using two mbed LPC1768 , one with TMP102 and nRF24L01P wireless transceiver, the other only with the transceiver, to send the temperature from the sensor to the other mbed. But the receiving transceiver won't receive anything. Any ideas?

#include "mbed.h"
#include "nRF24L01P.h"
#include "TMP102.h"


//#define TRANSMIT
#define RECEIVE


Serial pc(USBTX, USBRX); // tx, rx
#ifdef TRANSMIT
TMP102 tempSens(p28, p27, 0x90);
#endif
nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10);    // mosi, miso, sck, csn, ce, irq

DigitalOut myled1(LED1);
DigitalOut myled2(LED2);


typedef union float2bytes { 
        float f; 
        char b[sizeof(float)];
 }float2bytes;

float2bytes temperature;

int main() {

// The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's
//  "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019)
//  only handles 4 byte transfers in the ATMega code.
#define TRANSFER_SIZE   sizeof(float)



#ifdef TRANSMIT
    char txData[TRANSFER_SIZE];
    int txDataCnt = 0;
#endif
#ifdef RECEIVE
    char rxData[TRANSFER_SIZE];
    int rxDataCnt = 0;
#endif    

    my_nrf24l01p.powerUp();

    // Display the (default) setup of the nRF24L01+ chip
    pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency() );
    pc.printf( "nRF24L01+ Output power : %d dBm\r\n",  my_nrf24l01p.getRfOutputPower() );
    pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
    pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
    pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );

    my_nrf24l01p.setTransferSize( TRANSFER_SIZE );
          
     my_nrf24l01p.setReceiveMode();
     my_nrf24l01p.enable();
    
    
#ifdef TRANSMIT
pc.printf("TRANSMITTER!\r\n");
    while (1) {
     
            temperature.f = tempSens.read();
            wait(1);
            pc.printf("temp: %f",temperature.f);
            pc.printf(" == %c%c%c%c\r\n", temperature.b[0], temperature.b[1], temperature.b[2], temperature.b[3]); 
            for(int i = 0; i <= TRANSFER_SIZE; i++){
                txData[i] = temperature.b[i];
                pc.printf("byte %d processed\r\n", i);
                txDataCnt++;
            }     
           
            pc.printf("sending...\r\n");
             if(my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt ) != -1){
                 txDataCnt = 0;
                 myled1 = !myled1;
                 wait(0.5);
                 myled1 = !myled1;
             }else{
             pc.printf("ERROR SENDING\r\n");
                myled1 = 1;
                myled2 = 1;
                wait(0.5);
                myled1 = 0;
                myled2 = 0;
             }
     }
         
#endif

#ifdef RECEIVE       
         pc.printf("RECEIVER!\r\n");
        while (1) {
             
            if ( my_nrf24l01p.readable() ) {
                
                // ...read the data into the receive buffer
                rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) );
              
               if(rxDataCnt == 0 || rxDataCnt == -1){
                    pc.printf("ERROR OR NO DATA\r\n");
                }else{
                    pc.printf("received something\r\n");
                    pc.printf("processing data\r\n");
                    // Display the receive buffer contents via the host serial link
                    for ( int i = 0; rxDataCnt > 0; i++ ) {
                        temperature.b[i] = rxData[i];
                        rxDataCnt--;
                    }
                    
                    pc.printf("Temperatur: %f\r\n", temperature.f);
                    // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
                    myled2 = !myled2;
                }
            }

         }
 #endif
}


Please log in to post comments.