Morning Guys,
I am sure this is simple, as i am sure i am having some kind of mental block about this
I am sending characters (programmed in HEX) via Serial, and expecting a long string of characters as a response from a device.
I know i am getting the response, and if i Serial.write(DataLine[21]) into a terminal program that displays as HEX i get 8B. I need to convert 8B to a dec, which would be 139, then divide it by 10 to give a float 13.9. Thats the goal, and i intend to parse the whole string by position in a similar fashion (although math will vary a little)
The issue i am having is no matter what I use, "atoi", "int" i get zeros?? what am i missing. I am attaching the code so that you guys can review and tell me what on earth i am doing wrong...
Really appreciate any help - this is driving me crazy!
char DataLine [185];
char Convert[2];
static unsigned int input_pos = 0;
String inData;
void setup() {
 Serial2.begin(9600, SERIAL_8E1);
 Serial.begin(9600);
 Serial2.write(0xb8);
 Serial2.write(0x31);
 Serial2.write(0xf7);
 Serial2.write(0x02);
 Serial2.write(0x21);
 Serial2.write(0x01);
 Serial2.write(0x5C);
}
void loop() {
 if (Serial2.available()) {
  const char recieved = Serial2.read();
  DataLine [input_pos] = recieved;
   if (input_pos == 21)
   {
   Convert[1] = recieved;
   Convert[2] = '/0';
   Serial.println(DataLine[21],HEX);
   Serial.write(Convert);
   Serial.println();
   int number = atoi(Convert);
   Serial.println();
   Serial.print(number);
   }
 input_pos = input_pos + 1;
 }
Â
}