decimal to ascii

Hello everyone,

I'm pretty new to the Arduino and I don't know C very well either.

So, my problem I that when I send things over serial to the Arduino, each letter is converted to decimal. Is there a way to either not have it be converted to decimal, or a function that can convert decimal to ascii.

Pretty much I need the function chr() in python.

Thanks

How are you sending things over the Serial? And what exactly are you sending? Could you post some code, using the "#" button above.:smiley:

You can choose what to send, to an extent by using:
Serial.print(variable, BYTE);// as a byte, 0 - 255
or
Serial.print(variable, BIN); //binary

Also, you never stated if you're printing or writing.
Serial.write works a little bit differently than Serial.print.

Here's the tutorial to kind of explain.

Also, I believe sending a decimal value is dependent of what kind of variable you're using.
Take a look at this Arduino Notebook, page 12:

And here is a recent discussion on the same issue:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1253899085/.

How are you sending things over the Serial? And what exactly are you sending? Could you post some code, using the "#" button above.

I'm just using the serial monitor to send and receive data for now.
I'm sending strings to the Arduino then sending that string back, but when I get it back its in decimal.

Heres the code to explain:

int green = 13;
int blue = 12;
int red = 11;
int ibyte1 = 0;
int ibyte2 = 0;

void setup() {
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(red, OUTPUT);
  Serial.begin(9600);
  
}

void loop() {
  
  if (Serial.available() > 0) {
    ibyte1 = Serial.read();
    ibyte2 = Serial.read();
    Serial.print(ibyte1)
    if (ibyte1 == 103) {
      if (ibyte1 == 110) {
        digitalWrite(green, HIGH);
      }else{
        digitalWrite(green, LOW);
      }
    }
  }

This checks for the letter 'g' then the letter 'n'(for green and on), but if i want to check for full words it gets much more complicated.

Hope that clears it up a little.

When posting code, please first check that it compiles without errors.

You need to ensure there is at least two characters waiting...

  if (Serial.available() >= 2) {

In C(++) char is a subtype of int so this should work...

    if (ibyte1 == 'g') {
      if (ibyte1 == 'n') {

Sorry for the late reply.

Thank you, that was my problem.
I'm just not used to declaring the type.