natevw / node-nrf

Pure-JavaScript nRF24L01 driver library
117 stars 31 forks source link

Strange test-details output #26

Closed laktak closed 9 years ago

laktak commented 9 years ago

I've connected an NRF24L01 to an Raspberry Pi B+ (triple checked):

RPi GPIO9   (Pin 21)  to RF Module Pin 7 ( MISO )
RPi GPIO10  (Pin 19)  to RF Module Pin 6 ( MOSI )
RPi GPIO11  (Pin 23)  to RF Module Pin 5 ( SCK )
RPi GPIO25  (Pin 22)  to RF Module Pin 4 ( CSN )
RPi GPIO8   (Pin 24)  to RF Module Pin 3 ( CE )
RPI 3.3V    (Pin 17)  to RF Module Pin 2 ( VCC/3.3V )
RPi Gnd     (Pin 25)  to RF Module Pin 1 (GND)

But sudo node test-details.js /dev/spidev0.0 24 0 gives me this strange output:

SPI device:  /dev/spidev0.0
CE GPIO:     24
IRQ GPIO:    undefined
STATUS:      0x6 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=3 TX_FULL=0
RX_ADDR_P0–1:  0x0606060606 0x0606060606
RX_ADDR_P2–5:  0x06 0x06 0x06 0x06
TX_ADDR:     0x0606060606
RX_PW_P0–5:    0x6 0x6 0x6 0x6 0x6 0x6
EN_AA:       0x06
EN_RXADDR:   0x06
RF_CH:       0x6
RF_SETUP:    0x06
CONFIG:      0x06
DYNPD/FEATURE:   0x06 0x06
Data Rate:   1Mbps
Model:       nRF24L01
CRC Length:  Disabled
PA Power:    PA_MAX

What's the expected output?

natevw commented 9 years ago

Seems like now you're just picking up some sort of periodic "ticking" signal instead of actual SPI signals.

This always confuses me too, but I'm pretty sure all the pins node-nrf/pi-pins deals with are the GPIO numbers, not the actual header pin numbers. So when it says "CE GPIO: 24" but you have it connected to GPIO8, that is likely part of your problem.

Also your CSN should probably be connected to (physical header) pin 24 which appears on some RasPi pinouts as "SP10 CE0 N". Please do not confuse this with the transceiver's CE, which is not the SPI select. You need to use one of the two dedicated SPI chip select pins for CSN, and use a GPIO port for CE.

Once this is sorted, should get something that looks a lot more like the outputs logged on other tickets or similar to the Arduino library's printDetails call, e.g.

STATUS           = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     = 0xe7e7e7e7e7 0xf0f0f0f0d2
RX_ADDR_P2-5     = 0xc3 0xc4 0xc5 0xc6
TX_ADDR          = 0xe7e7e7e7e7
RX_PW_P0-6       = 0x00 0x20 0x00 0x00 0x00 0x00
EN_AA            = 0x3f
EN_RXADDR        = 0x03
RF_CH            = 0x4c
RF_SETUP         = 0x07
CONFIG           = 0x0f
DYNPD/FEATURE    = 0x00 0x00
Data Rate        = 1MBPS
Model            = nRF24L01+
CRC Length       = 16 bits
PA Power         = PA_HIGH
natevw commented 9 years ago

Here are the connections I've usually been starting with, btw: https://gist.github.com/natevw/5789019

laktak commented 9 years ago

Hey thanks for the connections! I was following this tutorial where CE and CSN were mixed up somehow.

I now have Pi and Arduino talking to each other via RF24 but no luck with node-nrf. With node-nrf the Pi never reacts to the Aruino and vice versa.

I'm not sure what I'm doing wrong ... do you have any sugestions or do you have a sample?

(I did sudo modprobe -r spi_bcm2708; sudo modprobe spi_bcm2708)

Node says this:

$ sudo node test.js
PONG back
SPI device:  /dev/spidev0.0
CE GPIO:     24
IRQ GPIO:    25
STATUS:      0xe RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0–1:  0xf0f0f0f0d2 0xf0f0f0f0e1
RX_ADDR_P2–5:  0xc3 0xc4 0xc5 0xc6
TX_ADDR:     0xf0f0f0f0e1
RX_PW_P0–5:    0x4 0x4 0x0 0x0 0x0 0x0
EN_AA:       0x3f
EN_RXADDR:   0x03
RF_CH:       0x2
RF_SETUP:    0x07
CONFIG:      0x0f
DYNPD/FEATURE:   0x03 0x07
Data Rate:   1Mbps
Model:       nRF24L01+
CRC Length:  16 bits
PA Power:    PA_MAX

Doese FEATURE=0x7 matter?

And the Arduino:

RF24/examples/GettingStarted/
*** PRESS 'T' to begin transmitting to the other node
STATUS       = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     = 0xf0f0f0f0d2 0xf0f0f0f0e1
RX_ADDR_P2-5     = 0xc3 0xc4 0xc5 0xc6
TX_ADDR      = 0xf0f0f0f0d2
RX_PW_P0-6   = 0x20 0x20 0x00 0x00 0x00 0x00
EN_AA        = 0x3f
EN_RXADDR    = 0x02
RF_CH        = 0x02
RF_SETUP     = 0x07
CONFIG       = 0x0f
DYNPD/FEATURE    = 0x00 0x00
Data Rate    = 1MBPS
Model        = nRF24L01+
CRC Length   = 16 bits
PA Power     = PA_MAX
*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK
Now sending 
failed.
Failed, response timed out.
laktak commented 9 years ago

Still can't get it to work...

I connected

RPi GPIO25          (Pin 22)  to RF Module Pin 8 (IRQ)
RPi GPIO9  SPI_MISO (Pin 21)  to RF Module Pin 7 (MISO)
RPi GPIO10 SPI_MOSI (Pin 19)  to RF Module Pin 6 (MOSI)
RPi GPIO11 SPI_CLK  (Pin 23)  to RF Module Pin 5 (SCK)
RPi GPIO8  SPI_CE0N (Pin 24)  to RF Module Pin 4 (CSN)
RPi GPIO24          (Pin 18)  to RF Module Pin 3 (CE)
RPI 3.3V            (Pin 17)  to RF Module Pin 2 (VCC/3.3V)
RPi Gnd             (Pin 25)  to RF Module Pin 1 (GND)

And it works with RF24 with this config:

RF24 radio(RPI_BPLUS_GPIO_J8_18 /*CE*/, RPI_BPLUS_GPIO_J8_24 /*CSN*/, BCM2835_SPI_SPEED_8MHZ);

The correct node-nrf config is spiDev = "/dev/spidev0.0", cePin = 24, irqPin = 25, right? (I also tried cePin = 18, irqPin = 22 without success).

natevw commented 9 years ago

That's looking much better now! Pretty sure the ce=24/irq=25 version is what you need as well. Now perhaps the only thing, since you've been using the C++ library, maybe you just need to "unbreak" the kernel SPI stack as described here? https://github.com/natevw/node-nrf/issues/1#issuecomment-32395546

laktak commented 9 years ago

Yes, 24/25 were correct. I already did the modprobe thing.

After doing this

  radio.enableDynamicPayloads();
  radio.enableAckPayload();

on the Arduino (RF24) I can actually receive on the Pi and it responds (no errors).

What I don't understand is that when I send from the Pi and receive on the Arduino I still get nothing. The Arduino receives the response when it pings so why doesn't it work the other way?

laktak commented 9 years ago

Still the same issue but I enabled your debug switch. I'm using your test.js sample with this (instead of the CountStream):

var ccc=1;
function writeTx(tx) {
  console.log("Piping out", ccc);
  var b=new Buffer(4);
  b.writeUInt32BE(ccc++, 0);
  tx.push(b);
  setTimeout(function() {writeTx(tx);}, 1000);
}

And get:

Piping out 12
_checkStatus, irq = false checking = false
execCommand [ 'R_REGISTER', 7 ] 1
 - exec read: <Buffer 0e 0e>
gotStates { RX_P_NO: 7, TX_DS: 0, MAX_RT: 0, RX_DR: 0 } null
Piping out 13

Shouldn't I see W_TX_PAYLOAD?

Also is tx.push() correct? (with write I get no debug output)

natevw commented 9 years ago

tx.push() is not correct, this is an internal stream method and unless you are implementing a stream subclass you should use tx.write(). That there is a difference makes me think it is waiting for an earlier write to complete. (I wonder maybe if this could happen if there's an issue with the IRQ pin? Might be able to guess better if you could paste the full output [from startup] to gist.github.com.)

laktak commented 9 years ago

I've uploded it here. I'd appreciate if you can take a look.

I tested it with a new module, new cables, even disabled the irq pin (NRF24.connect(spiDev, cePin)) but I always get the same result.

Could it be the node --version v0.10.28? Or any of these?

nrf@0.8.2 node_modules/nrf
├── fifolock@1.0.0
├── queue-async@1.0.7
├── pi-spi@0.8.7
└── pi-pins@1.0.2 (epoll@0.1.10)

It works with RF24 without problems.

laktak commented 9 years ago

switched to a different solution, thanks.