Go Down

Topic: Conversion from int/hex to char (Read 50433 times) previous topic - next topic

Grumpy_Mike

#15
Apr 28, 2012, 04:38 pm Last Edit: Apr 28, 2012, 04:42 pm by Grumpy_Mike Reason: 1
Quote
How do I get serial print to send the value in the correct format?

Like I told you in my first reply. You seem to have been lead astray since then.
Don't use the HEX with the .write

Code: [Select]
int decimalValue = 25;

void setup(){
  Serial.begin(9600);
}

void loop(){
  Serial.println("S_Print");
  Serial.print(decimalValue,HEX);
  Serial.println("S_Write");
  Serial.write(decimalValue);
}

Grumpy_Mike

So to see all the ASCII characters run this:-

Code: [Select]
void setup(){
  Serial.begin(9600);
}

void loop(){
  for(int i=0x20; i<0x7F; i++){
  Serial.print(i,HEX);
  Serial.println(" gives an ASCII character of ");
  Serial.write(i);
  Serial.println(" ");
  }
  delay(5000);
}


mrdovey

Code: [Select]
int value = 0xB0;

void setup(void)
{  Serial.begin(115200);
   Serial.print((char)value);
}

void loop(void)
{
}

multivir

I finally got it to work! Thanks a lot.

Go Up