• 0

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


Question

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=serial.Serial()   
serie.baudrate=9600
serie.port= 'COM4'
serie.parity=serial.PARITY_ODD
serie.stopbits=serial.STOPBITS_ONE
serie.bytesize=serial.EIGHTBITS

if serie.isOpen():
    serie.close()
serie.open()
serie.isOpen()
serie.write("hello".encode

 

and here we have the Arduino code:

 

int ledPin = 9;
byte incomingByte;

void setup() {
    Serial.begin(9600);
    pinMode(ledPin, OUTPUT);
}

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

    delay(1000);
    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(
    port='/dev/ttyUSB1',
    baudrate=9600,
    parity=serial.PARITY_ODD,
    stopbits=serial.STOPBITS_TWO,
    bytesize=serial.SEVENBITS
)

ser.isOpen()

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

input=1
while 1 :
    # get keyboard input
    input = raw_input(">> ")
        # Python 3 users
        # input = input(">> ")
    if input == 'exit':
        ser.close()
        exit()
    else:
        # 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)
        time.sleep(1)
        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!!

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Innit interesting that there's no metric standard for time?
    • Yeah, but these new clocks aren't going to change the fact that time is an illusion, and vacation time doubly so.
    • Science is almost ready to "redefine the second" with this new research by Sayan Sen Image by Samer Daboul via Pexels In an effort to make keeping time even more accurate, researchers from six European countries joined forces to compare ten ultra-precise optical clocks at the same time — something that’s never been done on this scale before. These clocks, which use lasers to measure how atoms jump between energy levels, are much more accurate than traditional cesium atomic clocks. In fact, optical clocks could lose or gain less than a second over billions of years. To see how closely these clocks agreed with each other, the team ran 38 measurements known as frequency ratios. Four of these had never been done directly before, and many were done with better precision than ever. The experiment helps move us closer to updating how the world defines one second potentially switching from cesium clocks to optical ones. Helen Margolis from the UK’s National Physical Laboratory said, “The accurate time and frequency signals provided by atomic clocks are essential for many everyday technologies like GPS, managing power grids and keeping financial transactions in sync.” Connecting these clocks over long distances was tricky. Scientists used two linking methods: GPS signals from satellites and custom optical fiber cables. GPS was accessible to all clocks but didn’t offer the best accuracy due to noise and signal issues. Fiber links used in France, Germany and Italy offered 100 times better precision but could only cover short distances. For clocks in the same lab, like those in Germany and the UK, short fiber cables helped reduce uncertainty even more. The findings were published in Optica, a journal focused on optical science. The team also looked at how the various frequency ratios compared across the different systems to spot any mismatches or patterns. “These measurements provide critical information about what work is still needed for optical clocks to achieve the precision and reliability required for use in international timekeeping,” said Marco Pizzocaro from Italy’s INRiM. He added that the setup acted like a distributed lab, which could be used for deeper physics research, like searching for dark matter or testing the foundations of physics. Coordinating all ten clocks and keeping them running in sync across six countries took a lot of preparation. Some results didn’t match predictions, but having so many clocks operating together helped spot where things went wrong. “Not all the results confirmed what we expected, and we observed some inconsistencies in the measurements,” said Rachel Godun from NPL. “However, comparing so many clocks at once and using more than one technique for linking the clocks made it easier to identify the source of the problem.” The researchers say more work is needed to cut down measurement uncertainty and make sure these optical clocks stay reliable over time. If they do, these clocks could soon be the ones we use to define time worldwide. As Thomas Lindvall from Finland’s VTT MIKES put it: “With a coordinated set of measurements, it becomes possible to check consistency while also providing more trusted results.” Source: Optica (link1, link2) This article was generated with some help from AI and reviewed by an editor. Under Section 107 of the Copyright Act 1976, this material is used for the purpose of news reporting. Fair use is a use permitted by copyright statute that might otherwise be infringing.
  • Recent Achievements

    • Rookie
      Snake Doc went up a rank
      Rookie
    • First Post
      nobody9 earned a badge
      First Post
    • One Month Later
      Ricky Chan earned a badge
      One Month Later
    • First Post
      leoniDAM earned a badge
      First Post
    • Reacting Well
      Ian_ earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      495
    2. 2
      Michael Scrip
      203
    3. 3
      ATLien_0
      199
    4. 4
      Xenon
      136
    5. 5
      +FloatingFatMan
      116
  • Tell a friend

    Love Neowin? Tell a friend!