Transmitter of Wireless sensor network using NRF24L01P.

Dependencies:   mbed nRF24L01P

Files at this revision

API Documentation at this revision

Comitter:
eduvanceIoT
Date:
Sat Sep 10 06:37:09 2016 +0000
Parent:
0:3b68b7f40f0a
Commit message:
To transmit analog sensor data, from transmitter to receiver wirelessly through NRF module and plot it on serial plotter (Transmitter). ;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Aug 02 08:22:13 2016 +0000
+++ b/main.cpp	Sat Sep 10 06:37:09 2016 +0000
@@ -1,4 +1,4 @@
-#include "mbed.h"
+ #include "mbed.h"
 #include "nRF24L01P.h"
 
 Serial pc(USBTX, USBRX); 
@@ -7,12 +7,21 @@
 nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTD4);    // mosi, miso, sck, csn, ce, irq
 DigitalOut RedLED(LED1);
 
+AnalogIn pot(PTB0);
+AnalogIn ldr(PTB1);
+
 int main()
 {
-    char count[1];
+    
+    float potval;
+    char potc;
+    float ldrval;
+    char ldrc;
+    
+    char count[2];
     char TxDataCnt;
     char temp;
-
+    int k = 255; 
     //waking up NRF
     my_nrf24l01p.powerUp();
     
@@ -26,9 +35,9 @@
     pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
     pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );
 
-    pc.printf( "Simple Transmitter (0 - 9 Counter) \r\n");
+    pc.printf( "Simple Transmitter \r\n");
     
-    TxDataCnt = 1;
+    TxDataCnt = 2;
     
     //set packet size of NRF
     my_nrf24l01p.setTransferSize(TxDataCnt);
@@ -37,22 +46,31 @@
     my_nrf24l01p.enable();
     
     //sending test count value
-    count[0] = 0x01;
+    //count[0] = 0x01;
+    //count[1] = 0x01;
 
     while (1) {
+        
+        potval = pot.read();
+        potc = potval*k;
+        ldrval = ldr.read();
+        ldrc = ldrval*k;
+        
+        count[0] = potc;
+        count[1] = ldrc;
 
         //Send the Transmit buffer via the nRF24L01+
         temp = my_nrf24l01p.write( NRF24L01P_PIPE_P0,count, TxDataCnt );
         
         //print how many bytes sent
-        pc.printf( "Sending %d - %d\r\n",temp,count[0]);
+        pc.printf( "Sending %d -pot - %d ldr - %d\r\n",temp,count[0],count[1]);
 
         //toggle debug led
         RedLED = !RedLED;
             
         //update count
-        count[0]++;
+        //count[0]++;
         
-        wait(1);
+        wait(0.5);
     }
 }