Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1.  
  2.  
  3. //NRF24
  4. #include "RF24.h"
  5. #include "RF24Network.h"
  6. #include "RF24Mesh.h"
  7. #include <SPI.h>
  8. #include <EEPROM.h>
  9.  
  10. //BNO 055
  11. #include <Wire.h>
  12. #include <Adafruit_Sensor.h>
  13. #include <Adafruit_BNO055.h>
  14. #include <utility/imumaths.h>
  15. //#include <printf.h>
  16.  
  17. RF24 radio(7, 8);
  18. RF24Network network(radio);
  19. RF24Mesh mesh(radio, network);
  20.  
  21. #define nodeID 1
  22. #define BNO055_SAMPLERATE_DELAY_MS (100)
  23.  
  24. Adafruit_BNO055 bno = Adafruit_BNO055();
  25.  
  26. uint32_t displayTimer = 0;
  27. uint32_t rotary = 0;
  28. int updateRate = 200;
  29.  
  30. void setup() {
  31.  
  32. Serial.begin(115200);
  33. pinMode(9, OUTPUT);
  34. digitalWrite(9, HIGH);
  35. if (!bno.begin())
  36. {
  37. Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
  38. while (1);
  39. }
  40.  
  41. delay(1000);
  42. digitalWrite(9, LOW);
  43.  
  44. /* Display the current temperature */
  45. int8_t temp = bno.getTemp();
  46. Serial.print("Current Temperature: ");
  47. Serial.print(temp);
  48. Serial.println(" C");
  49. Serial.println("");
  50.  
  51. bno.setExtCrystalUse(true);
  52.  
  53. mesh.setNodeID(nodeID);
  54. // Connect to the mesh
  55. Serial.println(F("Connecting to the mesh..."));
  56. mesh.begin();
  57.  
  58.  
  59. }
  60.  
  61.  
  62.  
  63. void loop() {
  64.  
  65. mesh.update();
  66.  
  67. // Send to the master node every second
  68. if (millis() - displayTimer >= updateRate) {
  69. displayTimer = millis();
  70. //sendData(displayTimer, 'M');
  71. // sendData(rotary++, 'R');
  72. imu::Quaternion quat = bno.getQuat();
  73. sendData((quat.w()), 'W');
  74. sendData((quat.x()), 'X');
  75. sendData((quat.y()), 'Y');
  76. sendData((quat.z()), 'Z');
  77.  
  78.  
  79. }
  80.  
  81. }
  82.  
  83. bool sendData(double value, char type) {
  84. bool messageSend;
  85. digitalWrite(9, HIGH);
  86. if (!mesh.write(&value, type, sizeof(value))) {
  87.  
  88. if ( ! mesh.checkConnection() ) {
  89. Serial.println("Renewing Address");
  90. mesh.renewAddress();
  91. } else {
  92. Serial.println("Send fail, Test OK");
  93. messageSend = false;
  94. }
  95. } else {
  96. Serial.print("Send OK: "); Serial.println(value);
  97. messageSend = true;
  98. digitalWrite(9, LOW);
  99.  
  100. }
  101.  
  102. /*while (network.available()) {
  103. RF24NetworkHeader header;
  104. payload_t payload;
  105. network.read(header, &payload, sizeof(payload));
  106. Serial.print("Received packet #");
  107. Serial.print(payload.counter);
  108. Serial.print(" at ");
  109. Serial.println(payload.ms);
  110. }*/
  111. return messageSend;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement