Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9192507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:56:27+00:00 2026-06-17T20:56:27+00:00

2nd UPDATE Almost there!! But getting a ValueError: Attempting to use a port that

  • 0

2nd UPDATE

Almost there!! But getting a “ValueError: Attempting to use a port that is not open”

File "c:\Python27\lib\site-packages\flask\app.py", line 1701, in __call__
return self.wsgi_app(environ, start_response)

File "c:\Python27\lib\site-packages\flask\app.py", line 1689, in wsgi_app
response = self.make_response(self.handle_exception(e))

File "c:\Python27\lib\site-packages\flask\app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()

File "c:\Python27\lib\site-packages\flask\app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)

File "c:\Python27\lib\site-packages\flask\app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()

File "c:\Python27\lib\site-packages\flask\app.py", line 1344, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)

File "G:\OverAir\arduino\server.py", line 19, in light_off
board.output([pin])

File "G:\OverAir\arduino\arduino.py", line 16, in output
self.__sendData(len(pinArray))

File "G:\OverAir\arduino\arduino.py", line 56, in __sendData
while(self.__getData()[0] != "w"):

File "G:\OverAir\arduino\arduino.py", line 61, in __getData
return self.serial.readline().rstrip('\n')

File "c:\Python27\lib\site-packages\serial\serialwin32.py", line 221, in read
if not self.hComPort: raise portNotOpenError

ValueError: Attempting to use a port that is not open

UPDATE

The code from @Blender answer below is probably correct. The issue now
I am having is I’m getting “SerialException: could not open port
COM5: [Error 5] Access is denied.”

However, if I run my original, on.py or off.py script individually, it
works fine…I don’t see how the new code is not working…unless does
it try to open COM5 twice??

END UPDATE

I trying to run multiple python functions, or separate .py scripts, using Flask; in order to generate separate URLs. Just trying to turn the Arduino ON/OFF running it locally.

For example, I have on.py and off.py and want to build sever.py.
So, when I open 127.0.0.1:5000/on it runs on.py, similarly 127.0.0.1:5000/off runs off.py,

After a few hours, I just decided to add both .py functions into the server.py, but of course it doesn’t work…I think I just don’t understand the parameters usage.

Really thank you in advance!

## Open a serial connection with Arduino.

from time import sleep
from arduino import Arduino

from flask import Flask


b = Arduino("COM5",9600)
pin = 13
num = 5

ON = Flask("Light_ON")
OFF = Flask("Light_OFF")


def LightON():
    #declare output pins as a list/tuple
    b.output([pin])
    b.setHigh(pin)
    b.close()
    return 'Light is ON'

def LightOFF():
    #declare output pins as a list/tuple
    b.output([pin])
    b.setLow(pin)
    return 'Light is OFF'

@ON.route('/ON')
@OFF.route('/OFF')

ON.run()
OFF.run()  //I know this doesn't run, just not sure how to include it.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:56:29+00:00Added an answer on June 17, 2026 at 8:56 pm

    Something like this should work:

    from arduino import Arduino
    from flask import Flask
    
    app = Flask('light_control')
    board = Arduino('COM5', 9600)
    pin = 13
    
    @app.route('/on')
    def light_on():
        board.output([pin])
        board.setHigh(pin)
        board.close()
    
        return 'Light is ON'
    
    @app.route('/off')
    def light_off():
        board.output([pin])
        board.setLow(pin)
        # board.close() ???
    
        return 'Light is OFF'
    
    if __name__ == '__main__':
        app.debug = True
        app.run()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file that looks like this: 1st ­ ­ ­ ­­­ 2nd
When using Hibernate 2nd level cache and query cache and not specifying anything inside
How can i append 2nd page of a pdf file to the first page.
A trivial use of PHP and frwite() to create/write to a text file. However,
(Update 2nd Jan 2013) I've now added all the code plus a pom.xml to
For an university project on usability I'm looking for an open source project that
I have 2 views in my app 1st view: tableview and button(update) 2nd view:
Please move down to the 2nd update. I didn't want to change the previous
2nd update, March 2014: Apple closed the bug saying they don't have enough information,
Why is new/override required on abstract methods but not on virtual methods? Sample 1:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.