#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    Serial communication of MCU with PC using Python(Pyserial)


    Hi,
    I am using MCU ATMEGA32A and i am doing serial communication of MCU with PC using Python(importing Pyserial module).

    I can give Commands to MCU via serial port using Python but I have to reset MCU after each command. I want MCU should accept multiple commands (second after executing first command and so on)
    When I tried same using Hyperterminal then it was accepting multiple commands and executing the same.

    I have tried following commands in python:


    Code:

    import serial, time
    ser = serial.Serial()
    ser.baudrate = 9600

    ser.bytesize = serial.EIGHTBITS #number of bits per bytes

    ser.parity = serial.PARITY_NONE #set parity check: no parity

    ser.stopbits = serial.STOPBITS_ONE #number of stop bits

    #ser.timeout = None #block read

    ser.timeout = 1 #non-block read

    #ser.timeout = 2 #timeout block read

    ser.xonxoff = False #disable software flow control

    ser.rtscts = False #disable hardware (RTS/CTS) flow control

    ser.dsrdtr = False #disable hardware (DSR/DTR) flow control

    ser.writeTimeout = 2 #timeout for write

    ser.flushInput() #flush input buffer, discarding all its contents

    ser.flushOutput()#flush output buffer, aborting current output

    ser.write("USB ON")

    It works fine but Now if i tri second command like ser.write ("USB OFF") then it does not work ....
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    138
    Rep Power
    2
    Originally Posted by SRL
    It works fine but Now if i tri second command like ser.write ("USB OFF") then it does not work ....
    When you say "it does not work", it's very hard to help you. Please elaborate on what happens, what error messages you get, or any other information you think is valuable.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by partoj
    When you say "it does not work", it's very hard to help you. Please elaborate on what happens, what error messages you get, or any other information you think is valuable.

    "It does not work" means Second command does not get received by Microcontroller , you have to reset the microcontroller then only it gets received

IMN logo majestic logo threadwatch logo seochat tools logo