• 0

data exchange between Arduino & PC fails - making clear to use pyserail correct



Hi, there at all good day dear community 

I'm trying to create a communicate betwheen Arduino and my PC> The host-pc runs on windows. At the moment my code is just very simple: What is aimed: i just want to switch on a LED when i send data from the host to the Arduino:  But this is actually not working. i struggle a bit with this piece of code.

By the way:  i make use of pySerial.


Findings: when i try to send the data to from the host (in other words the pc )to my arduino the led TX blinks but  the part of my code which is right behind the if ( serial.available()>0) doesn't run at all - i am pulling my hair.


Here is tbe full code: i begin with the Python part


import serial

serie.port= 'COM4'

if serie.isOpen():


and here we have the Arduino code:


int ledPin = 9;
byte incomingByte;

void setup() {
    pinMode(ledPin, OUTPUT);

void loop() {
    if (Serial.available() > 0) {
        incomingByte = Serial.read();
        digitalWrite(ledPin, HIGH);

    digitalWrite(ledPin, LOW);}



well -  i tried to look at a full python sample code that uses pyserial,  i have the package and am wondering how to send the commands and read them back!


again: what is aimed:  Use the Arduino ide to turn the Arduino LED on and off.


import time
import serial

# configure the serial connections (the parameters differs on the device you are connecting to)
ser = serial.Serial(


print 'Enter your commands below.\r\nInsert "exit" to leave the application.'

while 1 :
    # get keyboard input
    input = raw_input(">> ")
        # Python 3 users
        # input = input(">> ")
    if input == 'exit':
        # send the character to the device
        # (note that I happend a \r\n carriage return and line feed to the characters - this is requested by my device)
        ser.write(input + '\r\n')
        out = ''
        # let's wait one second before reading output (let's give device time to answer)
        while ser.inWaiting() > 0:
            out += ser.read(1)

        if out != '':
            print ">>" + out


what i have taken from the Arduino-specs; 



- i think that the usage of "PARITY_ODD? does not help here - since Arduino does not handle PARITY.
- guess that i have to try it with PARITY_NONE.


and subsequently: most Arduinos reset when we open the serial port of them.  That will give us  a certain delay of a few seconds during which time the Arduino can  not receive data from your PC (and it will be lost).

so i have to deal with this time somehow!!?


above all: i sure have to do some tests and have to learn to use the referenced Arduino code and how to use pyserial. 

Dear community - i do some tests and will try to digg deeper in that sort of problems. 

above all: i am so glad to be here at this great place of idea-sharing and knowledge-exchange. : to be here at this place is just great - and a overwehelming experience to me.

plz - keep up this great place - it is one of the best places for all programming and internet things i ever have experienced

i love this forum!!!! 


keep up the great project - it rocks!!

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.