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