Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Project: nRF905 AVR/Arduino Library/Driver (Low power ping server example)
- * Author: Zak Kemble, contact@zakkemble.co.uk
- * Copyright: (C) 2017 by Zak Kemble
- * License: GNU GPL v3 (see License.txt)
- * Web: http://blog.zakkemble.co.uk/nrf905-avrarduino-librarydriver/
- */
- /*
- * Low power ping server
- *
- * Similar to the pin server example
- * Output power is set to the lowest setting, receive sensitivity is lowered.
- *
- * 7 -> CE
- * 8 -> PWR
- * 9 -> TXE
- * 4 -> CD
- * 3 -> DR
- * 2 -> AM
- * 10 -> CSN
- * 12 -> SO
- * 11 -> SI
- * 13 -> SCK
- */
- #include <nRF905.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #define RXADDR 0x586F2E10 // Address of this device
- #define TXADDR 0xFE4CA6E5 // Address of device to send to
- #define PACKET_NONE 0
- #define PACKET_OK 1
- #define PACKET_INVALID 2
- //long omfg;
- LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6,7,3,POSITIVE);
- static volatile uint8_t packetStatus;
- void NRF905_CB_RXCOMPLETE(void)
- {
- packetStatus = PACKET_OK;
- nRF905_standby();
- }
- void NRF905_CB_RXINVALID(void)
- {
- packetStatus = PACKET_INVALID;
- nRF905_standby();
- }
- void setup()
- {
- Serial.begin(115200);
- Serial.println(F("Server started"));
- lcd.begin(16, 2);
- for(int i = 0; i<3; i++)
- {
- lcd.backlight();
- delay(250);
- lcd.noBacklight();
- delay(250);
- }
- lcd.backlight();
- pinMode(A5, OUTPUT); // LED
- // Start up
- nRF905_init();
- // Set address of this device
- nRF905_setListenAddress(RXADDR);
- // Lowest transmit level -10db
- nRF905_setTransmitPower(NRF905_PWR_n10);
- // Reduce receive sensitivity to save a few mA
- nRF905_setLowRxPower(NRF905_LOW_RX_ENABLE);
- // Put into receive mode
- nRF905_RX();
- }
- void loop() // Loop > while / if
- {
- static uint32_t pings;
- static uint32_t invalids;
- static uint32_t volts;
- Serial.println(F("---- Incoming Message ----"));
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("TEST help");
- delay(500);
- // Wait for data
- while(packetStatus == PACKET_NONE);
- if(packetStatus != PACKET_OK)
- {
- invalids++;
- Serial.println(F("Invalid packet! Appox on Thee!"));
- lcd.clear();
- lcd.setCursor(0,0); //Start at character 4 on line 0
- lcd.print("!ERROR!");
- delay(500);
- packetStatus = PACKET_NONE;
- nRF905_RX();
- }
- else // this is what it should do when it works properly
- {
- pings++;
- packetStatus = PACKET_NONE;
- // Make buffer for data
- uint8_t buffer[NRF905_MAX_PAYLOAD];
- nRF905_read(buffer, sizeof(buffer));
- // Serial.write(buffer, sizeof,(buffer));
- Serial.println(F("Ten 4, sending reply..."));
- // Send back the data, once the transmission has completed go into receive mode
- while(!nRF905_TX(TXADDR, buffer, sizeof(buffer), NRF905_NEXTMODE_RX));
- Serial.println(F("Reply sernt"));
- // Toggle LED
- static uint8_t ledState;
- digitalWrite(A5, ledState ? HIGH : LOW);
- ledState = !ledState;
- // Print out ping contents
- Serial.print(F("Data from serrrver: "));
- Serial.write(buffer, sizeof(buffer));
- Serial.println();
- lcd.clear();
- lcd.setCursor(0,0); //Start at character 4 on line 0
- lcd.write(buffer, sizeof(buffer));
- delay(500);
- lcd.setCursor(0,1);
- lcd.print("can");
- delay(500);
- }
- // Pings & invalids
- // Serial.print(F("Totals: "));
- // Serial.print(pings);
- // Serial.print(F(" Pings, "));
- // Serial.print(invalids);
- // Serial.println(F(" Invalid"));
- //Serial.println(F("------"));
- if (Serial.available()) {
- Serial.print("lol");
- // wait a bit for the entire message to arrive
- delay(100);
- // clear the screen
- lcd.clear();
- // read all the available characters
- while (Serial.available() > 0) {
- // display each character to the LCD
- lcd.write(Serial.read());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement