WSN node 0 transmitter

Dependencies:   mbed nRF24L01P

Fork of WSN_Node0 by Akashlal Bathe

Committer:
akashlal
Date:
Tue Jul 12 15:51:23 2016 +0000
Revision:
6:1e211aba678d
Parent:
5:dfff2a4e46d1
na

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SIT2016 5:dfff2a4e46d1 1 /****PIPE0 Transmitter****/
SIT2016 5:dfff2a4e46d1 2 #include "mbed.h"
akashlal 6:1e211aba678d 3 #include "nRF24L01P.h" //Including nRF library
SIT2016 5:dfff2a4e46d1 4 Serial pc(USBTX, USBRX); // tx, rx
SIT2016 5:dfff2a4e46d1 5 nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTD4); // mosi, miso, sck, csn, ce, irq
SIT2016 5:dfff2a4e46d1 6 DigitalOut RedLED(PTA5);
SIT2016 5:dfff2a4e46d1 7 AnalogIn pot(A0);
SIT2016 5:dfff2a4e46d1 8 int main()
SIT2016 5:dfff2a4e46d1 9 {
SIT2016 5:dfff2a4e46d1 10 char count[1];
SIT2016 5:dfff2a4e46d1 11 char TxDataCnt;
SIT2016 5:dfff2a4e46d1 12 char temp;
SIT2016 5:dfff2a4e46d1 13 //set tx and rx address for pipe0: 5 bytes long; different for every pipe
SIT2016 5:dfff2a4e46d1 14 long long TxAddress_PIPE0 = 0xC2C2C2C2C2;
SIT2016 5:dfff2a4e46d1 15 long long RxAddress_PIPE0 = 0xC2C2C2C2C2;
akashlal 6:1e211aba678d 16 my_nrf24l01p.powerUp(); //Powering up nrf chip
akashlal 6:1e211aba678d 17 my_nrf24l01p.setRfFrequency(2405); //Setting RF frequency, same for tx and rx
SIT2016 5:dfff2a4e46d1 18 //setting tx and rx address
SIT2016 5:dfff2a4e46d1 19 my_nrf24l01p.setTxAddress(TxAddress_PIPE0);
SIT2016 5:dfff2a4e46d1 20 //set rx address with default width and pipe number
SIT2016 5:dfff2a4e46d1 21 my_nrf24l01p.setRxAddress(RxAddress_PIPE0, DEFAULT_NRF24L01P_ADDRESS_WIDTH, NRF24L01P_PIPE_P0);
SIT2016 5:dfff2a4e46d1 22 // Display the (default) setup of the nRF24L01+ chip
SIT2016 5:dfff2a4e46d1 23 pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() );
SIT2016 5:dfff2a4e46d1 24 pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() );
SIT2016 5:dfff2a4e46d1 25 pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
SIT2016 5:dfff2a4e46d1 26 pc.printf( "nRF24L01+ TX Address - PIPE0 : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
SIT2016 5:dfff2a4e46d1 27 pc.printf( "Wirelesss sensor network \r\n");
SIT2016 5:dfff2a4e46d1 28 TxDataCnt = 1;
SIT2016 5:dfff2a4e46d1 29 //set transfer size for specified pipe
SIT2016 5:dfff2a4e46d1 30 my_nrf24l01p.setTransferSize(TxDataCnt, NRF24L01P_PIPE_P0);
SIT2016 5:dfff2a4e46d1 31 my_nrf24l01p.enable();
akashlal 6:1e211aba678d 32 char pot_val; //Variable to store value of potentiometer
SIT2016 5:dfff2a4e46d1 33 while (1) {
SIT2016 5:dfff2a4e46d1 34 //adjusting data to 0-255 with char data type
akashlal 6:1e211aba678d 35 pot_val = 255*(pot.read()); //Get value of potentiometer
SIT2016 5:dfff2a4e46d1 36 count[0] = pot_val;
SIT2016 5:dfff2a4e46d1 37 //transmit on specified pipe
SIT2016 5:dfff2a4e46d1 38 temp = my_nrf24l01p.write( NRF24L01P_PIPE_P0,count, TxDataCnt );
akashlal 6:1e211aba678d 39 pc.printf( "Sending %d bytes from PIPE0; POT=%d\r\n",temp,count[0]); //Print on serial terminal
SIT2016 5:dfff2a4e46d1 40 // Toggle LED1 (to help debug Host -> nRF24L01+ communication)
SIT2016 5:dfff2a4e46d1 41 RedLED = !RedLED;
SIT2016 5:dfff2a4e46d1 42 wait(1);
SIT2016 5:dfff2a4e46d1 43 }
SIT2016 5:dfff2a4e46d1 44 }