Ein Roboter mit bürstenlosem Antrieb, differenzial und NRF24L01 Funk. Großflächig gebaut um ein großes Solarpanel aufzunehmen. https://gitlab.informatik.hs-fulda.de/fdai5253/roboter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
4.9 KiB

  1. /*
  2. This program is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU General Public License
  4. version 2 as published by the Free Software Foundation.
  5. rf24ping85.ino by tong67 ( https://github.com/tong67 )
  6. This is an example of how to use the RF24 class to communicate with ATtiny85 and other node.
  7. Write this sketch to an ATtiny85. It will act like the 'transmit' mode of GettingStarted.ino
  8. Write GettingStarted.ino sketch to UNO (or other board or RPi) and put the node in 'receiver' mode.
  9. The ATtiny85 will transmit a counting number every second starting from 1.
  10. The ATtiny85 uses the tiny-core by CodingBadly (https://code.google.com/p/arduino-tiny/)
  11. When direct use of 3v3 does not work (UNO boards have bad 3v3 line) use 5v with LED (1.8V ~ 2.2V drop)
  12. For low power consumption solutions floating pins (SCK and MOSI) should be pulled high or low with eg. 10K
  13. ** Hardware configuration **
  14. ATtiny25/45/85 Pin map with CE_PIN 3 and CSN_PIN 4
  15. +-\/-+
  16. NC PB5 1|o |8 Vcc --- nRF24L01 VCC, pin2 --- LED --- 5V
  17. nRF24L01 CE, pin3 --- PB3 2| |7 PB2 --- nRF24L01 SCK, pin5
  18. nRF24L01 CSN, pin4 --- PB4 3| |6 PB1 --- nRF24L01 MOSI, pin7
  19. nRF24L01 GND, pin1 --- GND 4| |5 PB0 --- nRF24L01 MISO, pin6
  20. +----+
  21. ATtiny25/45/85 Pin map with CE_PIN 3 and CSN_PIN 3 => PB3 and PB4 are free to use for application
  22. Circuit idea from http://nerdralph.blogspot.ca/2014/01/nrf24l01-control-with-3-attiny85-pins.html
  23. Original RC combination was 1K/100nF. 22K/10nF combination worked better.
  24. For best settletime delay value in RF24::csn() the timingSearch3pin.ino scatch can be used.
  25. This configuration is enabled when CE_PIN and CSN_PIN are equal, e.g. both 3
  26. Because CE is always high the power consumption is higher than for 5 pins solution
  27. ^^
  28. +-\/-+ nRF24L01 CE, pin3 ------| //
  29. PB5 1|o |8 Vcc --- nRF24L01 VCC, pin2 ------x----------x--|<|-- 5V
  30. NC PB3 2| |7 PB2 --- nRF24L01 SCK, pin5 --|<|---x-[22k]--| LED
  31. NC PB4 3| |6 PB1 --- nRF24L01 MOSI, pin6 1n4148 |
  32. nRF24L01 GND, pin1 -x- GND 4| |5 PB0 --- nRF24L01 MISO, pin7 |
  33. | +----+ |
  34. |-----------------------------------------------||----x-- nRF24L01 CSN, pin4
  35. 10nF
  36. ATtiny24/44/84 Pin map with CE_PIN 8 and CSN_PIN 7
  37. Schematic provided and successfully tested by Carmine Pastore (https://github.com/Carminepz)
  38. +-\/-+
  39. nRF24L01 VCC, pin2 --- VCC 1|o |14 GND --- nRF24L01 GND, pin1
  40. PB0 2| |13 AREF
  41. PB1 3| |12 PA1
  42. PB3 4| |11 PA2 --- nRF24L01 CE, pin3
  43. PB2 5| |10 PA3 --- nRF24L01 CSN, pin4
  44. PA7 6| |9 PA4 --- nRF24L01 SCK, pin5
  45. nRF24L01 MOSI, pin7 --- PA6 7| |8 PA5 --- nRF24L01 MISO, pin6
  46. +----+
  47. */
  48. // CE and CSN are configurable, specified values for ATtiny85 as connected above
  49. #define CE_PIN 3
  50. #define CSN_PIN 4
  51. //#define CSN_PIN 3 // uncomment for ATtiny85 3 pins solution
  52. #include "RF24.h"
  53. RF24 radio(CE_PIN, CSN_PIN);
  54. byte addresses[][6] = {
  55. "1Node","2Node"};
  56. unsigned long payload = 0;
  57. void setup() {
  58. // Setup and configure rf radio
  59. radio.begin(); // Start up the radio
  60. radio.setAutoAck(1); // Ensure autoACK is enabled
  61. radio.setRetries(15,15); // Max delay between retries & number of retries
  62. radio.openWritingPipe(addresses[1]); // Write to device address '2Node'
  63. radio.openReadingPipe(1,addresses[0]); // Read on pipe 1 for device address '1Node'
  64. radio.startListening(); // Start listening
  65. }
  66. void loop(void){
  67. radio.stopListening(); // First, stop listening so we can talk.
  68. payload++;
  69. radio.write( &payload, sizeof(unsigned long) );
  70. radio.startListening(); // Now, continue listening
  71. unsigned long started_waiting_at = micros(); // Set up a timeout period, get the current microseconds
  72. boolean timeout = false; // Set up a variable to indicate if a response was received or not
  73. while ( !radio.available() ){ // While nothing is received
  74. if (micros() - started_waiting_at > 200000 ){ // If waited longer than 200ms, indicate timeout and exit while loop
  75. timeout = true;
  76. break;
  77. }
  78. }
  79. if ( !timeout ){ // Describe the results
  80. unsigned long got_time; // Grab the response, compare, and send to debugging spew
  81. radio.read( &got_time, sizeof(unsigned long) );
  82. }
  83. // Try again 1s later
  84. delay(1000);
  85. }