IBS
/
WSN_Coordinator
Wsn co ordinator
Fork of WSN_Coordinator by
Receiver.cpp@3:208abcd4751d, 2016-05-24 (annotated)
- Committer:
- janhavi
- Date:
- Tue May 24 10:08:51 2016 +0000
- Revision:
- 3:208abcd4751d
- Parent:
- 2:9f401852272c
- Child:
- 4:b3a70cbb7c81
WSN logging LDR and POT values with NRF.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ganeshgore | 2:9f401852272c | 1 | #include "mbed.h" |
ganeshgore | 2:9f401852272c | 2 | #include "nRF24L01P.h" |
janhavi | 3:208abcd4751d | 3 | |
ganeshgore | 2:9f401852272c | 4 | Serial pc(USBTX, USBRX); // tx, rx |
janhavi | 3:208abcd4751d | 5 | |
janhavi | 3:208abcd4751d | 6 | nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTD4); // mosi, miso, sck, csn, ce, irq |
ganeshgore | 2:9f401852272c | 7 | DigitalOut GreenLED(LED2); |
janhavi | 3:208abcd4751d | 8 | PwmOut RedLed(LED1); |
janhavi | 3:208abcd4751d | 9 | |
ganeshgore | 2:9f401852272c | 10 | int main() { |
ganeshgore | 2:9f401852272c | 11 | |
ganeshgore | 2:9f401852272c | 12 | char count[2]; |
ganeshgore | 2:9f401852272c | 13 | char RxDataCnt; |
ganeshgore | 2:9f401852272c | 14 | char temp; |
janhavi | 3:208abcd4751d | 15 | |
janhavi | 3:208abcd4751d | 16 | float ldr_val, pot_val; |
janhavi | 3:208abcd4751d | 17 | |
ganeshgore | 2:9f401852272c | 18 | my_nrf24l01p.powerUp(); |
ganeshgore | 2:9f401852272c | 19 | my_nrf24l01p.setRfFrequency(2410); |
janhavi | 3:208abcd4751d | 20 | |
ganeshgore | 2:9f401852272c | 21 | // Display the (default) setup of the nRF24L01+ chip |
ganeshgore | 2:9f401852272c | 22 | pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); |
ganeshgore | 2:9f401852272c | 23 | pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); |
ganeshgore | 2:9f401852272c | 24 | pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); |
ganeshgore | 2:9f401852272c | 25 | pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); |
ganeshgore | 2:9f401852272c | 26 | pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() ); |
janhavi | 3:208abcd4751d | 27 | |
ganeshgore | 2:9f401852272c | 28 | pc.printf( "Simple 2 Byte Receiver\r\n" ); |
ganeshgore | 2:9f401852272c | 29 | |
ganeshgore | 2:9f401852272c | 30 | RxDataCnt = 2; |
ganeshgore | 2:9f401852272c | 31 | my_nrf24l01p.setTransferSize( RxDataCnt ); |
ganeshgore | 2:9f401852272c | 32 | |
ganeshgore | 2:9f401852272c | 33 | my_nrf24l01p.setReceiveMode(); |
ganeshgore | 2:9f401852272c | 34 | my_nrf24l01p.enable(); |
janhavi | 3:208abcd4751d | 35 | |
ganeshgore | 2:9f401852272c | 36 | while (1) { |
janhavi | 3:208abcd4751d | 37 | |
ganeshgore | 2:9f401852272c | 38 | // If we've received anything in the nRF24L01+... |
ganeshgore | 2:9f401852272c | 39 | if ( my_nrf24l01p.readable() ) { |
janhavi | 3:208abcd4751d | 40 | |
ganeshgore | 2:9f401852272c | 41 | // ...read the data into the receive buffer |
ganeshgore | 2:9f401852272c | 42 | temp = my_nrf24l01p.read( NRF24L01P_PIPE_P0, count, RxDataCnt ); |
janhavi | 3:208abcd4751d | 43 | |
janhavi | 3:208abcd4751d | 44 | ldr_val = count[0]/255.0; |
janhavi | 3:208abcd4751d | 45 | pot_val = count[1]/255.0; |
janhavi | 3:208abcd4751d | 46 | |
janhavi | 3:208abcd4751d | 47 | //change according to need here; Im printing on serial terminal |
janhavi | 3:208abcd4751d | 48 | pc.printf("Received: %d bytes ;LDR=%.3f, POT=%.3f\r\n",temp,ldr_val, pot_val); |
janhavi | 3:208abcd4751d | 49 | |
ganeshgore | 2:9f401852272c | 50 | // Toggle LED2 (to help debug nRF24L01+ -> Host communication) |
ganeshgore | 2:9f401852272c | 51 | GreenLED = !GreenLED; |
ganeshgore | 2:9f401852272c | 52 | wait_ms(10); |
ganeshgore | 2:9f401852272c | 53 | } |
ganeshgore | 2:9f401852272c | 54 | } |
janhavi | 3:208abcd4751d | 55 | } |