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.

134 lines
3.2 KiB

  1. /*
  2. *
  3. * Filename : rpi-hub.cpp
  4. *
  5. * This program makes the RPi as a hub listening to all six pipes from the remote sensor nodes ( usually Arduino )
  6. * and will return the packet back to the sensor on pipe0 so that the sender can calculate the round trip delays
  7. * when the payload matches.
  8. *
  9. * I encounter that at times, it also receive from pipe7 ( or pipe0 ) with content of FFFFFFFFF that I will not sent
  10. * back to the sender
  11. *
  12. * Refer to RF24/examples/rpi_hub_arduino/ for the corresponding Arduino sketches to work with this code.
  13. *
  14. *
  15. * CE is not used and CSN is GPIO25 (not pinout)
  16. *
  17. * Refer to RPi docs for GPIO numbers
  18. *
  19. * Author : Stanley Seow
  20. * e-mail : stanleyseow@gmail.com
  21. * date : 6th Mar 2013
  22. *
  23. * 03/17/2013 : Charles-Henri Hallard (http://hallard.me)
  24. * Modified to use with Arduipi board http://hallard.me/arduipi
  25. * Changed to use modified bcm2835 and RF24 library
  26. *
  27. *
  28. */
  29. #include <cstdlib>
  30. #include <iostream>
  31. #include <RF24/RF24.h>
  32. using namespace std;
  33. // Radio pipe addresses for the 2 nodes to communicate.
  34. // First pipe is for writing, 2nd, 3rd, 4th, 5th & 6th is for reading...
  35. const uint64_t pipes[6] =
  36. { 0xF0F0F0F0D2LL, 0xF0F0F0F0E1LL,
  37. 0xF0F0F0F0E2LL, 0xF0F0F0F0E3LL,
  38. 0xF0F0F0F0F1, 0xF0F0F0F0F2
  39. };
  40. // CE Pin, CSN Pin, SPI Speed
  41. // Setup for GPIO 22 CE and GPIO 25 CSN with SPI Speed @ 1Mhz
  42. //RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_18, BCM2835_SPI_SPEED_1MHZ);
  43. // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
  44. //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
  45. // Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz
  46. RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
  47. int main(int argc, char** argv)
  48. {
  49. uint8_t len;
  50. // Refer to RF24.h or nRF24L01 DS for settings
  51. radio.begin();
  52. radio.enableDynamicPayloads();
  53. radio.setAutoAck(1);
  54. radio.setRetries(15,15);
  55. radio.setDataRate(RF24_1MBPS);
  56. radio.setPALevel(RF24_PA_MAX);
  57. radio.setChannel(76);
  58. radio.setCRCLength(RF24_CRC_16);
  59. // Open 6 pipes for readings ( 5 plus pipe0, also can be used for reading )
  60. radio.openWritingPipe(pipes[0]);
  61. radio.openReadingPipe(1,pipes[1]);
  62. radio.openReadingPipe(2,pipes[2]);
  63. radio.openReadingPipe(3,pipes[3]);
  64. radio.openReadingPipe(4,pipes[4]);
  65. radio.openReadingPipe(5,pipes[5]);
  66. //
  67. // Start listening
  68. //
  69. radio.startListening();
  70. //
  71. // Dump the configuration of the rf unit for debugging
  72. //
  73. radio.printDetails();
  74. printf("Output below : \n");
  75. delay(1);
  76. while(1)
  77. {
  78. char receivePayload[32];
  79. uint8_t pipe = 1;
  80. // Start listening
  81. radio.startListening();
  82. while ( radio.available(&pipe) )
  83. {
  84. len = radio.getDynamicPayloadSize();
  85. radio.read( receivePayload, len );
  86. // Display it on screen
  87. printf("Recv: size=%i payload=%s pipe=%i",len,receivePayload,pipe);
  88. // Send back payload to sender
  89. radio.stopListening();
  90. // if pipe is 7, do not send it back
  91. if ( pipe != 7 )
  92. {
  93. radio.write(receivePayload,len);
  94. receivePayload[len]=0;
  95. printf("\t Send: size=%i payload=%s pipe:%i\n",len,receivePayload,pipe);
  96. }
  97. else
  98. {
  99. printf("\n");
  100. }
  101. pipe++;
  102. // reset pipe to 0
  103. if ( pipe > 6 )
  104. pipe = 0;
  105. }
  106. delayMicroseconds(20);
  107. }
  108. return 0;
  109. }