Documentation by Orwa
- Hardware
- relay_sketch.ino
- relay.py
- PySerial package. To install, type the following from the command prompt: “pip install pyserial”
- Launch “idle” on windows
- Type: “import os;print(os.getcwd())”
- Copy “relay.py” to subdirectory “Lib” within the folder above (displayed in idle in blue)
- Now you can use the library using “import relay” then calling the following functions:
a. relay.turn_on(): turns the relay on
b. relay.turn_off(): turns the relay off - Note that if the hardware is not connected, then an exception will be thrown when importing the library
- Note that if the hardware is connected but being used by another program, an exception will also be thrown when importing the library
- To turn on the relay from the command line, go to the folder where “relay.py” is stored and type the following commands:
a. “python relay.py 1” turns the relay on
b. “python relay.py 0” turns the relay off - Note that if the hardware is not connected, an error message will be displayed.
- Note that if the hardware is connected but being used by another program, an error message will be displayed