Char convert from appinventor to arduino

I send from app inventor to arduino by bluetooth : 'A003360' and 'B006875'
How can arduino take 'A' or 'B' without numbers ?
And how to convert the numbers to make mathematical operations ?
I M NOOB , thanks for help

I believe this can help you :

One solution would be to send the Character Val (e.g. 'A') and it's number value (e.g. '003360') as two separate strings from the App, and receive them as a Char and an Integer respectively in the Arduino Sketch.

1 Like

Hi all
since I like to play with Arduino (Chris is already aware of that :innocent:), I've coded it on a Uno board.
I've simulated the two strings received on the BT line just assigning two strings.
Then I extract the first character (from the two strings) and store them in two char type variables.
The remaining parts of the two strings are then converted into integers on which you can do whatever mathematical operations.
On AI2 side you don't need to do nothing: just send out on the BT the two strings.
That's all.

I hope it can help.
Cheers

PS thanks to ABG hint the code is correctly indented ... :rofl:


String S_A = "A003360";
String S_B = "B006875";
int first_data;
int second_data;
char first_ch;
char second_ch;
String numericA = "";
String numericB = "";
int total = 0;


void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);  
S_A = "A003360";                              // simulates the first string received on BT from the App
S_B = "B006875";                              // simulates the second string received on BT from the App

Serial.println(S_A);                          // prints the first string complete
first_ch = S_A.charAt(0);                     // extracts the first character
numericA = S_A.substring(1);                  // extracts the numeric part from the first string received
first_data = numericA.toInt();                // converts it to an integer
Serial.print(first_ch);                       // prints the first character of the first string received
Serial.print("  data: ");                     
Serial.println(first_data);                   // prints the numeric part as integer

Serial.println(S_B);                          // see comments for string A
second_ch = S_B.charAt(0);
numericB = S_B.substring(1);
second_data = numericB.toInt();
Serial.print(second_ch);
Serial.print("  data: ");
Serial.println(second_data);


total  = first_data + second_data;           // dummy operation just to show that the numeric parts have been converted correctly
Serial.println(total);                       // and mathematical operations work fine
}

void loop() {
  // nothing to do repeatedly:

} 
'''
1 Like

Thank you very much uskiara !!!!!!!!

and to abg also !

Hi Seif,
u r welcome.
:hugs:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.