i have bought a arduino nano with a nrf2401 but the CRC_lenght is disable when i use the nf24/exemple/scanne
this is what i get
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
000000000000000011111111111111112222222222222222333333333333333344444444444444445555555555555555666666666666666677777777777777
0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcd
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
and i found on the web that normally it need to be like this
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 = 0x0c
DYNPD/FEATURE = 0x00 0x00
Data Rate = 1MBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_HIGH
why is the CRC Length and other things are not the same other things can be because of the brand but the most weird thing is hy CRC Length is disable instead off 16 bits
this is the cable settings
CE=pin7
CSN=pin8
SCK=pin13
MO=pin11
MI=pin12
of corse i have change this line RF24 radio(7,8); with the CE and CSN pin
"normally it need to be like this"
Why do you think that? Nothing needs to be like this unless you want to have the very same outcome.
NRF2401 has 144 configuration bits and they exist so you can configure them to your liking/needs.
As for all configurable things there are different configurations.
Yours looks like some default configuration as most values are 0 or disabled what I would expect when nothing has been configured yet.
Related
I am trying to read a series of data via serial port. Below are my test scenarios:
I have a sender (POS terminal) and a receiver (dll) on windows 10. Both connected via RS232 cable (9 pins).
The sender writes 16 bytes of data at one time. The receiver is able to read the data, 1 byte per read, by looping 16 times.
The sender writes 114 bytes of data at one time. The receiver is able to read the data , 1 byte per read, by looping 114 times.
The sender writes 115 bytes of data at one time. The receiver is able to read the data, 1 byte per read, by looping 115 times. But the last character is lost. In other words, the last character seems to be corrupted.
E.g. Data written: ABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNO
I am able to get "ABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMNOPQRSTABCDEFGHIJKLMN" correctly. But the last character 'O' is corrupted. Instead the data read in place of last character is (ASCII value) 205, 255, 234 etc. The data is not consistent during multiple read attempts.
Can anyone please put some light on this? Can anyone guide me if I am missing something-somewhere?
I referred this article for my project: Serial Port Communication
Below is the code snippet:
//Port opening.
HANDLE hPortDailUp = CreateFile(portfinal,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_ALWAYS,
0,
NULL);
//Setting COM timeouts.
SetCommMask(hPortDailUp, 0);
SetupComm(hPortDailUp, 2048, 2048);
GetCommTimeouts (hPortDailUp, &commTimeOuts);
commTimeOuts.ReadIntervalTimeout = 100;
commTimeOuts.ReadTotalTimeoutMultiplier = 70;
commTimeOuts.ReadTotalTimeoutConstant = 1000; //1000
commTimeOuts.WriteTotalTimeoutMultiplier = 0;
commTimeOuts.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(hPortDailUp, &commTimeOuts);
//Setting port configuration.
DCB PortDCB;
PortDCB.DCBlength = sizeof(DCB);
PortDCB.BaudRate = BaudRate;
PortDCB.ByteSize = 8;
PortDCB.Parity = NOPARITY;
PortDCB.StopBits = ONESTOPBIT;
PortDCB.fOutxCtsFlow = RTS_CONTROL_DISABLE;
PortDCB.fRtsControl = RTS_CONTROL_DISABLE;
SetCommState(hPortDailUp, &PortDCB)
//Reading data from serial port.
unsigned char tempRecvBuf[3001] = {'\0'};
ReadFile(hPortDailUp, tempRecvBuf + nBytesRead, 1, &TempLen, NULL);
//PortDCB Value at runtime.
PortDCB {DCBlength=28 BaudRate=115200 fBinary=1 ...} _DCB
DCBlength 28 unsigned long
BaudRate 115200 unsigned long
fBinary 1 unsigned long
fParity 0 unsigned long
fOutxCtsFlow 0 unsigned long
fOutxDsrFlow 0 unsigned long
fDtrControl 1 unsigned long
fDsrSensitivity 0 unsigned long
fTXContinueOnXoff 0 unsigned long
fOutX 0 unsigned long
fInX 0 unsigned long
fErrorChar 0 unsigned long
fNull 0 unsigned long
fRtsControl 0 unsigned long
fAbortOnError 0 unsigned long
fDummy2 0 unsigned long
wReserved 0 unsigned short
XonLim 2048 unsigned short
XoffLim 512 unsigned short
ByteSize 8 '\b' unsigned char
Parity 0 '\0' unsigned char
StopBits 0 '\0' unsigned char
XonChar 17 '\x11' char
XoffChar 19 '\x13' char
ErrorChar 0 '\0' char
EofChar 0 '\0' char
EvtChar 0 '\0' char
wReserved1 0 unsigned short
It's possible your loop doesn't get the characters read out quite fast enough, so that by the 115th time, a new character is already overwriting the last one that is being read out too late.
To test this, you can add a very short delay between characters on the transmitter side, then see if the receiver acts differently.
To exchange data very fast between Python and R I programmed a rather dirty solution, which works. On linux and OSX. May it not be that I now have to get this working in windows.
The below code runs a python script that builds a raw vector which can be serialised by RApiSerialise to an R object.
COMMAND = "python"
PATH_TO_SCRIPT='/GetCassandraData.py'
QueryCassandra <- function(query){
allArgs = c(PATH_TO_SCRIPT, query)
output.connection <- rawConnection(raw(length = 0), "r+")
exec_wait(COMMAND, args = allArgs, std_out = output.connection)
output <- rawConnectionValue(output.connection)
close(output.connection)
final <- unserializeFromRaw(output)
return(final)
}
This works as intended on OSX & linux however, windows has the tendancy to put a 0x0d (Carriage return) byte before a 0x0a (line feed) byte which makes RApiSerialise unable to deserialise it.
I am now attempting to solve the problem by communicating through sockets but I do not seem to be able to find a way to read data from a make.socket() object to a raw vector.
I have tried:
data <- read.socket(datasocket)
Which resulted in:
Error in read.socket(datasocket) :
embedded nul in string: 'X\n\0\0\0\002\0\003\004\002\0\002\003\0'
The function read.socket() tries to read a string and doesn't accept null bytes.
Is there a way to read socket data to a raw vector in R?
R server-side:
library(sys)
COMMAND = "python"
PATH_TO_SCRIPT='/lengthCheck.py'
allArgs = c(PATH_TO_SCRIPT)
sys::exec_background(COMMAND, args = allArgs, std_out = TRUE, std_err = TRUE)
datasocket <- socketConnection(port = 1205, server = TRUE, open = "w+b", blocking = TRUE)
on.exit(close(datasocket))
datasize <- readBin(datasocket, what = "double")
data <- readBin(datasocket, what = "raw", n = datasize)
Python client-side:
import struct
import socket
import time
your_raw_array_to_send = bytearray([0x58, 0x0a, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x04, 0x02, 0x00, 0x02, 0x03, 0x00])
arrayLength = len(your_raw_array_to_send)
datasize = struct.pack('d', arrayLength)
# Wait 100ms for R to set up a listening socket
time.sleep(.100)
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('localhost', 1205))
client_socket.send(datasize)
client_socket.send(your_raw_array_to_send)
client_socket.close()
I want to write a code in R to split hex numbers by delimiters. I have a file including with all hex numbers separated by space like below:
0x01 0x02 0x03 0x04 0x0d 0x0a 0x05 0x06 0x07 0x0d 0x0a
I want to split all of these hex numbers by 0x0d (CR:carriage return) and 0x0a (LF: line feed), i mean i want output like this:
0x01 0x02 0x03 0x04
0x05 0x06 0x07
I think i can use functions like strsplit() but i dont know how. Would you please tell me how can i implement this in R?
Thanks.
Would a pair of gsub calls work?
text <- "0x01 0x02 0x03 0x04 0x0d 0x0a 0x05 0x06 0x07 0x0d 0x0a"
text <- gsub( "0x0d", "\r", text )
text <- gsub( "0x0a", "\n", text )
Which gives:
text
[1] "0x01 0x02 0x03 0x04 \r \n 0x05 0x06 0x07 \r \n"
library(purrr)
library(stringi)
library(magrittr)
# stringi & tidyverse
readLines(textConnection("0x01 0x02 0x03 0x04 0x0d 0x0a 0x05 0x06 0x07 0x0d 0x0a")) %>%
stri_split_fixed("0x0d 0x0a") %>%
.[[1]] %>%
stri_trim_both() %>%
discard(equals, "")
## [1] "0x01 0x02 0x03 0x04" "0x05 0x06 0x07"
# base R + a little tidyverse
readLines(textConnection("0x01 0x02 0x03 0x04 0x0d 0x0a 0x05 0x06 0x07 0x0d 0x0a")) %>%
strsplit("0x0d 0x0a") %>%
.[[1]] %>%
trimws() %>%
discard(equals, "")
## [1] "0x01 0x02 0x03 0x04" "0x05 0x06 0x07"
# old school R
con <- textConnection("0x01 0x02 0x03 0x04 0x0d 0x0a 0x05 0x06 0x07 0x0d 0x0a")
lines <- readLines(con)
lines <- strsplit(lines, "0x0d 0x0a")[[1]]
lines <- trimws(lines)
lines <- lines[lines != ""]
lines
## [1] "0x01 0x02 0x03 0x04" "0x05 0x06 0x07"
paste0() to make a single string with line breaks. cat() to display to the screen or write to a file as separate lines.
I have a raspberry pi and an arduino. So far I have been able to have the Pi send data to the arduino using serial communication, however it only send one variable and I have multiple variables(2) that I want to send to the arduino (x,y coordinates). Does anyone know if this is possible. I want the first number that is sent from the pi to be the x and the second one the y and the next one the x of the next coord ect.
I have tried editing the code that I use to send one variable but it doesn't work.
Any help would be awesome
Consider the following method to send 2 variable at the same time:
int xpos, ypos;
char x_tx_buffer[20], y_tx_buffer[20];
char x_dummy_buffer[20];
char y_dummy_buffer[20];
char *p_x_tx_buffer, *p_y_tx_buffer;
sprintf(x_dummy_buffer,"%d", xposs);
sprintf(y_dummy_buffer,"%d", yposs);
p_x_tx_buffer = &x_tx_buffer[0];
*p_x_tx_buffer++ = x_dummy_buffer[0];
*p_x_tx_buffer++ = x_dummy_buffer[1];
*p_x_tx_buffer++ = x_dummy_buffer[2];
*p_x_tx_buffer++ = x_dummy_buffer[3];
p_y_tx_buffer = &y_tx_buffer[0];
*p_y_tx_buffer++ = y_dummy_buffer[0];
*p_y_tx_buffer++ = y_dummy_buffer[1];
*p_y_tx_buffer++ = y_dummy_buffer[2];
*p_y_tx_buffer++ = y_dummy_buffer[3];
uart0_filestream = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY); //Open in non blocking read/write mode
if (uart0_filestream == -1)
{
//ERROR - CAN'T OPEN SERIAL PORT
printf("Error - Unable to open UART. Ensure it is not in use by another application\n");
}
if (uart0_filestream != -1)
{
int countx = write(uart0_filestream, &x_tx_buffer[0], (p_x_tx_buffer - &x_tx_buffer[0])); //Filestream, bytes to write, number of bytes to write
int county = write(uart0_filestream, &y_tx_buffer[0], (p_y_tx_buffer - &y_tx_buffer[0])); //Filestream, bytes to write, number of bytes to write
if (countx < 0 || county < 0)
{
printf("UART TX error\n");
}
}
close(uart0_filestream);
You can send a max of 8 bytes at a time. Keep that in mind and with that you can modify the about code to send your x and y values in the same uart0_filestream.
Good luck.
I try to connect a device to my windows CE device, through the serial port using ppp and I discovered that the other device (arm-linux) changes its port speed continuously.
It should be 38400 baud but it's not constant.
The speed should be constant?
What I'm doing to chek it is
stty -F /dev/ttyS3
and the output
speed 9600 baud;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
-brkint -imaxbel
-echo
[some time later]
speed 38400 baud;
[some time later]
speed 0 baud;
In the windows CE device I get:
Error: 679 (Incorrect connection profile)
The point is that the speed should be constant in my linux device? or should I check other thinks.