hi,
I purchased the Bluefruit nFR8001 and i've been having the hardest time trying to convert the data in the buffer from ASCii to either an integer or a string. when I wrap int() around the buffer byte, it comes out as ASCii decimal form, not an integer...
I'm not coding from scratch, I'm just trying to manipulate the code from the example, "callbackEcho" See below
all that I'm wanting to do is use the UART on my iphone to send a message such as "au456" to move a servo angle up to position 456
thanks for any help!! (I've spent a frustrating hour with this)
void rxCallback(uint8_t *buffer, uint8_t len)
{
Serial.print(F("Received "));
Serial.print(len);
Serial.print(F(" bytes: "));
for(int i=0; i<len; i++)
Serial.print((char)buffer);
int value = int((char)buffer[0]); // <-- here is what i am trying to add. just makes it a ASCii decimal, not an actual integer value
char ch = (char)buffer[1];
String str = string(ch); // <-- here is where I stop
Serial.print(F(" ["));
for(int i=0; i<len; i++)
{
Serial.print(" 0x"); Serial.print((char)buffer, HEX);
}
Serial.println(F(" ]"));
/* Echo the same data back! */
uart.write(buffer, len);
}
BlueFruit buffer data to integer or string
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 12
- Joined: Sat Jun 22, 2013 11:11 pm
- Barry914
- Posts: 448
- Joined: Sun Dec 08, 2013 1:26 pm
Re: BlueFruit buffer data to integer or string
The function atoi() is what you are looking for.
int i;
char *number = "100";
i = atoi(number);
int i;
char *number = "100";
i = atoi(number);
-
- Posts: 12
- Joined: Sat Jun 22, 2013 11:11 pm
Re: BlueFruit buffer data to integer or string
I appreciate your reply/ interest but it didnt work, I keep getting:
invalid conversion from 'char' to 'const char*'
invalid conversion from 'char' to 'const char*'
- Franklin97355
- Posts: 23940
- Joined: Mon Apr 21, 2008 2:33 pm
Re: BlueFruit buffer data to integer or string
Code: Select all
int i;
char *number = "100";
i = atoi(number);
-
- Posts: 12
- Joined: Sat Jun 22, 2013 11:11 pm
Re: BlueFruit buffer data to integer or string
can you guys help me some more?
now with the * I get
Invalid conversion from 'int' to 'char*'
the library can be downloaded from the link below. And you guys can just verify the code with what you are showing me?
// OK while we still have something to read, get a character and print it out
while (BTLEserial.available()) {
char *c = BTLEserial.read();
Serial.print(c);
int i;
i = atoi(c);
}
https://learn.adafruit.com/getting-star ... rt-service
now with the * I get
Invalid conversion from 'int' to 'char*'
the library can be downloaded from the link below. And you guys can just verify the code with what you are showing me?
// OK while we still have something to read, get a character and print it out
while (BTLEserial.available()) {
char *c = BTLEserial.read();
Serial.print(c);
int i;
i = atoi(c);
}
https://learn.adafruit.com/getting-star ... rt-service
- Franklin97355
- Posts: 23940
- Joined: Mon Apr 21, 2008 2:33 pm
Re: BlueFruit buffer data to integer or string
Code: Select all
// OK while we still have something to read, get a character and print it out
while (BTLEserial.available()) {
char *c = BTLEserial.read();
int i;
i = atoi(c);
Serial.print(i);
}
- Barry914
- Posts: 448
- Joined: Sun Dec 08, 2013 1:26 pm
Re: BlueFruit buffer data to integer or string
You might want to look at Serial.parseInt()
Please be positive and constructive with your questions and comments.