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.
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 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
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.
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)?
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.
; )
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?
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.
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.
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.
'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
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.
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.
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)
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.
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.