Serial communication between Raspi and Arduino MKR1000

Hello Arduino forums, I need help troubleshooting an issue with a code I tried to use from the forum. Thanks to Robin2 for his wonderful thread at PC - Arduino comms using Python -- updated - Interfacing w/ Software on the Computer - Arduino Forum, I was inspired to connect the MKR1000 to my Raspi 3B+ however running his sample code returns the "waiting for Arduino to reset" and code hangs there in the console indefinitely until I close it. Can someone help me identify what the issue is?

Hardware: Raspi 3B+, Arduino MKR1000

I also noticed that everytime I use this code and run the ls /dev/tty* command to check the port Arduino is connected to, it increments by 1. The first time I ran the code, the Arduino was connected to ACM0, after 4 times or so, I saw that Arduino was connected to ACM4. Is there something wrong with the code or is it my Pi? I want to send data from Pi to Arduino through Serial on USB. Any hints, advice or another example code to help with my serial communication problem is greatly appreciated. Thank you for your time.

On the Arduino boards that don’t have native USB capabilities (e.g., Uno, Nano, Mega), the microcontroller resets when a serial connection is opened to the Arduino board. On the Arduino boards with native USB, such as your MKR1000, the microcontroller is not reset when a serial connection is opened. This could mean that the Arduino starts up and prints “” before your Python program is running and listening for it, so that input is missed.

Try adding this line to the Arduino sketch on the line after the call to Serial.begin():

while(!Serial);  // wait for the serial port to be opened before continuing

I added the line like you suggested and it works however, I need to hit the manual reset button on the Arduino to make it work next time I want to run the code. Any idea what would be the cause for this issue? and potential fixes? Thank you for the help!!

When I had a Pi hooked up to an Arduino, I just sent, via a level shifter, a reset pulse to the Arduino. The Pi can be made to understand when the Arduino is not responding and reset it.

That’s actually a very smart idea, thank you for the input. I’ll try to add this to my list of functions to implement. I still dont understand why I need to reset it everytime for the code to work.