Hi,
I am designing a two energy meters on a same arduino. i calculated the energy and transmitting it using zigbee. i am receiving the data in the form a string. i Got the data from the string, but i need that data in the form of integers. so my question is how to convert the char array into integers?
Post your code.
But fundamentally, anything you an represent using a char, you can represent using an integer. char is 1 byte of data, int is 2 bytes of data on this platform.
char char_data = 4;
int int_data = (int)char_data;
@oz1994, I see you cross-posted / hijacked. Don't do that.
the transmitter code:
Serial1.print("<");
Serial1.print(E);Serial1.print(",");
Serial1.print(E1); Serial1.print(">");
The receiver code:
int i;
int j;
#include <stdlib.h>
#include <string.h>
#define SOP '<'
#define EOP '>'
bool started = false;
bool ended = false;
char inData[80];
byte index;
void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
}
void loop()
{
// Read all serial data available, as fast as possible
while(Serial1.available() > 0)
{
char inChar = Serial1.read();
if(inChar == SOP)
{
index = 0;
inData[index] = '\0';
started = true;
ended = false;
}
else if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 79)
inData[index] = inChar;
index++;
inData[index] = '\0';
}
}
char *Data=NULL;
if (started && ended)
{
//Serial.print(inData);
//Serial.print("\n");
Data =strtok(inData,",");
while(Data != NULL)
{
//Serial.print(Data);Serial.print("\n");
Data=strtok(NULL,",");
//delay(2000);
}
i = atoi(strtok(inData,","));
j = atoi(strtok(NULL, ","));
while(1)
{
Serial.print("A");
//Serial.print("I = ");
Serial.print(i);
//Serial.print("J =");
Serial.print(j);
delay(300);
}
//Reset
started = false;
ended= false;
index = 0;
inData[index]='\0';
}
I am getting Value at "i" but zero at "j".
What did i Hijack??
Have a look at the parse example in serial input basics
...R
no, still not working.
oz1994:
no, still not working.
I'm not sure I have seen a less useful statement on the Forum.
WHAT is not working? - post your latest code
HOW is it not working? - describe the symptoms.
...R