Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8726451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:14:58+00:00 2026-06-13T08:14:58+00:00

I am trying to take the standard input from the console and send it

  • 0

I am trying to take the standard input from the console and send it to my Arduino Uno as plain ASCII.

I get the Input and strip \r\n from it using this code:

String Input = Console.Read().ToString().Replace("\r",string.Empty).Replace("\n",string.Empty);

When I perform doConsole.WriteLine(Input);, it outputs “72” which is correct, but when I do serialPort.Write(Input); the Arduino returns “55”, which it does for everything.

What am I doing wrong?

My code for the C# side (host/PC):

String Input = Console.Read().ToString().Replace("\r", string.Empty).Replace("\n",string.Empty);

//Console.WriteLine(Input);
//serialPort.Write(Input);

char[] InputChar = Input.ToCharArray();
serialPort.Write(InputChar,0,1);

//byte[] InputByte = Encoding.ASCII.GetBytes(Input);
//Console.WriteLine(Input);
//serialPort.WriteLine(Input);

Thread.Sleep(25);  //Wait 0.025 second.


//***************************************************************//
// Read anything from the serial port.                           //
//***************************************************************//

numBytes = serialPort.BytesToRead;
for (int i = 0; i < numBytes; i++)
    rxPacket[i] = (byte)serialPort.ReadByte();

result = new char[numBytes];
for (int i = 0; i < numBytes; i++)
    result[i] = (char)rxPacket[i];

Console.Write("Read this from Arduino:");
Console.WriteLine(result);

Console.WriteLine("press Enter to continue");
Console.ReadKey();                                   //Read nothing.

And my Arduino sketch:

const int ledPin = 13; // The pin that the LED is attached to.
int incomingByte;      // A variable to read incoming serial data into.

void setup() {
    // Initialize serial communication:
    Serial.begin(9600);
    // Initialize the LED pin as an output:
    pinMode(ledPin, OUTPUT);
}

void loop() {
    // see if there's incoming serial data:
    if (Serial.available() > 0) {
        // Read the oldest byte in the serial buffer:
        incomingByte = Serial.read();
        // If it's a capital H (ASCII 72), turn on the LED:
        if (incomingByte == 'H') {
            digitalWrite(ledPin, HIGH);
            Serial.print(incomingByte);
        }
        // If it's an L (ASCII 76), turn off the LED:
        else if (incomingByte == 'L') {
            digitalWrite(ledPin, LOW);
            Serial.print(incomingByte);
        }
        else{
            Serial.print(incomingByte);
       }
    }
}

Edit: changed the code to the following. Still no luck; I am getting same reply.

String Input = Console.Read().ToString().Replace("\r",string.Empty).Replace("\n",string.Empty);
Console.Write(Input,0,1);
//serialPort.Write(Input);
byte[] inputByte = Encoding.ASCII.GetBytes(Input);
serialPort.Write(inputByte,0,1);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:14:59+00:00Added an answer on June 13, 2026 at 8:14 am

    Well, I looked it up… As it turns out, ASCII code 55 = 7.

    7 is the first digit of 72.

    Hmm, so perhaps your sending decimal numbers to the Arduino here and the Arduino sees a 7 first. May I suggest to convert your byte and send it as a byte (a byte can only contain 0..255), but it is a single ASCII code.

    Maybe for the Arduino to think about, but maybe it is not related to this. Instead of

    int incomingByte;  // ints are made of 2 bytes an int isn't an incomming byte
    

    try

    Byte incomingByte;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to take a stream of data from standard in, compress it one
I am trying to take input from the keyboard and then store it in
Due to some legacy standard when you send an email from Outlook the plain
All I am trying to do is take a standard range on an excel
I'm trying to use a standard Intent that will take a picture, then allow
trying to take this content: <div class=content>one,two,three</div> <div class=content>four,five,six</div> <div class=content>seven,eight,nine</div> and .split and
I can't find anyone doing this, and I'm trying to get my head around
Using the standard Win32 file I/O API's (CreateFile/ReadFile/etc), I'm trying to wait for a
I'm trying to take a xml document and transform to a standard html list
I'm trying to map a fairly standard category model using EF Code First public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.