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 <Servo.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
- int servoPin = 6;
- Servo servo;
- int servoAngle = 0;
- 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);
- servo.attach(servoPin);
- Serial.println(F("Server started"));
- 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 ----"));
- // Wait for data
- while(packetStatus == PACKET_NONE);
- if(packetStatus != PACKET_OK)
- {
- invalids++;
- Serial.println(F("Invalid packet! Appox on Thee!"));
- //Serial.println("Haven't seen this one yet");
- 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.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;
- // char cats = (buffer, sizeof(buffer));
- int cats; // Print out ping contents
- Serial.print(F("Data from serrrver: "));
- Serial.write(buffer, sizeof(buffer));
- FFF = Serial.write(buffer, sizeof(buffer));
- Serial.println();
- Serial.println("cats >>>");
- Serial.println(cats);
- // servo.write(buffer, sizeof(buffer));
- delay(500);
- // servo.write(20);
- // delay(1000);
- }
- // Pings & invalids
- // Serial.print(F("Totals: "));
- // Serial.print(pings);
- // Serial.print(F(" Pings, "));
- // Serial.print(invalids);
- // Serial.println(F(" Invalid"));
- //Serial.println(F("------"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement