Skip to content

Instantly share code, notes, and snippets.

@death667b
Created August 31, 2016 04:32
Show Gist options
  • Save death667b/135fc5be978b4dbc32cf8b32564ee9d6 to your computer and use it in GitHub Desktop.
Save death667b/135fc5be978b4dbc32cf8b32564ee9d6 to your computer and use it in GitHub Desktop.
var spiDev = "/dev/spidev0.0";
var cePin = 8;
var irqPin = 5;
var pipes = [0xABCDABCD71, 0x544d52687C];
var nrf = require('nrf');
var radio = nrf.connect(spiDev, cePin, irqPin); // Connect to the radio
radio.channel(0x4c); // Set channel to 76
radio.transmitPower('PA_LOW');
radio.dataRate('1Mbps') // Set data rate to 1Mbps
radio.crcBytes(2) // Set the CRC to 2
radio.autoRetransmit({
count: 15,
delay: 4000
}); // Auto retransmit up to 15 times
// Start the radio
radio.begin(function() {
var rx = radio.openPipe('rx', pipes[0]); // Listen at address
var tx = radio.openPipe('tx', pipes[1]); // Send to address
// Fires when our transmission pipe is ready
tx.on('ready', function() {
console.log("TX Ready");
//tx.write("I-PI!"); // Send a quick "I'm here" message
});
// Fires when our reception pipe is ready
rx.on('ready', function() {
console.log("RX Ready");
radio.printDetails();
});
// Fires when our reception pipe recieves data
rx.on('data', function(d) {
//console.log("Recieved:", d.toString('utf8')); // Decode the data and print
console.log(d.readUIntBE(0, 4));
//tx.write(d); // Send back the same data we just got
});
// Handler for errors
tx.on('error', function(e) {
console.log("Error:", e);
});
rx.on('error', function(e) {
console.log("Error:", e);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment