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 9191769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:45:57+00:00 2026-06-17T20:45:57+00:00

I have a program running on my Arduino that takes serial input, and saves

  • 0

I have a program running on my Arduino that takes serial input, and saves it to a variable. Works a charm. With the Arduino applications built in serial monitor, I have successfully sent and received bytes between 0-255.

Using pyserial, to send any byte higher then 127 (or 0b01111111), pyserial returns 2 – Meaning for values higher then 127, say 0b10000000, 2 bytes will be sent, not one.

I believe my problem is with pyserial, therefore.

ser.write(chr(int('01000000', base=2)).encode('utf-8'))

works perfectly, and is received on the Arduino end correctly.

ser.write(chr(int('10000000', base=2)).encode('utf-8')) 

returns 2, however – And shows on the Arduino as 0b11000010 and 0b10000000.

  • 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-17T20:45:58+00:00Added an answer on June 17, 2026 at 8:45 pm

    As NPE says, this is the encoding for UTF-8 – a byte between 128 and 2047 (8 – 11 bits) inclusive is converted to two bytes: if the original 11 bits is abcdefghijk then then utf-8 version is 110abcde 10fghijk. In your example (with padding left 0s to make 11 bits), 00010000000 would be converted to 11000010 10000000 or \xc2\x80, which is exactly what you are seeing. See the Wikipedia article on UTF-8 for more

    You can see this in python with this code (I’m replacing int(‘10000000’, base=2) with 128):

    >>> unichr(128).encode('utf-8')
    '\xc2\x80' 
    

    The thing that confuses me is that you can use chr(int(‘10000000’,base=2)).encode(‘utf-8’), or equivalently chr(128).encode(‘utf-8)’. When I do this I get:

    >>> chr(int('10000000', base=2)).encode('utf-8')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0: ordinal not in range(128)
    

    Have you changed the default encoding?

    What you need is an encoding that uses one byte for 0 – 255, and matches unicode. So try using ‘latin_1’ instead:

    >>> unichr(128).encode('latin_1')
    '\x80'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a method to monitor a running program that I have
I have a java program that is running in the background(Windows). I would like
I have a Matlab program that is running longer than I'd like it to.
I have a program in Octave that has a loop - running a function
I now have a running Java program which only lacks of the final step,that
I have a Java program running on two computers that are both on the
I have a Python program running a thread that consistently outputs the following: (my_program.py:12313):
Suppose I have a program running that periodically adds information to a .CSV file.
I have a program that sends MSMQ messages to a remote machine. This works
I have a running program that uses glVertexPointer, glNormalPointer etc to draw a large

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.