0
votes

I am working on doing an Arduino project using a Wifi connection. I was wondering how to send integers through the serial moniter. This is what I have so far:

      if(Serial.available()) {
        while(Serial.available()) {

        char c = Serial.read();

        if(c == '\n') {
          send_message(client, tx_buffer);
          tx_buffer = "";
      } else tx_buffer += c;
    }
  }

This is to send a character through the serial moniter. How would you do it for an integer?

1
How about sending it as a text? You know 123 => '1' '2' '3' (or "123\n")KIIV

1 Answers

0
votes

Anything you type in the serial monitor is converted to its ASCII equivalent so typing 3 actually sends '3' == 51. This should work for getting unsigned integers:

unsigned long tx_buffer = 0;

if (Serial.available()) {
   while(Serial.available()) {
     char c = Serial.read();
     if(c == '\r') {
       send_message(client, tx_buffer);
       tx_buffer = 0;
     } 
     else
       tx_buffer = (tx_buffer * 10) + (c - '0');  
   }
}