IO Port
This documentation includes installation guidelines and sample code for your hardware.
Python Library
IOPort library is responsible for reading analog inputs and controlling GPIO pins on the IO Ports.
To install the library from the (PyPI) Python Package Index, enter the following command to the console.
Add the following statement to the top of your Python code.
Then, create an instance of the Turta_IOPort class.
Now you're ready to access the library by calling the io instance.
Initialization
The library automatically initializes the required components when its instance is being created, so there is no need to do a manual initialization.
Basic Members
Set Digital IO
Sets the digital output state.
Parameters
Int ch: IO channel. 1 to 4.
Bool st: Output state.
Returns
None
Read Digital IO
Reads the digital input.
Parameters
Int ch: IO channel. 1 to 4.
Returns
Bool: Input state.
Read Analog Input
Reads the analog input.
There is a known issue on reading analog inputs with Python. As a result, the analog readouts may not be consistent. This is a software related issue and we'll publish the updated software when the problem is resolved.
Parameters
Int ch: Analog input channel. 1 to 4.
Returns
Float: Analog input value. 0.0 to 1.0.
Samples
You can copy the example code from https://github.com/Turta-io/IoTHAT/tree/master/Samples/Raspbian/Python address, and then copy it to the Raspberry Pi. There are two examples of this library.
IO Port Digital Sample App
This application demonstrates digital read and write functions.
To run the example:
Copy the library and sample code to a folder on the Raspberry Pi.
Open terminal, and go to the folder you copied the codes.
Run the sample with the following command:
Sample Code
Result
When you run the sample, it toggles digital IO pin 3 every 5 seconds. The application also writes the IO state to the terminal. The example output should be like this:
To stop the Python script, just press CTRL + C.
IO Port Analog Sample App
This application demonstrates analog read function.
To run the example:
Copy the library and sample code to a folder on the Raspberry Pi.
Open terminal, and go to the folder you copied the codes.
Run the sample with the following command:
Sample Code
Result
When you run the sample, it reads the analog input channel 1 and writes the analog value to the terminal. The example output should be like this:
To stop the Python script, just press CTRL + C.
Last updated