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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:22:58+00:00 2026-05-26T23:22:58+00:00

Python version: 2.6.6 PySerial version: 2.5 Arduino board: Duemilanove 328 I have written some

  • 0
  • Python version: 2.6.6
  • PySerial version: 2.5
  • Arduino board: Duemilanove 328

I have written some code to simulate some hardware I’m working with and uploaded it to the Arduino board. This code works. I know this, because I get the expected response from HyperTerminal.

However, when I try to connect using PySerial the connection does not error, but I get no response to the commands I send.

Why might this be?

Python code

import serial

def main():
    sp = serial.Serial()
    sp.port = 'COM4'
    sp.baudrate = 19200
    sp.parity = serial.PARITY_NONE
    sp.bytesize = serial.EIGHTBITS
    sp.stopbits = serial.STOPBITS_ONE
    sp.timeout = 0.5
    sp.xonxoff = False
    sp.rtscts = False
    sp.dsrdtr = False

    sp.open()

    sp.write("GV\r\n".encode('ascii'))
    value = sp.readline()
    print value
    sp.write("GI\r\n".encode('ascii'))
    value = sp.readline()
    print value

    sp.close()
 
if __name__ == "__main__":
    main()

NB: the code on the Arduino sends back \r\n at the end of a response to a command.

HyperTerminal configuration:

COM4 configuration in HyperTerminal

Edit

I have found that if I increase the timeout to 10 seconds and add a sp.readline() before I send anything, then I get responses to both commands.

How long is the hardware handshake usually between PySerial and an Arduino or USB RS-232 ports?

  • 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-05-26T23:22:59+00:00Added an answer on May 26, 2026 at 11:22 pm

    Can not verify this but it could be that you try and read before there is any data there, thus you get no reply back.

    To test this you could try and poll until there is data

    value = None
    while not value:
       value = sp.readline()
    print value
    

    Edit

    The Arduino will reset when you open a serial connection, any data written during bootup will likely go to bit heaven. You could use a sleep for 2 seconds (could not find the exact time it takes, will likely vary anyway) before you do any reads/writes.

    Alternatively you could write to it until you get a response back, after you get a return you start doing “real work”.

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

Sidebar

Related Questions

I would like to run some code on the Python version of Google App
I am running Cygwin Python version 2.5.2. I have a three-line source file, called
I have a linux VPS that uses an older version of python (2.4.3). This
I have a version of Vim compiled with python 2.6 support enabled ( from
Does python have a function like call_user_func() in PHP? PHP Version: call_user_func(array($object,$methodName),$parameters) How do
i have installed lxml2.2.2 on windows platform(i m using python version 2.6.5).i tried this
I have the strangest error I have seen for a while in Python (version
I am working with Google App Engine python version. The app sends an email
Python version | Javascript version | Whitepaper So, I'm working on a website to
I would like to pass some options to Python (version 2.6) every time, not

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.