Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. var spiDev = "/dev/spidev0.0";
  2. var cePin = 24;
  3. var irqPin = 25;
  4.  
  5. var nrf = require('nrf');
  6. var radio = nrf.connect(spiDev, cePin, irqPin); // Connect to the radio
  7. radio.channel(0x4c); // Set channel to 76
  8. radio.dataRate('1Mbps') // Set data rate to 1Mbps
  9. radio.crcBytes(2) // Set the CRC to 2
  10. radio.autoRetransmit({
  11. count: 15,
  12. delay: 4000
  13. }); // Auto retransmit up to 15 times
  14.  
  15. // Start the radio
  16. radio.begin(function() {
  17.  
  18. var rx = radio.openPipe('rx', 0xF0F0F0F0E1); // Listen at address
  19. var tx = radio.openPipe('tx', 0xF5F0F0F0F2); // Send to address
  20.  
  21. // Fires when our transmission pipe is ready
  22. tx.on('ready', function() {
  23. console.log("TX Ready");
  24. tx.write("I-PI!"); // Send a quick "I'm here" message
  25. });
  26.  
  27. // Fires when our reception pipe is ready
  28. rx.on('ready', function() {
  29. console.log("RX Ready");
  30. radio.printDetails();
  31. });
  32.  
  33. // Fires when our reception pipe recieves data
  34. rx.on('data', function(d) {
  35. console.log("Recieved:", d.toString('utf8')); // Decode the data and print
  36. tx.write(d); // Send back the same data we just got
  37. });
  38.  
  39. // Handler for errors
  40. tx.on('error', function(e) {
  41. console.log("Error:", e);
  42. });
  43. rx.on('error', function(e) {
  44. console.log("Error:", e);
  45. });
  46. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement