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

  • Home
  • SEARCH
  • 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 8606725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:09:54+00:00 2026-06-12T03:09:54+00:00

I’ve searched around but can’t find a solution to this problem. I’m using the

  • 0

I’ve searched around but can’t find a solution to this problem. I’m using the simplest example I can think of to test this. This is the processing Code:

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

void loop() { 
  for(int i =48;i<51;i++)  {
    Serial.write(i);  //writes 0-2 in ascii and 48-51 in bytes. 
  }
}

If I view the output on the serial monitor it correctly prints “012012012012012012012” etc without any problems. I wrote a simple program in processing to view the data:

import processing.serial.*;
Serial myPort;  

void setup() { 
  String[] ports =Serial.list();
  myPort = new Serial(this, ports[1], 9600);
}

void draw() {
  if (myPort.available() >=10) 
  {   
    byte[] serialIn = new byte[10];
    myPort.readBytes(serialIn);
    for (int i =0;i<serialIn.length;i++)
    {
      println(serialIn[i] +" binary:"+ binary(serialIn[i]));
    }
  }
}

most of the time it prints junk:

-126   binary:10000010
-118   binary:10001010
-110   binary:10010010
-126   binary:10000010
-118   binary:10001010
-110   binary:10010010 

And occasionally it prints the correct values:

48   binary:00110000
49   binary:00110001
50   binary:00110010
48   binary:00110000
49   binary:00110001
50   binary:00110010                                                                

It looks like each byte gets shifted to the left by 3 bits although I can’t work out why it behaved differently each time I run the program. Interestingly, if I get the arduino to send 0,1,2 it never prints garbage.

Really I want to read the data in C#. This is the meat of the C# code which is based on this example:
http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx

if (serialPort.BytesToRead >0)
{
  byte temp = (byte)serialPort.ReadByte();
  Console.WriteLine(temp +"\t binary: " +byte2Binary(temp));
}

It prints some of the correct values but often misses numbers and is interspersed with garbage:

130    binary: 10000010
138    binary: 10001010
48     binary: 00110000
49     binary: 00110001
50     binary: 00110010
146    binary: 10010010
49     binary: 00110001
50     binary: 00110010
49     binary: 00110001
50     binary: 00110010
146    binary: 10010010
49     binary: 00110001
50     binary: 00110010
48     binary: 00110000
138    binary: 10001010
146    binary: 10010010

The binary values of the incorrect data is exactly the same as the processing binary values. Here the 3 bit shift seems random during runtime instead of being consistent for each time I run. I have tried putting a delay of up to 200ms between sending serial commands. It helps a bit but I still get at least 10% junk data. I’m trying to run a control loop so the longest delay I can afford is 3ms.
What can I do to fix this?

Thanks

  • 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-12T03:09:56+00:00Added an answer on June 12, 2026 at 3:09 am

    If I view the output on the serial monitor it correctly prints

    And occasionally it prints the correct values:

    This points at a misconfiguration, try 4800 baud for instance. And maybe check the other properties (stopbits, handshake).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.