Links

IO Port

This documentation includes installation guidelines and sample code for your hardware.

Windows 10 IoT Core Library

IOPort library is responsible for reading analog inputs and controlling GPIO pins on the IO Ports.
To use the library, add the following using statement to the top of your C# code.
using TurtaIoTHAT;
Then, create an instance of the IOPort class.
IOPort ioPort;
Now you're ready to access the library by calling the ioPort instance.

Initialization

IOPort

Initiates the IO Port function to use GPIO and analog input functions.
IOPort(bool d1In, bool d2In, bool d3In, bool d4In)
  • Parameters
    • Bool d1In: Set true for input, false for output.
    • Bool d2In: Set true for input, false for output.
    • Bool d3In: Set true for input, false for output.
    • Bool d4In: Set true for input, false for output.

Basic Members

Write Pin State

Writes to digital pin.
void WriteDPinState(int ch, bool st)
  • Parameters
    • Int ch: Digital output channel. 1, 2, 3 or 4.
    • Bool st: True for high, false for low output state.
  • Returns
    • None

Read Pin State

Reads current digital pin input state.
bool ReadDPinState(int ch)
  • Parameters
    • Int ch: Digital input channel. 1, 2, 3 or 4.
  • Returns
    • Bool: True if input is high. False if input is low.

Read Analog Input

Reads analog input value.
double ReadAnalogInput(int ch, bool multipleRead)
  • Parameters
    • Int ch: Analog input channel. 1, 2, 3 or 4.
    • Bool multipleRead: Performs multiple reads and returns average value.
  • Returns
    • Double: Analog read value, 0.0 to 1.0. 0 equals to 0V input and 1 equals to 3.3V input.

Interrupts

D1 Value Changed

Notifies on digital pin input change.
event IOPortDigitalInputEventHandler DigitalInputStateChanged
  • Event Args
    • Int Ch: IO Port GPIO pin numver. 1 to 4.
    • Bool State: GPIO Pin input state. True for logic high, false for logic low.

Disposal

To clean up the resources used by the class, call the Dispose() method it when the application is closing.
void Dispose()
This method cleans the resources used by the class.

Samples

You can copy the example code from https://github.com/Turta-io/IoTHAT/tree/master/Samples/Windows10IoTCore address. There is one example of this library.

Analog In Sample App

This application demonstrates reading analog input from IO Port A1, A2, A3, and A4 channels.
To run the example:
  1. 1.
    Open the sample project you downloaded.
  2. 2.
    Make sure "ARM" is selected from the solution platforms selection.
  3. 3.
    Deploy the sample to the Raspberry Pi using the "F5" key.
Sample Code
MainPage.xaml.cs
using Windows.UI.Xaml.Controls;
using System.Threading;
using System.Diagnostics;
using TurtaIoTHAT;
namespace AnalogInSampleApp
{
public sealed partial class MainPage : Page
{
// I/O Port
static IOPort ioPort;
// Sensor timer
Timer sensorTimer;
public MainPage()
{
this.InitializeComponent();
// Initialize I/O Port and timer
Initialize();
}
private void Initialize()
{
// Initialize and configure I/O Port
ioPort = new IOPort(false, false, false, false);
// Configure timer to 2000ms delayed start and 2000ms interval
sensorTimer = new Timer(new TimerCallback(SensorTimerTick), null, 2000, 2000);
}
private static void SensorTimerTick(object state)
{
// Write ADC data to output / immediate window
Debug.WriteLine("AIn 1: " + ioPort.ReadAnalogInput(1, false).ToString("0.000"));
Debug.WriteLine("AIn 2: " + ioPort.ReadAnalogInput(2, false).ToString("0.000"));
Debug.WriteLine("AIn 3: " + ioPort.ReadAnalogInput(3, false).ToString("0.000"));
Debug.WriteLine("AIn 4: " + ioPort.ReadAnalogInput(4, false).ToString("0.000"));
Debug.WriteLine("-----");
}
}
}
Result
When you run the sample, it prints the analog input readings to the Visual Studio Output / Immediate Window.
AIn 1: 1.234
AIn 1: 2.345
AIn 1: 3.456
AIn 1: 4.567
-----
To stop the application, use the "Stop" button on the Visual Studio.