D.I.Y- Make Your Own AllJoyn Enabled Switches on Windows 10 IoT Core

Making AllJoyn Producer for Four Channel Relay Module on Windows 10 for IoT

0
2761
Raspberry Pi 2

In this tutorial we will be learning how to control a four channel relay module with the help of AllJoyn Device System Bridge(DSB) on Windows 10 IoT core. Microsoft recently released a Visual Studio project template for AllJoyn DSB applications. We will take help of this template and build a producer application which can control four relays with four different interfaces.

Prerequisites

  1. AllJoyn Explorer
  2. Visual Studio 2015
  3. A Raspberry Pi running with Windows 10 IoT core

Getting Started

Download and install AllJoyn Device System Bridge Template from here. After installing the template create a new project. Make sure you select the AllJoyn Device System Bridge template from the Templates section.

New Project: AllJoyn Device System Bridge Template
New Project: AllJoyn Device System Bridge Template

Next, we will add a reference to the AdapterLib project to use the Windows IoT Extension SDK. This is needed in order to use the Windows.Devices.Gpio API.

Add references to the AdapterLib project
Add references to the AdapterLib project
Add references to the AdapterLib project
Add references to the AdapterLib project

Let’s Code

Now we need to make some changes in Adapter.cs class file in AdapterLib project. First, add using Windows.Devices.Gpio; and then make the following changes:

We have declared certain attributes which will be used to expose the GPIO pins to the AllJoyn bus. Next, we will edit the Adapter() constructor.

We’ll now make some changes in the Initialize() function.

We have declared four different AdapterDevice instances for four different relays. Each of these instance represents an independent interface on the AllJoyn bus. We have also declared four AdapterProperty instances which will be used to add a Gpio pin as a property to each of the AdapterDevice instances.

Next, we make some changes in GetPropertyValue() and SetPropertyValue() function to retrieve and change GPIO pin value for each of the declared Adapter Devices respectively.

We’re done with the code part. But before deploying to your Raspberry Pi let’s connect the relays to the GPIO pins.

Hardware Setup

As mentioned in code above we are using pin number 5, 6, 12, 16, GND and 5V. Connect these pins as shown in the diagram.

Pin Connections Between Raspberry Pi and 4 Channel Relay Module
Pin Connections Between Raspberry Pi and 4 Channel Relay Module

Now connect the Pi to power and network(to which your PC is connected) and deploy the app onto it.

Start Playing

Open AllJoyn Explorer and you will find four Switch Devices that we have added in our code. Explore these devices and you’ll find the Pin Properties too.

AllJoyn Explorer Showing All Connected Switch Devices
AllJoyn Explorer Showing All Connected Switch Devices

Go ahead and change the value of PinValue(Switch 1→Pin5→interface_1) on any of these devices from 1 to 0, this will switch the particular relay on.

Changing Value For Interfaces
Changing Value For Interfaces

Github Repo

Find the project on Github here.

Next Step

Now we have our AllJoyn producer ready. In our next tutorial we’ll see how to make universal app which can run on our Windows PC and Phones and control these switches.

LEAVE A REPLY

Please enter your comment!
Please enter your name here