vermeull
Posts: 7
Joined: Mon May 04, 2015 12:32 am

VB and GPIO

Thu May 14, 2015 5:29 am

Hi All

Has anyone used vb.net to control the gpio pins? I have the following code from the forum which looks correct but the error displayed is "gpio controller is not declared". I have recoded the sample below into c++ and it works fine. Any ideas appreciated.

Len

Code: Select all

Imports Windows.Devices.Gpio
Public NotInheritable Class MainPage
    Inherits Page
    Private gpio
    Private pin As GpioPin
    Private Const LED_PIN = 18

    Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click
        Call TurnLedOnOff()
    End Sub

    Private Sub TurnLedOnOff()

        'Check if gpio was already initialied
        If gpio Is Nothing Then
            gpio = GpioController.GetDefault
        End If

        'Check if LED's pin was already initialied
        If pin Is Nothing Then
            pin = gpio.OpenPin(LED_PIN)
            pin.Write(GpioPinValue.Low)
            pin.SetDriveMode(GpioPinDriveMode.Output)
        End If

        'Read pin status and invert state
        If pin.Read = GpioPinValue.High Then
            pin.Write(GpioPinValue.Low)
        Else
            pin.Write(GpioPinValue.High)
        End If
    End Sub
End Class

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: VB and GPIO

Thu May 14, 2015 5:45 am

vermeull wrote: . . . Any ideas appreciated.

Len
I recommend controlling the gpio on the Raspberry PI using native Python. Here is a great tutorial:

https://learn.sparkfun.com/tutorials/ra ... pigpio-api

https://www.raspberrypi.org/learning/py ... ogrammers/




.
marcus
:ugeek:

vermeull
Posts: 7
Joined: Mon May 04, 2015 12:32 am

Re: VB and GPIO

Thu May 14, 2015 5:49 am

I know it is possible to do it in other languages but I would like to do this project in vb.net.

Len

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: VB and GPIO

Thu May 14, 2015 6:03 am

vermeull wrote:I know it is possible to do it in other languages but I would like to do this project in vb.net.

Len
Something you will learn with experience is that you really want to use the language(s) for your platform that are the 'heart' language of the platform (just like with humans, its better to speak the platform's heart language)

VM-->Rexx
System36-->RPG
gnu/linux generally-->C|C++
Raspberry PI GPIO generally--> Python

You of course are free to do anything you like (its your PI after all). But is the issue vb.net or is the issue making your gpio work? Also, you will get more assistance (especially around here) if you use the RPi.GPIO module and Python to control the RPi GPIO pin-block. But, its up to you.

Is there a reason for requiring vb.net ? ... just curious about that, not being argumentative/
marcus
:ugeek:

vermeull
Posts: 7
Joined: Mon May 04, 2015 12:32 am

Re: VB and GPIO

Thu May 14, 2015 6:10 am

I agree that using the native language is always going to provide the most support for the hardware. The reason for using Vb is because I have a lot of experience with VB and it is supposed to work. I guess I am really just testing the extent to which VB will work on this device.

If it doesn't work I will switch to coding in C++

Len

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: VB and GPIO

Thu May 14, 2015 6:22 am

vermeull wrote:I agree that using the native language is always going to provide the most support for the hardware. The reason for using Vb is because I have a lot of experience with VB and it is supposed to work. I guess I am really just testing the extent to which VB will work on this device.

If it doesn't work I will switch to coding in C++

Len
Fair enough; best of luck
marcus
:ugeek:

GerritV
Posts: 91
Joined: Fri May 01, 2015 4:16 pm
Location: St Catharines, ON
Contact: Website

Re: VB and GPIO

Thu May 14, 2015 12:14 pm

No need to switch/learn a new language. If the capabilities are there for C++ then they are there for all the languages supported by Visual Studio
There is a Reference missing from your project. The GPIO etc functionality is in the Extended WinIoT library. Projects/Add Reference then see the attached screen shot
I am running VS2015RC on a Windows 8.1 PC
The hint that the Reference is missing shows up while you are typing the using/imports line. It should show a drop down as you type Windows, then another as you type Devices. If Gpio is missing from the second list then the correct Reference/lib is not part of your project. Like -lwiniotlib missing on gcc link stage, except you get to find out as you write the code :-)

Gerrit
Attachments
WinIoT.JPG
WinIoT.JPG (48.8 KiB) Viewed 4280 times

vermeull
Posts: 7
Joined: Mon May 04, 2015 12:32 am

Re: VB and GPIO

Thu May 14, 2015 11:50 pm

Thank you very much Gerrit. That fixed it.

Len

Return to “Windows 10 for IoT”