Hei
I'm still newbie. I'm trying to change some string so i can change node address by serial. I've read strtoull yet stdlib on arduino can't support it. Is it possible if i just use strtoul? Or, any suggestion? Thanks
Hei
I'm still newbie. I'm trying to change some string so i can change node address by serial. I've read strtoull yet stdlib on arduino can't support it. Is it possible if i just use strtoul? Or, any suggestion? Thanks
More detail, be specific, post code (in code tags, click the </> button), post errors, etc
For example, what string are you converting?
Convert it as two unsigned longs.
(This topic isn't a "Suggestion for the Arduino project", so I deleted your copy of this question in that forum section)
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
RF24 wirelessSPI(9,10);
void setup() {}
void loop() {
uint64_t nodea, nodeb, nodec, noded, nodee;
uint64_t Address[] = {nodea, nodeb, nodec, noded, nodee};
wirelessSPI.begin();
Serial.begin(115200);
bool k;
k=0;
while(!k){
wirelessSPI.openReadingPipe(1,Address[0]);
wirelessSPI.openReadingPipe(2,Address[1]);
wirelessSPI.openReadingPipe(3,Address[2]);
wirelessSPI.openReadingPipe(4,Address[3]);
wirelessSPI.openReadingPipe(5,Address[4]);
char data;
wirelessSPI.startListening();
while (wirelessSPI.available())
{
wirelessSPI.read( &data, sizeof(data));
char command1[32]="";
char command2[32]="";
char command3[32]="";
char tmp[2];
tmp[1]=0;
tmp[0]=data;
if (isdigit(data)) {strcat(command1,tmp);
delay(20);}
else
if (isxdigit(data)){strcat(command2,tmp);
delay(20);}
else
if (isalpha(data)){strcat(command3,tmp);
delay(20);};
if (strlen(command2) !=0){
unsigned long kar;
kar=strtoul(command2,0,16);
nodea=kar;};};};}
Edit your response. Do you remember what I said
post code (in code tags, click the </> button)
Click the </> button, here I'll show you
That way your code will look like this
just what should i do, ccan i just use that code earlier?
Aryunaji7:
just what should i do, ccan i just use that code earlier?
an example of how to parse a hex string:
remember that your number must be proceeded by "0x" and followed by a semicolon
enum State {
QUESTION,
WAIT,
ANSWER
};
State state = QUESTION;
char input[32];
unsigned char index = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
if (state == QUESTION)
{
Serial.println("Enter an unsigned number: ");
state = WAIT;
}
else if (state == WAIT)
{
if (Serial.available())
{
if (Serial.peek() != ';' || index >= sizeof(input) - 1)
{
input[index] = Serial.read();
Serial.println(input[index]);
index++;
}
else
{
input[index] = NULL;
Serial.read();
state = ANSWER;
input[index] = NULL;
index = 0;
}
}
}
else if (state == ANSWER)
{
Serial.print("Input = ");
Serial.println(input);
unsigned long result = strtoul(input, 0, 0);
Serial.println(result, HEX);
Serial.println(result, BIN);
Serial.println(result);
state = QUESTION;
}
}
so is it okay using strtoul for creating uint64_t type?
@Aryunaji7, can you give some examples of what you want to do without any code?
...R
soo.. like, i want to be able to change the node address remotely. if i like sending the hex(0xF0F0F0) as a string using my nrf. then the string will be read by another nrf and the string would change the node address so the another nrf will be able to transmit to different places. (we can control where it transmit)
;};};};}
Don't you just hate it when that happens?
sooo.. what should i do?
Ordinary arithmetic shifts work on 64 bit variables, so you could simply knife-and-fork it, one hex digit at a time.
Or, you could convert two unsigned longs, and merge them. I may already have mentioned this.
Aryunaji7:
sooo.. what should i do?
Read 8 characters representing the first 8 nibbles. Read another 8 representing the second 8 nibbles.
Convert both to long.
Copy the most significant long into an uint64 variable; shift it 32 positions to the left; add the least significant long to the uint64 variable