3

i'm making a web server that can contro an arduino with python and i get this error: serial.serialutil.SerialException: could not open port 'COM3': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2)

from flask import Flask
from pyfirmata import Arduino
import time





main_page = """
<!DOCTYPE html>
<html>
<body>

<h2>Button</h2>
<form action="button">
    <button type="submit">Press Button!</button>

<form>

</body>
</html>
"""

app = Flask(__name__)


@app.route('/button')



def button():
    board = Arduino('COM3')
    board.digital[13].write(1)
    time.sleep(1)
    board.digital[13].write(0)
    print("hello")
    return main_page

@app.route('/')
def index():
    return main_page


if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')
MMCH
  • 31
  • 1
  • 1
  • 3

2 Answers2

1

had the same issue and by checking com3 in device manager i found it disabled, enabled it and it worked fine

Moharam
  • 11
  • 2
0

This problem can be solved with few processes:

  1. Open device manager.
  2. Open ports(COM & LPT)
  3. Unplug and plug your Arduino USB cable.
  4. New port will get added. (eg. USB-SERIAL CH340 (COM6))
  5. Go to Arduino IDE.
  6. Under tools find port
  7. Click and change to your cable port (My case COM6)
Yakraj
  • 29
  • 3