-
• #2
I'm not sure anyone got it working, which does seem particularly strange. What was the BASE_CONFIG change you made? It'd be good to update the NRF24 initialisation to bring it more in line with Arduino's (and maybe automatically set the channel on startup).
Just wondering, are the payload sizes the same? Looks like Arduino's is 16 and Espruino's is 32?
-
• #3
RX_PW_P1 is 0x20 (32) on arduino, that's 32 byte payload by my understanding? I had tried it with 16 bytes as well.
My modified version of the module
function b(a,c,e,b){this.CSN=c;this.CE=e;this.PAYLOAD=b?b:16;this.cmd="";this.spi=a;this.callbacks=[]}b.prototype.init=function(a,c){digitalWrite(this.CE,0);digitalWrite(this.CSN,1);this.setRXAddr(a);this.setTXAddr(c);for(var b=17;22>=b;b++)this.setReg(b,this.PAYLOAD);this.setReg(0,15);this.setReg(4,95);digitalWrite(this.CE,1)};b.prototype.setEnabled=function(a){digitalWrite(this.CE,a)};b.prototype.setReg=function(a,c){this.spi.send([32|a,c],this.CSN)};b.prototype.setAddr=function(a,c){c= c.clone();c.splice(0,0,32|a);this.spi.send(c,this.CSN)};b.prototype.setRXAddr=function(a,c){void 0===c?c=1:this.setReg(2,this.getReg(2)|1<<c);this.setAddr(10+c,2>c?a:[a[0]])};b.prototype.setTXAddr=function(a){this.setAddr(10,a);this.setAddr(16,a)};b.prototype.getReg=function(a){return this.spi.send([0|a,0],this.CSN)[1]};b.prototype.getAddr=function(a){a=this.spi.send([0|a,0,0,0,0,0],this.CSN);a.splice(0,1);return a};b.prototype.getStatus=function(a){return this.getReg(7)};b.prototype.setDataRate= function(a){var c={25E4:32,1E6:0,2E6:8};!a in c&&console.log("Unknown rate");this.setReg(6,this.getReg(6)&-41|c[a])};b.prototype.getDataPipe=function(){var a=this.getReg(7)&14;return 14==a?void 0:a>>1};b.prototype.getData=function(){for(var a=[97],c=0;c<this.PAYLOAD;c++)a.push(0);a=this.spi.send(a,this.CSN);a.splice(0,1);this.setReg(7,64);return a};b.prototype.send=function(a){this.setReg(7,48);digitalWrite(this.CE,0);this.setReg(0,14);this.spi.send(225,this.CSN);a=a.clone();a.splice(0,0,160);this.spi.send(a, this.CSN);digitalWrite(this.CE,1);for(a=1E3;a--&&!(this.getReg(7)&48););0>=a&&print("TX timeout");a=!0;this.getReg(7)&16&&(print("TX not received "+this.getReg(7)),a=!1);digitalWrite(this.CE,0);this.setReg(0,15);digitalWrite(this.CE,1);this.setReg(7,48);return a};b.prototype.slaveHandler=function(){for(;void 0!==this.getDataPipe();){var a=this.getData(),c;for(c in a){var b=a[c];if(0===b&&""!==this.cmd){var d=this.cmd;this.cmd="";var f=this;setTimeout(function(){print("...>"+d);var a=""+eval(d);print("...="+ a);f.sendStringTimeout(a,500)},1)}else 0!==b&&(this.cmd+=String.fromCharCode(b))}}};b.prototype.masterHandler=function(){for(;void 0!==this.getDataPipe();){var a=this.getData(),c;for(c in a){var b=a[c];if(0===b&&""!==this.cmd){b=this.cmd;this.cmd="";var d=this.callbacks.splice(0,1)[0];void 0!==d&&d(b)}else 0!==b&&(this.cmd+=String.fromCharCode(b))}}};b.prototype.sendString=function(a){for(var c=0;c<=a.length;c+=this.PAYLOAD){for(var b=[],d=0;d<this.PAYLOAD;d++)b[d]=a.charCodeAt(c+d);if(!this.send(b))return!1}return!0}; b.prototype.sendCommand=function(a,b){this.callbacks.push(b);this.sendString(a)};b.prototype.sendStringTimeout=function(a,b){var e=this;setTimeout(function(){e.sendString(a)},b)};exports.connect=function(a,c,e,d){return new b(a,c,e,d)}
BASE_CONFIG was 8, is now 12
Difference in the minified code is the two setReg(0,11) calls are now setReg(0,15), and setReg(0,10) changed to setReg(0,14)
-
• #4
did you manage to link the modules? If yes, is there an example?
-
• #6
I never made it work back then. Never had much luck with the nrf's
Has anyone managed to make this work?
I'm using the RF24 arduino library from here:
https://github.com/TMRh20/RF24
Espruino:
My version of the NRF module was modified to change the BASE_CONFIG to use 2-byte CRC, since the arduino library wants that; no other changes.
Code on Arduino side (hacked up from an example)
Serial output is this - which all looks right:
On the Espruino, I try to do:
I remember reading a post by someone else doing this - I can't seem to find it now though. I'm wondering if they ever got it working.... The NRF24 should be a great way to do simple communications between an Espruino and one or more less-capable Arduino-like devices tucked into corners, or located outdoors, etc.