Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

BlinkyVB -- first Netduino app using Visual Basic


  • Please log in to reply
20 replies to this topic

#1 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 08 June 2011 - 08:34 AM

Here is a simple Netduino app using Visual Basic. This is the "hello world" of microcontroller apps; it simply blinks the LED on and off twice a second.

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.Netduino

Module Module1

    Sub Main()

        Dim led As New OutputPort(Pins.ONBOARD_LED, False)

        Do
            led.Write(True)
            Thread.Sleep(250)
            led.Write(False)
            Thread.Sleep(250)
        Loop

    End Sub

End Module
I have attached the project to this post.

Chris

Attached Files



#2 MDalton

MDalton

    New Member

  • Members
  • Pip
  • 6 posts
  • LocationPA

Posted 13 December 2011 - 07:18 AM

I wrote the other project.
The code below turns the onboard LED on when you press the button.
Module Module1

    Sub Main()

        Dim button As New InputPort(Pins.ONBOARD_SW1, False, Port.ResistorMode.Disabled)
        Dim led As New OutputPort(Pins.ONBOARD_LED, False)
        Dim buttonstate As Boolean = False

        Do
            buttonstate = button.Read()
            led.Write(buttonstate)

        Loop
    End Sub

End Module

And then a hybird

The code below flashes the LED when you press the on board button
Module Module1

    Sub Main()
        
        Dim button As New InputPort(Pins.ONBOARD_SW1, False, Port.ResistorMode.Disabled)
        Dim led As New OutputPort(Pins.ONBOARD_LED, False)
        Dim buttonstate As Boolean = False



        Do
            buttonstate = button.Read()
            If buttonstate = True Then
                led.Write(True)
                Thread.Sleep(50)
                led.Write(False)
                Thread.Sleep(100)
            Else

            End If
        Loop
    End Sub

End Module
How do you keep the color formatting?

#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 13 December 2011 - 10:01 AM

How do you keep the color formatting?

If you put [ code ][ /code ] tags around your source code (without the extra spaces), it'll be formatted with a bit of color automatically.

I have added them in for you :)

Chris

#4 MDalton

MDalton

    New Member

  • Members
  • Pip
  • 6 posts
  • LocationPA

Posted 13 December 2011 - 02:20 PM

If you put [ code ][ /code ] tags around your source code (without the extra spaces), it'll be formatted with a bit of color automatically.

I have added them in for you :)

Chris

Thanks :P

#5 tknman0700

tknman0700

    Member

  • Members
  • PipPip
  • 26 posts

Posted 24 April 2012 - 04:26 PM

Any idea why I cannot figure out how to make the button blink the LED using event handler?

Any help is appreciated.


Namespace NetDuinoTogglePower
    Public Class Program
        Shared ledStatus As Boolean = False
        Shared led As New OutputPort(Pins.ONBOARD_LED, ledStatus)
        Public WithEvents boardButton As New InterruptPort(Pins.ONBOARD_SW1, False, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth)

        Public Shared Sub Main()
            Thread.Sleep(Timeout.Infinite)
        End Sub



        Private Shared Sub boardButton_OnInterrupt(ByVal data1 As UInteger, ByVal data2 As UInteger, ByVal time As DateTime) Handles boardButton.OnInterrupt
            ledStatus = Not ledStatus
            led.Write(ledStatus)
        End Sub

    End Class
End Namespace

This is my first vb program when I hit F5 VS tells me the target it not initialized rebooting... it does this every time. Is there something to this? I dont recall seeing this before.

Thanks

#6 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 24 April 2012 - 04:29 PM

This is my first vb program when I hit F5 VS tells me the target it not initialized rebooting... it does this every time. Is there something to this? I dont recall seeing this before.

Have you got the 4.2 beta firmware flashed on your netduino (incl. the new tinybooter)?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#7 tknman0700

tknman0700

    Member

  • Members
  • PipPip
  • 26 posts

Posted 24 April 2012 - 06:19 PM

Thank you for your response.. I am not having a good day here. Yes I have it flashed to 4.2 and run MFDeploy with no errors. Previously when connect to my USB port it would show up... now when I am VS and trying to change the deployment to USB and select my device my device is not listed. Additionally when I run MFDeploy it does not see my device at all. I think my problems are compounding. ; )

#8 tknman0700

tknman0700

    Member

  • Members
  • PipPip
  • 26 posts

Posted 24 April 2012 - 06:26 PM

Ok update - I decided to change USB ports on my laptop. No idea why but that made it show up as Netduino as expected. Now I hit F5 and it says preparing to deploy assemblies to the device for a few minutes... and does nothing. Then I get tired of watching it do nothing and unplug the netduino. Any ideas?

#9 tknman0700

tknman0700

    Member

  • Members
  • PipPip
  • 26 posts

Posted 24 April 2012 - 06:49 PM

More info... MFDeploy now says "Pinging... Error: No response from device" when I try to ping it. Hmm....

#10 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 24 April 2012 - 07:09 PM

I have had that too once. I deployed Microsoft.SPOT.Hardware.PWM to it by accident (it's not compatible with 4.2RC4). I had to re-flash my device, but since then, it works just fine.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#11 tknman0700

tknman0700

    Member

  • Members
  • PipPip
  • 26 posts

Posted 24 April 2012 - 07:29 PM

I have had that too once. I deployed Microsoft.SPOT.Hardware.PWM to it by accident (it's not compatible with 4.2RC4). I had to re-flash my device, but since then, it works just fine.



Ok I reflased and it seems to at least let me deploy now but I dont understand what is wrong with my code trying to handle events.

#12 tknman0700

tknman0700

    Member

  • Members
  • PipPip
  • 26 posts

Posted 24 April 2012 - 07:32 PM

Ok it is because the code was in a class... this code now runs.

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.NetduinoPlus

Module Module1
    Dim ledStatus As Boolean = False
    Dim led As New OutputPort(Pins.ONBOARD_LED, ledStatus)
    Public WithEvents boardButton As New InterruptPort(Pins.ONBOARD_SW1, False, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth)

    Public Sub Main()
        Thread.Sleep(Timeout.Infinite)
    End Sub



    Private Sub boardButton_OnInterrupt(ByVal data1 As UInteger, ByVal data2 As UInteger, ByVal time As DateTime) Handles boardButton.OnInterrupt

        ledStatus = Not ledStatus
        led.Write(ledStatus)
    End Sub

End Module

I am not sure I understand why this matters but it seems to run well now and demonstrates responding to event as opposed to sleep and timer.

#13 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 24 April 2012 - 07:40 PM

Ok it is because the code was in a class... this code now runs.

I am not sure I understand why this matters but it seems to run well now and demonstrates responding to event as opposed to sleep and timer.

Glad to know that, hopefully it can help others as well! :)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#14 voidmain

voidmain

    New Member

  • Members
  • Pip
  • 4 posts

Posted 29 July 2012 - 05:50 PM

'Here is some code to use a potentiometer to set the speed of the flashing onboard led.
'Thanks to those who helped me, I wanted to post the code to help others trying to figure out that
'you need to fully qualify the line shown below since there is a duplicate in Microsoft.SPOT.Hardware
'Dim PotPin As SecretLabs.NETMF.Hardware.AnalogInput = New SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0)


Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.Netduino


Module Module1

    Sub Main()
        ' write your code here
'Code to flash onboard led at rate set by potentiometer
'Hook Left pin facing front of pot to 3.3v on board
'Hook Middle pin facing front of pot to Analog In 0
'Hook Right pin facing front of pot to Gnd pin on board



        Dim Led As OutputPort = New OutputPort(Pins.ONBOARD_LED, False)
        Dim PotPin As SecretLabs.NETMF.Hardware.AnalogInput = New SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0) 'use analog pin 0

        PotPin.SetRange(0, 1023)

        Dim PotVal As Integer
        Dim MyDelay As Integer

        Do While True

            MyDelay = PotPin.Read 'Get value of pot to use as delay
            Led.Write(True)'flash led on
            Thread.Sleep(MyDelay)
            Led.Write(False)'flash led off
            Thread.Sleep(MyDelay)
            Debug.Print(PotPin.Read.ToString) 'print out the value to debug

        Loop

    End Sub

End Module


#15 Dr Who

Dr Who

    Advanced Member

  • Members
  • PipPipPip
  • 261 posts
  • LocationNYC

Posted 24 September 2012 - 02:38 AM

Hello!
Chris has that application been tested on a Netduino running 4.2.0.1? I'm getting an error that says it part that it can't find the device to deploy it to.

Doctor Who
"This signature does not exist!"

#16 Dr Who

Dr Who

    Advanced Member

  • Members
  • PipPipPip
  • 261 posts
  • LocationNYC

Posted 24 September 2012 - 02:46 AM

Ok it is because the code was in a class... this code now runs.

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.NetduinoPlus

Module Module1
    Dim ledStatus As Boolean = False
    Dim led As New OutputPort(Pins.ONBOARD_LED, ledStatus)
    Public WithEvents boardButton As New InterruptPort(Pins.ONBOARD_SW1, False, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth)

    Public Sub Main()
        Thread.Sleep(Timeout.Infinite)
    End Sub



    Private Sub boardButton_OnInterrupt(ByVal data1 As UInteger, ByVal data2 As UInteger, ByVal time As DateTime) Handles boardButton.OnInterrupt

        ledStatus = Not ledStatus
        led.Write(ledStatus)
    End Sub

End Module

I am not sure I understand why this matters but it seems to run well now and demonstrates responding to event as opposed to sleep and timer.


Hello!
I don't either. But your code runs properly, as opposed to the one Chris created. Must be something else doing it. All I changed in it was the platform selection from Plus to a regular Netduino and I was off.

Doctor Who
"This signature does not exist!"

#17 LakeOzark

LakeOzark

    Member

  • Members
  • PipPip
  • 18 posts

Posted 29 December 2012 - 07:55 PM

I am trying to get the Blinkey Program to run on a NetduinoGo board in Visual Basic. Since the NGo has Sockets need to make some changes.

 

The following works on C# 

 

 internal const Cpu.Pin SOCKET8_LED = (Cpu.Pin)41; // SOCKET8_LED  OutputPort led8 = new OutputPort((SOCKET8_LED), false);  led8.Write(false); // turn off the LED

 

How do I write the VB Code

 

Dim led As New OutputPort(Pins.ONBOARD_LED, False) or

Dim led As New OutputPort(Pins.SOCKET8_LED, False)

 

 

 



#18 LakeOzark

LakeOzark

    Member

  • Members
  • PipPip
  • 18 posts

Posted 30 December 2012 - 08:58 PM

Guess I do not understand the ShieldBase. I have been trying to use the sockets alone.  But I guess I will buy a ShieldBase.

 

In the code below why is NetduinoGo.ShieldBase not defined (it is an error in VB)?

I thought I had the latest software. Is there something special about the ShieldBase software?

When I key NetduinoGo and add the . the drop down menu does not include ShieldBase.

 

Imports Microsoft.SPOT

Imports Microsoft.SPOT.Hardware

Imports SecretLabs.NETMF.Hardware

 

Imports SecretLabs.NETMF.Hardware.NetduinoGo

?

Module Module1

 

Sub Main()

 

Dim SB As NetduinoGo.ShieldBase = New NetduinoGo.ShieldBase(GoSockets.Socket5)



#19 Fahdil

Fahdil

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationJakarta, Indonesia

Posted 08 January 2013 - 05:28 AM

Dear crish,

 

I just Find This Problem once I try to built your Blinky Program into My Net+

 

[color=#0000ff;]Cannot deploy the base assembly 'mscorlib', or any of his satellite assemblies, to device - USB:NetduinoPlus twice. Assembly 'mscorlib' on the device has version 4.1.2821.0, while the program is trying to deploy version 4.2.0.0    [/color]
 

 

Last time I built using C# language it's never happen(I mean just work fine). but When I try to built using basic language this error appears.

 

what should I do?

 

Regards

 

 



#20 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 08 January 2013 - 06:19 AM

Dear crish,

 

I just Find This Problem once I try to built your Blinky Program into My Net+

 

[color=rgb(0,0,255);]Cannot deploy the base assembly 'mscorlib', or any of his satellite assemblies, to device - USB:NetduinoPlus twice. Assembly 'mscorlib' on the device has version 4.1.2821.0, while the program is trying to deploy version 4.2.0.0    [/color]
 

 

Last time I built using C# language it's never happen(I mean just work fine). but When I try to built using basic language this error appears.

 

what should I do?

 

Regards

 

Your device is running 4.1.2821.0 and your code 4.2.0.0.

You should upgrade your device to .NETMF 4.2.


"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.