Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of WSN_Node0 by
node0.cpp@5:dfff2a4e46d1, 2016-06-06 (annotated)
- Committer:
- SIT2016
- Date:
- Mon Jun 06 11:04:28 2016 +0000
- Revision:
- 5:dfff2a4e46d1
- Child:
- 6:1e211aba678d
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:dfff2a4e46d1 | 1 | /****PIPE0 Transmitter****/ |
SIT2016 | 5:dfff2a4e46d1 | 2 | |
SIT2016 | 5:dfff2a4e46d1 | 3 | #include "mbed.h" |
SIT2016 | 5:dfff2a4e46d1 | 4 | #include "nRF24L01P.h" |
SIT2016 | 5:dfff2a4e46d1 | 5 | |
SIT2016 | 5:dfff2a4e46d1 | 6 | Serial pc(USBTX, USBRX); // tx, rx |
SIT2016 | 5:dfff2a4e46d1 | 7 | |
SIT2016 | 5:dfff2a4e46d1 | 8 | nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTD4); // mosi, miso, sck, csn, ce, irq |
SIT2016 | 5:dfff2a4e46d1 | 9 | DigitalOut RedLED(PTA5); |
SIT2016 | 5:dfff2a4e46d1 | 10 | AnalogIn pot(A0); |
SIT2016 | 5:dfff2a4e46d1 | 11 | |
SIT2016 | 5:dfff2a4e46d1 | 12 | int main() |
SIT2016 | 5:dfff2a4e46d1 | 13 | { |
SIT2016 | 5:dfff2a4e46d1 | 14 | char count[1]; |
SIT2016 | 5:dfff2a4e46d1 | 15 | char TxDataCnt; |
SIT2016 | 5:dfff2a4e46d1 | 16 | char temp; |
SIT2016 | 5:dfff2a4e46d1 | 17 | |
SIT2016 | 5:dfff2a4e46d1 | 18 | //set tx and rx address for pipe0: 5 bytes long; different for every pipe |
SIT2016 | 5:dfff2a4e46d1 | 19 | long long TxAddress_PIPE0 = 0xC2C2C2C2C2; |
SIT2016 | 5:dfff2a4e46d1 | 20 | long long RxAddress_PIPE0 = 0xC2C2C2C2C2; |
SIT2016 | 5:dfff2a4e46d1 | 21 | |
SIT2016 | 5:dfff2a4e46d1 | 22 | my_nrf24l01p.powerUp(); |
SIT2016 | 5:dfff2a4e46d1 | 23 | my_nrf24l01p.setRfFrequency(2410); |
SIT2016 | 5:dfff2a4e46d1 | 24 | |
SIT2016 | 5:dfff2a4e46d1 | 25 | //setting tx and rx address |
SIT2016 | 5:dfff2a4e46d1 | 26 | my_nrf24l01p.setTxAddress(TxAddress_PIPE0); |
SIT2016 | 5:dfff2a4e46d1 | 27 | |
SIT2016 | 5:dfff2a4e46d1 | 28 | //set rx address with default width and pipe number |
SIT2016 | 5:dfff2a4e46d1 | 29 | my_nrf24l01p.setRxAddress(RxAddress_PIPE0, DEFAULT_NRF24L01P_ADDRESS_WIDTH, NRF24L01P_PIPE_P0); |
SIT2016 | 5:dfff2a4e46d1 | 30 | |
SIT2016 | 5:dfff2a4e46d1 | 31 | // Display the (default) setup of the nRF24L01+ chip |
SIT2016 | 5:dfff2a4e46d1 | 32 | pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); |
SIT2016 | 5:dfff2a4e46d1 | 33 | pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); |
SIT2016 | 5:dfff2a4e46d1 | 34 | pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); |
SIT2016 | 5:dfff2a4e46d1 | 35 | pc.printf( "nRF24L01+ TX Address - PIPE0 : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); |
SIT2016 | 5:dfff2a4e46d1 | 36 | |
SIT2016 | 5:dfff2a4e46d1 | 37 | pc.printf( "Wirelesss sensor network \r\n"); |
SIT2016 | 5:dfff2a4e46d1 | 38 | |
SIT2016 | 5:dfff2a4e46d1 | 39 | TxDataCnt = 1; |
SIT2016 | 5:dfff2a4e46d1 | 40 | |
SIT2016 | 5:dfff2a4e46d1 | 41 | //set transfer size for specified pipe |
SIT2016 | 5:dfff2a4e46d1 | 42 | my_nrf24l01p.setTransferSize(TxDataCnt, NRF24L01P_PIPE_P0); |
SIT2016 | 5:dfff2a4e46d1 | 43 | my_nrf24l01p.enable(); |
SIT2016 | 5:dfff2a4e46d1 | 44 | |
SIT2016 | 5:dfff2a4e46d1 | 45 | char pot_val; |
SIT2016 | 5:dfff2a4e46d1 | 46 | |
SIT2016 | 5:dfff2a4e46d1 | 47 | while (1) { |
SIT2016 | 5:dfff2a4e46d1 | 48 | |
SIT2016 | 5:dfff2a4e46d1 | 49 | //adjusting data to 0-255 with char data type |
SIT2016 | 5:dfff2a4e46d1 | 50 | pot_val = 255*(pot.read()); |
SIT2016 | 5:dfff2a4e46d1 | 51 | |
SIT2016 | 5:dfff2a4e46d1 | 52 | count[0] = pot_val; |
SIT2016 | 5:dfff2a4e46d1 | 53 | |
SIT2016 | 5:dfff2a4e46d1 | 54 | //transmit on specified pipe |
SIT2016 | 5:dfff2a4e46d1 | 55 | temp = my_nrf24l01p.write( NRF24L01P_PIPE_P0,count, TxDataCnt ); |
SIT2016 | 5:dfff2a4e46d1 | 56 | |
SIT2016 | 5:dfff2a4e46d1 | 57 | pc.printf( "Sending %d bytes from PIPE0; POT=%d\r\n",temp,count[0]); |
SIT2016 | 5:dfff2a4e46d1 | 58 | |
SIT2016 | 5:dfff2a4e46d1 | 59 | // Toggle LED1 (to help debug Host -> nRF24L01+ communication) |
SIT2016 | 5:dfff2a4e46d1 | 60 | RedLED = !RedLED; |
SIT2016 | 5:dfff2a4e46d1 | 61 | |
SIT2016 | 5:dfff2a4e46d1 | 62 | wait(1); |
SIT2016 | 5:dfff2a4e46d1 | 63 | } |
SIT2016 | 5:dfff2a4e46d1 | 64 | } |