# Problem with Serial communication between Arduino and Python

**URL:** <https://forum.arduino.cc/t/problem-with-serial-communication-between-arduino-and-python/1212670>\
**Category:** Interfacing w/ Software on the Computer\
**Created:** [January 18, 2024, 1:06pm UTC](https://forum.arduino.cc/t/problem-with-serial-communication-between-arduino-and-python/1212670 "2024-01-18T13:06:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kubanowicz](https://avatars.discourse-cdn.com/v4/letter/k/b38774/32.png) [@kubanowicz](https://forum.arduino.cc/u/kubanowicz)\
**Post date:** [January 18, 2024, 1:06pm UTC](https://forum.arduino.cc/t/problem-with-serial-communication-between-arduino-and-python/1212670/1 "2024-01-18T13:06:22Z")

</div>

Hi!

I've been doing a project of Ball Beam Balancing Problem in Arduino. I am using servo and eFLL libraries as a tools to implement fuzzy logic as a controller to servo. The script in python sends coordinates of a ball using pyserial library.

As I am trying to debug the code, python script sends the coordinates to Arduino, the Arduino sends back the coordinates as a confirmation of data recieved. While working with the Arduino Uno board, the back and forth communication lasts between 20 to 60 seconds, then no data is recieved by a Python script. Thought it might be something with computation power or memory overload, so I switched to Arduino Mega. On Mega there are no data recieved in python script (yes i changed the COM port)

---

<div class="post-metadata">

**Author:** ![jfjlaros](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jfjlaros/32/716915_2.png) [@jfjlaros](https://forum.arduino.cc/u/jfjlaros)\
**Post date:** [January 18, 2024, 8:01pm UTC](https://forum.arduino.cc/t/problem-with-serial-communication-between-arduino-and-python/1212670/2 "2024-01-18T20:01:58Z")

</div>

It could be a case of memory fragmentation. Perhaps you can try to replace the following lines,

> [@kubanowicz](#):
>
> ```cpp
> x_rel_str = Serial.readStringUntil('\n');
> x = x_rel_str.toFloat();                  
> 
> ```

with:

```cpp
    x = Serial.parseFloat();
    Serial.read(); // Discard '\n'.

```

Otherwise, the problem is likely in a part of the code that was not shared.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 16, 2024, 8:58pm UTC](https://forum.arduino.cc/t/problem-with-serial-communication-between-arduino-and-python/1212670/4 "2024-07-16T20:58:42Z")

</div>

Closed on July 16, 2024, 8:58pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
