Node 1 for WSN communication, sending Pot values over nRF
Fork of WSN_Node1 by
node1.cpp@6:47347a642702, 2016-07-12 (annotated)
- Committer:
- akashlal
- Date:
- Tue Jul 12 15:52:34 2016 +0000
- Revision:
- 6:47347a642702
- Parent:
- 5:c44298b018f4
na
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SIT2016 | 5:c44298b018f4 | 1 | /****PIPE1 Transmitter****/ |
ganeshgore | 2:9f401852272c | 2 | #include "mbed.h" |
akashlal | 6:47347a642702 | 3 | #include "nRF24L01P.h" //Including nRF library |
ganeshgore | 2:9f401852272c | 4 | Serial pc(USBTX, USBRX); // tx, rx |
janhavi | 3:208abcd4751d | 5 | nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTD4); // mosi, miso, sck, csn, ce, irq |
SIT2016 | 5:c44298b018f4 | 6 | DigitalOut RedLED(PTA5); |
SIT2016 | 5:c44298b018f4 | 7 | AnalogIn pot(A0); |
janhavi | 3:208abcd4751d | 8 | |
SIT2016 | 5:c44298b018f4 | 9 | int main() |
SIT2016 | 5:c44298b018f4 | 10 | { |
janhavi | 4:b3a70cbb7c81 | 11 | char count[1]; |
SIT2016 | 5:c44298b018f4 | 12 | char TxDataCnt; |
ganeshgore | 2:9f401852272c | 13 | char temp; |
SIT2016 | 5:c44298b018f4 | 14 | //set tx and rx address for pipe1: 5bytes long; different for every pipe |
SIT2016 | 5:c44298b018f4 | 15 | long long TxAddress_PIPE1 = 0xE2E2E2E2E2; |
janhavi | 4:b3a70cbb7c81 | 16 | long long RxAddress_PIPE1 = 0xE2E2E2E2E2; |
ganeshgore | 2:9f401852272c | 17 | my_nrf24l01p.powerUp(); |
ganeshgore | 2:9f401852272c | 18 | my_nrf24l01p.setRfFrequency(2410); |
SIT2016 | 5:c44298b018f4 | 19 | //set tx address |
SIT2016 | 5:c44298b018f4 | 20 | my_nrf24l01p.setTxAddress(TxAddress_PIPE1); |
SIT2016 | 5:c44298b018f4 | 21 | //set rxaddress with default width for specified pipe |
janhavi | 4:b3a70cbb7c81 | 22 | my_nrf24l01p.setRxAddress(RxAddress_PIPE1, DEFAULT_NRF24L01P_ADDRESS_WIDTH, NRF24L01P_PIPE_P1); |
janhavi | 4:b3a70cbb7c81 | 23 | |
ganeshgore | 2:9f401852272c | 24 | // Display the (default) setup of the nRF24L01+ chip |
ganeshgore | 2:9f401852272c | 25 | pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); |
ganeshgore | 2:9f401852272c | 26 | pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); |
ganeshgore | 2:9f401852272c | 27 | pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); |
SIT2016 | 5:c44298b018f4 | 28 | pc.printf( "nRF24L01+ TX Address - PIPE1 : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); |
SIT2016 | 5:c44298b018f4 | 29 | pc.printf( "Wirelesss sensor network \r\n"); |
SIT2016 | 5:c44298b018f4 | 30 | TxDataCnt = 1; |
SIT2016 | 5:c44298b018f4 | 31 | //set transfer size for each pipe |
SIT2016 | 5:c44298b018f4 | 32 | my_nrf24l01p.setTransferSize(TxDataCnt, NRF24L01P_PIPE_P1); |
SIT2016 | 5:c44298b018f4 | 33 | my_nrf24l01p.enable(); |
akashlal | 6:47347a642702 | 34 | char pot_val; //Variable to store value of potentiometer |
ganeshgore | 2:9f401852272c | 35 | while (1) { |
SIT2016 | 5:c44298b018f4 | 36 | //adjusting data to 0-255 with char data type |
SIT2016 | 5:c44298b018f4 | 37 | pot_val = 255*(pot.read()); |
SIT2016 | 5:c44298b018f4 | 38 | count[0] = pot_val; |
SIT2016 | 5:c44298b018f4 | 39 | //transmit on specified pipe |
SIT2016 | 5:c44298b018f4 | 40 | temp = my_nrf24l01p.write( NRF24L01P_PIPE_P1,count, TxDataCnt ); |
akashlal | 6:47347a642702 | 41 | pc.printf( "Sending %d bytes from PIPE1; POT=%d\r\n",temp,count[0]); //Print on serial terminal |
SIT2016 | 5:c44298b018f4 | 42 | // Toggle LED1 (to help debug Host -> nRF24L01+ communication) |
SIT2016 | 5:c44298b018f4 | 43 | RedLED = !RedLED; |
SIT2016 | 5:c44298b018f4 | 44 | wait(1); |
ganeshgore | 2:9f401852272c | 45 | } |
janhavi | 3:208abcd4751d | 46 | } |