SHARE
TWEET

Untitled

a guest Oct 5th, 2018 194 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Project: nRF905 AVR/Arduino Library/Driver (Low power ping server example)
  3.  * Author: Zak Kemble, contact@zakkemble.co.uk
  4.  * Copyright: (C) 2017 by Zak Kemble
  5.  * License: GNU GPL v3 (see License.txt)
  6.  * Web: http://blog.zakkemble.co.uk/nrf905-avrarduino-librarydriver/
  7.  */
  8.  
  9. /*
  10.  * Low power ping server
  11.  *
  12.  * Similar to the pin server example
  13.  * Output power is set to the lowest setting, receive sensitivity is lowered.
  14.  *
  15.  * 7 -> CE
  16.  * 8 -> PWR
  17.  * 9 -> TXE
  18.  * 4 -> CD
  19.  * 3 -> DR
  20.  * 2 -> AM
  21.  * 10 -> CSN
  22.  * 12 -> SO
  23.  * 11 -> SI
  24.  * 13 -> SCK
  25.  */
  26.  
  27. #include <nRF905.h>
  28. #include <Wire.h>
  29. #include <LiquidCrystal_I2C.h>
  30.  
  31. #define RXADDR 0x586F2E10 // Address of this device
  32. #define TXADDR 0xFE4CA6E5 // Address of device to send to
  33.  
  34. #define PACKET_NONE    0
  35. #define PACKET_OK   1
  36. #define PACKET_INVALID  2
  37.  
  38. //long omfg;
  39.  
  40. LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6,7,3,POSITIVE);
  41.  
  42. static volatile uint8_t packetStatus;
  43.  
  44. void NRF905_CB_RXCOMPLETE(void)
  45. {
  46.   packetStatus = PACKET_OK;
  47.   nRF905_standby();
  48. }
  49.  
  50. void NRF905_CB_RXINVALID(void)
  51. {
  52.   packetStatus = PACKET_INVALID;
  53.   nRF905_standby();
  54. }
  55.  
  56. void setup()
  57. {
  58.   Serial.begin(115200);
  59.   Serial.println(F("Server started"));
  60.  
  61.   lcd.begin(16, 2);
  62.  
  63.   for(int i = 0; i<3; i++)
  64.     {
  65.       lcd.backlight();
  66.       delay(250);
  67.       lcd.noBacklight();
  68.       delay(250);
  69.     }
  70.     lcd.backlight();
  71.  
  72.   pinMode(A5, OUTPUT); // LED
  73.  
  74.   // Start up
  75.   nRF905_init();
  76.  
  77.   // Set address of this device
  78.   nRF905_setListenAddress(RXADDR);
  79.  
  80.   // Lowest transmit level -10db
  81.   nRF905_setTransmitPower(NRF905_PWR_n10);
  82.  
  83.   // Reduce receive sensitivity to save a few mA
  84.   nRF905_setLowRxPower(NRF905_LOW_RX_ENABLE);
  85.  
  86.   // Put into receive mode
  87.   nRF905_RX();
  88. }
  89.  
  90. void loop()             // Loop > while / if
  91. {
  92.   static uint32_t pings;
  93.   static uint32_t invalids;
  94.   static uint32_t volts;
  95.  
  96.   Serial.println(F("---- Incoming Message ----"));
  97.   lcd.clear();
  98.   lcd.setCursor(0,0);
  99.   lcd.print("TEST       help");
  100.   delay(500);
  101.  
  102.   // Wait for data
  103.   while(packetStatus == PACKET_NONE);
  104.    
  105.   if(packetStatus != PACKET_OK)
  106.   {
  107.     invalids++;
  108.     Serial.println(F("Invalid packet! Appox on Thee!"));
  109.   lcd.clear();  
  110.   lcd.setCursor(0,0); //Start at character 4 on line 0
  111.   lcd.print("!ERROR!");
  112.   delay(500);
  113.     packetStatus = PACKET_NONE;
  114.     nRF905_RX();
  115.   }
  116.   else // this is what it should do when it works properly
  117.   {
  118.     pings++;
  119.     packetStatus = PACKET_NONE;
  120.  
  121.     // Make buffer for data
  122.     uint8_t buffer[NRF905_MAX_PAYLOAD];
  123.     nRF905_read(buffer, sizeof(buffer));
  124. //    Serial.write(buffer, sizeof,(buffer));
  125.  
  126.     Serial.println(F("Ten 4, sending reply..."));
  127.  
  128.     // Send back the data, once the transmission has completed go into receive mode
  129.     while(!nRF905_TX(TXADDR, buffer, sizeof(buffer), NRF905_NEXTMODE_RX));
  130.  
  131.     Serial.println(F("Reply sernt"));
  132.  
  133.     // Toggle LED
  134.     static uint8_t ledState;
  135.     digitalWrite(A5, ledState ? HIGH : LOW);
  136.     ledState = !ledState;
  137.  
  138.     // Print out ping contents
  139.     Serial.print(F("Data from serrrver: "));
  140.     Serial.write(buffer, sizeof(buffer));
  141.     Serial.println();
  142.  
  143.     lcd.clear();
  144.    
  145.   lcd.setCursor(0,0); //Start at character 4 on line 0
  146.   lcd.write(buffer, sizeof(buffer));
  147.   delay(500);
  148.    
  149.   lcd.setCursor(0,1);
  150.   lcd.print("can");
  151.   delay(500);
  152.  
  153.    
  154.  
  155.   }
  156.  
  157.     // Pings & invalids
  158.  
  159. //  Serial.print(F("Totals: "));
  160. //  Serial.print(pings);
  161. //  Serial.print(F(" Pings, "));
  162. //  Serial.print(invalids);
  163. //  Serial.println(F(" Invalid"));
  164. //Serial.println(F("------"));
  165.  
  166.   if (Serial.available()) {
  167.       Serial.print("lol");
  168.       // wait a bit for the entire message to arrive
  169.       delay(100);
  170.       // clear the screen
  171.       lcd.clear();
  172.       // read all the available characters
  173.       while (Serial.available() > 0) {
  174.         // display each character to the LCD
  175.         lcd.write(Serial.read());
  176.       }
  177.     }
  178.  
  179. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top