This code is not running my laptop(Arduino slave mod question)

from Arduino import Arduino
import time

POT = 0
val = 0

board = Arduino('115200')
board.pinMode(POT, "INPUT")

while True :

val = board.analogRead(POT)

I run the above code result

Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.

= RESTART: C:\Users\User\AppData\Local\Programs\Python\Python39\physicalcomputing\

Originally, the normal output should read the potentiometer value continuously and output it to the serial monitor, but nothing is displayed.
I went through the same installation process and tried running it on another laptop, but it worked fine there.

I haven't found a solution yet.

(I'm Korean, so I'm sorry that I'm not good at English.)

Possibly outside my area of expertise. Is this MicroPython running on an Arduino or Python running on a PC?

Python running on a PC

So how does it communicate with Serial Monitor? Serial Monitor is not the Arduino.

I'm not a python person but I think that this line prints in your python application.

What does this line do? Does it open the serial port?

You're using some form of library / module? Can you provide a link?

To me, it looks like a MicroPython program for Arduino, attempting to run on Python for PC. So of course, it crashes. But I could be wrong.

After making the Arduino board in a dummy state, the slave mode is to allow the code to be written on the Arduino to be written in Python.

(1) In the command prompt, write 'pip install arduino-python3' to install the required pip

(2) From the link below, download the Python Arduino Command API to change the Arduino board to slave mode and run it-->

(3) After downloading and unpacking the program, 'Arduino Python3 Command API master\sketches\prototype\prototype.ino'

Compile the code in the above path on the Arduino board.

(4) After this operation, it is possible to write the code necessary to operate the Arduino board in python.

Thanks for the explanation and details.

Is your Arduino correctly recognised by your operating system?

Yes, the Arduino port is recognized correctly, and the Arduino sketch compiles without any problems.

You can force the use of a specific port; from the documentation

board = Arduino("115200", port="COM3") #Windows example

I've uploaded prototype.ino to a Nano and used serial monitor (you can use any terminal program) to read an analog input. The command is


You can try the same to make sure that your sketch behaves as expected.

As this has nothing to do with Installation and Troubleshooting (IDE is working and you can upload code; see About the Installation & Troubleshooting category), I've moved your topic to Interfacing w/ Software on the Computer - Arduino Forum.

I'm not a Python person so might not be able to help further.

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