Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault #1

Closed
luckwaski opened this issue Oct 5, 2017 · 11 comments
Closed

Segmentation fault #1

luckwaski opened this issue Oct 5, 2017 · 11 comments

Comments

@luckwaski
Copy link

Using:

  • Raspberry PI 2 with armv6l
  • Raspbian 4.9.41+
  • Node v8.5.0

Got Segmentation fault when I try to run:

var radio = require('./node_modules/rf24js/build/Release/rf24js.node');
radio.create(2, 10);
radio.begin();

or

var radio = require('rf24js');
radio.create(2, 10);
radio.begin();

@RioloGiuseppe
Copy link
Owner

Hello,
I think it's correct because you are using the orange pi zero pin configuration.
The radio.create function takes two arguments. The first one is the GPIO pin correspondent to the CE pin in of the radio (see radio and raspberry pinout and gpio map), the second one is the spi id.
Run:

ls /dev

You should to see spidev0.0 and/or spidev1.0 if not run:

sudo raspi-config

and turn on spi from Interfacing Options => SPI
Now you have to see spidev0.0 and spidev0.1 on on general spidevX.Y
If you are using the first one the second parameter is 0 otherwise 1.
In general the second parameter is an integer that represent the id of the spi you find in /dev without dot. Example spidev0.0 => 0, spidev0.1 => 1, spidev1.0 => 10, ecc

Best regards
Giuseppe Riolo

@luckwaski
Copy link
Author

Thank you,
changing 10 to 0 helped with Segmentation Fault.
Could you please tell me what should the CE in create(ce, cs) be exactly (using RPI B+) a pin number 22 or coresponding GPIO number (25) ?

@RioloGiuseppe
Copy link
Owner

You are welcome!
According with RF24 RPi bcm header file and this image at pin 22 should correspond gpio 25. A way to be sure your radio is working correctly is run printDetails method.

It should be to print something similar to

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

If you read something like:

STATUS           = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
RX_ADDR_P0-1     = 0x0000000000 0x0000000000
RX_ADDR_P2-5     = 0x00 0x00 0x00 0x00
TX_ADDR          = 0x0000000000
RX_PW_P0-6       = 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA            = 0x00
EN_RXADDR        = 0x00
RF_CH            = 0x00
RF_SETUP         = 0x00
CONFIG           = 0x00
DYNPD/FEATURE    = 0x00 0x00
Data Rate        = 1MBPS
Model            = nRF24L01
CRC Length       = Disabled
PA Power         = PA_MIN

radio is not connected correctly.
If pin22/gpio25 does not work try with some other pin.

Regards
GR

@luckwaski
Copy link
Author

luckwaski commented Oct 5, 2017

Thank you,
so I suppose I'm hooked right - as the printDetails throws somethink like that:

================ SPI Configuration ================
CSN Pin          = CE0 (PI Hardware Driven)
CE Pin           = Custom GPIO25
Clock Speed      = 8 Mhz
================ NRF Configuration ================
STATUS           = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     = 0x65646f4e32 0x65646f4e31
RX_ADDR_P2-5     = 0xc3 0xc4 0xc5 0xc6
TX_ADDR          = 0x65646f4e32
RX_PW_P0-6       = 0x20 0x20 0x00 0x00 0x00 0x00
EN_AA            = 0x3f
EN_RXADDR        = 0x02
RF_CH            = 0x4c
RF_SETUP         = 0x07
CONFIG           = 0x0e
DYNPD/FEATURE    = 0x00 0x00
Data Rate        = 1MBPS
Model            = nRF24L01+
CRC Length       = 16 bits
PA Power         = PA_MAX

Unfortunatelly - trying to pong it in or out with Arduino:

STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1	 = 0x65646f4e32 0x65646f4e31
RX_ADDR_P2-5	 = 0xc3 0xc4 0x63 0x7f
TX_ADDR		 = 0x65646f4e32
RX_PW_P0-6	 = 0x01 0x01 0x00 0x00 0x00 0x3f
EN_AA		 = 0x3f
EN_RXADDR	 = 0x02
RF_CH		 = 0x4c
RF_SETUP	 = 0x00
CONFIG		 = 0x0f
DYNPD/FEATURE	 = 0x03 0x06
Data Rate	 = 1MBPS
Model		 = nRF24L01+
CRC Length	 = 16 bits
PA Power	 = PA_MIN

Gives me timeouts no matter the direction. If you have any advice it would be appreciated.

Thank you!

@RioloGiuseppe
Copy link
Owner

Using nRF/RF24 arduino sample inside arduino and sample.js you find rf24js/samples in orange pi zero I successfully send data from mini-pc to arduino. Unfortunatelly with some problems at receiving time. The next week i will use interrupt and I will try to release a new version (with ts support).

Looking at your arduino trace RF_SETUP register has a different value from minipc. You can try tro look the RF24 arduino samples, specially nRF24L01.h and more specific configurations.

Regards
GR

@luckwaski
Copy link
Author

Thank you again Giuseppe,
for anyone that has problems communicating one way or the other - when everything was checked, rewired and checked again - try replacing the mother board (arduino / pi) - looks like my fake arduino uno is a trash - and wont receive anything no matter what you do.

At the moment it looks I'm on tracks - right now fighting with pockets beeing lost around (done capacitors).
Could you please advice how to use function like setDataRate() ?
Using it like:

radio.setDataRate("RF24_250KBPS");

wont do anything,

radio.setDataRate(RF24_250KBPS);

gets me an undefined error obviously, and

radio.setDataRate(250);

doesnt seems to work either.

Thank you!

@RioloGiuseppe
Copy link
Owner

Hello,
I have not mapped the enums at this time.
For any enum reference please use the low level header file.

According with line 38 of file above, for 250kbps you have to pass 2.
I'm sorry. It will be available with the next release.

Regards
Giuseppe

@luckwaski
Copy link
Author

luckwaski commented Oct 8, 2017

According with line 38 of file above, for 250kbps you have to pass 2.
I'm sorry. It will be available with the next release.

Thank you - that explained everything. No worries - you did a great job so far!

I'm on a phase of planning the packets structure (trying to send few different values in one package, like int, float). Dunno if thats a good place to ask - but maybe you have some good ideas to make it work between C and node.js? Been thinking about C "struct".

@RioloGiuseppe
Copy link
Owner

Hello, thanks you :)

I don't think use c-struct is a good idea. In my project im using a simple high speed byte serializer totally written in typescript. It's not still published but if you clone it, you can see how it works. I use this serializer to convert js object in byte array and vice versa. In the C side I'll read the byte array using a serial message protocol convention.

Serial message protocol convention

Start Length Message# Payload CKS1 CKS2
0x7E 0x08 0x01 0x0000 0x00 0x00

Where

  • start is a convetional byte used to mark the start of a new message (in case of stream)
  • Length is the message len without start and crc
  • Message number is a number used to identificate message and associate an action or a semantic meaning
  • Payload is the content of message (byte array)
  • CRC bytes are the bytes computed excluding start and len

Note: for CRC you can use this

Regards

@luckwaski
Copy link
Author

Note: for CRC you can use this

Thank you - thats a nice module! Could you please advice what can I use for CRC from arduino side? The _crc16_update looks like its only suitable for numbers and gives me 0 for strings.

@RioloGiuseppe
Copy link
Owner

Theoretically you can use any kind of CRC alg/config. I notice that one of the most used crc16 with arduino is CRC16_CCIT_ZERO. You can find helpful the issue at crc-full library about crc in c and javascript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants