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.
I am trying to use the shield base to read a TMP36 temperature sensor. For testing I have a wire installed between ground and Analog_0.
I am getting an Unhandled exception error of type "System.ArgumentNullException" occurred in mscorlib.dll
Dim SB As NetduinoGo.ShieldBase = New NetduinoGo.ShieldBase(GoSockets.Socket5)
Dim TempSensor As AnalogInput = New AnalogInput(SB.AnalogChannels.ANALOG_0)
...
Debug.Print(TempSensor.Read.ToString("n2"))
If I comment out the 3 lines everything else seems to work (i.e. Display Module etc.)
Also I assume that the maximum reading for an analog channel should be 4095 for the 12 bit ADC.
I am using:
Dim voltage As Double = TempSensor.Read * 3.3 / 4095
temperature = CSng((voltage - 0.5) * 100)
to convert to degrees centigrade.
If anyone has similar code that they can share it would be appreciated.
Also I assume that the maximum reading for an analog channel should be 4095 for the 12 bit ADC.
...
Dim voltage As Double = TempSensor.Read * 3.3 / 4095
The .ReadRaw() function will return a value in the range of { 0-4095 }. The .Read() function of the new .NET MF 4.2 AnalogInput class will return a value between 0.0 and 0.9999.
If you remove the "/ 4095" your data should look much better...
The .ReadRaw() function will return a value in the range of { 0-4095 }. The .Read() function of the new .NET MF 4.2 AnalogInput class will return a value between 0.0 and 0.9999.
If you remove the "/ 4095" your data should look much better...
Chris
I must be working with an old .net MF 4.2, I was not seeing a .ReadRaw() function. I was getting the number 1000 for A0, 1001 for A1 etc. it look more like an address code.
Then I started get error exceptions.
I backed out everything except the SB and a debug.print line and was still having problems.
I must be working with an old .net MF 4.2, I was not seeing a .ReadRaw() function. I was getting the number 1000 for A0, 1001 for A1 etc. it look more like an address code.
The numbers 1000, 1001, etc. are the virtual channel #s for the analog inputs on the shield base. When you use .Read() you'll get a floating point number back. If it's anything outside the range of 0.0 to 0.999, please let us know.
You should only get the virtual channel # back if you ask for the channel # and convert it to a number.
The numbers 1000, 1001, etc. are the virtual channel #s for the analog inputs on the shield base. When you use .Read() you'll get a floating point number back. If it's anything outside the range of 0.0 to 0.999, please let us know.
You should only get the virtual channel # back if you ask for the channel # and convert it to a number.
Chris
Chris,
I reloaded the .net MF 4.2 signed drivers, no change.
Started a new project, entered the code with the reccommended changes(changed to .ReadRaw & removed the / 4095).
I am still getting an Exception Error.
Current code is: (I am sending TempSensor.ReadRaw to a Debug.Print until I get it working that far)
Imports System
Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware.NetduinoGo
Namespace NetduinoGo_Test
Public Module Module1
Dim SB As NetduinoGo.ShieldBase = New NetduinoGo.ShieldBase(GoSockets.Socket5)
Dim TempSensor As New AnalogInput(SB.AnalogChannels.ANALOG_0)
Sub Main()
While True
Debug.Print(TempSensor.ReadRaw.ToString)
'WriteTemperature(GetAverageTemperature)
Thread.Sleep(5000)
End While
End Sub
Function GetTemperature() As Single
Dim voltage As Single = CSng(TempSensor.ReadRaw * 3.3)
Return CSng((voltage - 0.5) * 100)
End Function
Function GetAverageTemperature() As Single
Dim TotalTemp As Single = 0
Dim AverageTemp As Single
TotalTemp += GetTemperature()
AverageTemp = TotalTemp / 1
Return AverageTemp
End Function
Sub WriteTemperature(ByVal CTemp As Single)
Dim FTemp As Single = CTemp * 9 / 5 + 32
Dim KTemp As Single = CTemp + CSng(273.15)
Dim RTemp As Single = FTemp + CSng(459.67)
Dim DT As Date = Date.Now
Dim CString As String = "Celsius = " + CTemp.ToString("N2")
Dim FString As String = "Farenheit = " + FTemp.ToString("N2")
Dim KString As String = "Kelvin = " + KTemp.ToString("N2")
Dim RString As String = "Rankine = " + RTemp.ToString("N2")
Debug.Print(CString + " " + FString + " " + KString + " " + RString)
End Sub
End Module
End Namespace
Any Suggestions to stop the exceptions?
The Output window had this information:
The debugging target runtime is loading the application assemblies and starting execution.
Ready.
A first chance exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
An unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
Uncaught exception
A first chance exception of type 'System.NullReferenceException' occurred in NetduinoPlusApplication5.exe
An unhandled exception of type 'System.NullReferenceException' occurred in NetduinoPlusApplication5.exe
Uncaught exception
Done.
Waiting for debug commands...
Dim SB As NetduinoGo.ShieldBase = New NetduinoGo.ShieldBase(GoSockets.Socket5)
Dim TempSensor As New AnalogInput(SB.AnalogChannels.ANALOG_0)
[code]
It's possible that these aren't getting created in order. Which is sort of important, since the AnalogInput can't be created until after the Shield Base.
What if you change those two lines too...
[code]
Dim SB As NetduinoGo.ShieldBase
Dim TempSensor As AnalogInput
[/code]
And then add the following code to the beginning of your Main Sub...
[code]
SB = New NetduinoGo.ShieldBase(GoSockets.Socket5)
TempSensor = New AnalogInput(SB.AnalogChannels.ANALOG_0)
Finally, is your Shield Base on socket 5? And as importantly, have you made sure to dedicate the whole go!bus channel (sockets 5-8) to the shield base? During the first month or so of the beta, you'll need to keep the same-channel sockets clear...
Dim SB As NetduinoGo.ShieldBase = New NetduinoGo.ShieldBase(GoSockets.Socket5)
Dim TempSensor As New AnalogInput(SB.AnalogChannels.ANALOG_0)
[code]
It's possible that these aren't getting created in order. Which is sort of important, since the AnalogInput can't be created until after the Shield Base.
What if you change those two lines too...
[code]
Dim SB As NetduinoGo.ShieldBase
Dim TempSensor As AnalogInput
[/code]
And then add the following code to the beginning of your Main Sub...
[code]
SB = New NetduinoGo.ShieldBase(GoSockets.Socket5)
TempSensor = New AnalogInput(SB.AnalogChannels.ANALOG_0)
Finally, is your Shield Base on socket 5? And as importantly, have you made sure to dedicate the whole go!bus channel (sockets 5-8) to the shield base? During the first month or so of the beta, you'll need to keep the same-channel sockets clear...
Chris
Sorry I didn't get right back to you I was in the chat room,
I will try the suggested changes and get back to you.
The shield base is plugged into socket 5 with nothing in 6 through 8.
I am now reading the analog pin. I will put the Nwazet Display code back in and hook up the TMP36 (I tried the code with a wire from the 3.3v ref, then unhook the 3.3v and connected to ground) the .ReadRaw displayed 4095 for 3.3v and 1 for ground).
I changed to just the .Read (displays 0.0 to 1.0) and removed the divide by 4095 and got the correct temperature readings for the inputs to analog_0.
I'll post the corrected code either tonight or tommorrow morning.
It is now working correctly or at least the way I wanted it to work.
The program is written in Visual Basic, uses the Netduino Go main board, Nwazet Display Module, RGBLed Module, Shield Base Module and a TMP-36 Temperature Sensor to display an averaged temperature in Clesius, Farenheit, Kelvin & Rankine to the LCD touchscreen display every 10 seconds.
The RGB Led changes colors based on the current temperature, Blue for to Cold, Red for to Hot and Green for just right.
Hopefully the code will help someone else get started with VB.Net and Neduino Go!
Imports System
Imports System.IO
Imports System.Threading
Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware.NetduinoGo
Imports Nwazet.Go.Fonts
Imports Nwazet.Go.Imaging
Imports Nwazet.Go.Display.TouchScreen
Namespace Basic_go_display
Public Module Module1
Dim canvas As VirtualCanvas
Dim SB As NetduinoGo.ShieldBase
Dim Led As RgbLed
Dim TempSensor As AnalogInput
Public ReadOnly ColorBackground As UShort = CUShort(BasicColor.Blue)
Dim lastTouchX As Integer
Dim lastTouchY As Integer
Sub Main()
canvas = New VirtualCanvas(AddressOf TouchEventHandler, AddressOf WidgetClickedHandler)
canvas.Initialize(GoSockets.Socket4)
canvas.TouchscreenCalibration()
SB = New NetduinoGo.ShieldBase(GoSockets.Socket5)
Led = New RgbLed
TempSensor = New AnalogInput(SB.AnalogChannels.ANALOG_0)
While True
WriteTemperature(canvas, GetAverageTemperature)
Thread.Sleep(8000)
End While
canvas.Reboot()
canvas.Dispose()
End Sub
Function GetTemperature() As Single
Dim voltage As Single = CSng(TempSensor.Read * 3.3)
Return CSng((voltage - 0.5) * 100)
End Function
Function GetAverageTemperature() As Single
Dim TotalTemp As Single = 0
Dim AverageTemp As Single
For i = 0 To 19 Step 1
TotalTemp += GetTemperature()
Thread.Sleep(50)
Next
AverageTemp = CSng(TotalTemp / 20)
Return AverageTemp
End Function
Public Sub TouchEventHandler(ByVal touchEvent As TouchEvent)
Debug.Print("------------TouchEventHandler------------")
Debug.Print("X: " & touchEvent.X.ToString)
Debug.Print("Y: " & touchEvent.Y.ToString)
Debug.Print("Pressure: " & touchEvent.Pressure.ToString)
lastTouchX = touchEvent.X
lastTouchY = touchEvent.Y
End Sub
Public Sub WidgetClickedHandler(ByVal widget As Widget, ByVal touchEvent As TouchEvent)
End Sub
Public Sub WriteTemperature(ByVal canvas As VirtualCanvas, ByVal CTemp As Single)
Dim fontInfo = New Fonts.Verdana14().GetFontInfo()
Dim FTemp As Single = CTemp * 9 / 5 + 32
Dim KTemp As Single = CTemp + CSng(273.15)
Dim RTemp As Single = FTemp + CSng(459.67)
Dim DT As Date = Date.Now
Dim CString As String = "Celsius = " + CTemp.ToString("N1")
Dim FString As String = "Farenheit = " + FTemp.ToString("N1")
Dim KString As String = "Kelvin = " + KTemp.ToString("N1")
Dim RString As String = "Rankine = " + RTemp.ToString("N1")
canvas.DrawFill(CUShort(ColorBackground))
canvas.DrawString(10, 10, CUShort(BasicColor.White), fontInfo.ID, DT.ToString)
canvas.DrawString(10, 50, CUShort(BasicColor.White), fontInfo.ID, CString)
canvas.DrawString(10, 80, CUShort(BasicColor.White), fontInfo.ID, FString)
canvas.DrawString(10, 110, CUShort(BasicColor.White), fontInfo.ID, KString)
canvas.DrawString(10, 140, CUShort(BasicColor.White), fontInfo.ID, RString)
If FTemp < 72.0 Then
canvas.DrawString(10, 170, CUShort(BasicColor.Cyan), fontInfo.ID, "Damn it's Cold!")
Led.SetColor(0, 0, 75)
ElseIf FTemp > 75 Then
canvas.DrawString(10, 170, CUShort(BasicColor.Red), fontInfo.ID, "It's to Hot!")
Led.SetColor(75, 0, 0)
Else
canvas.DrawString(10, 170, CUShort(BasicColor.Green), fontInfo.ID, "It Feels Good.")
Led.SetColor(0, 75, 0)
End If
canvas.Execute()
End Sub
End Module
End Namespace
The biggest problem is setting up the references and where they are located, this should go away with the release of the Netduino Go templates.
The program is written in Visual Basic, uses the Netduino Go main board, Nwazet Display Module, RGBLed Module, Shield Base Module and a TMP-36 Temperature Sensor to display an averaged temperature in Clesius, Farenheit, Kelvin & Rankine to the LCD touchscreen display every 10 seconds.
The RGB Led changes colors based on the current temperature, Blue for to Cold, Red for to Hot and Green for just right.
This is awesome! Did you take a video of it by any chance? We'd love to tweet about it and share your project with 1,000 or so Twitter followers...
This is awesome! Did you take a video of it by any chance? We'd love to tweet about it and share your project with 1,000 or so Twitter followers...
Chris
No, but I as soon as I can get a chance to clean my desk off (i.e. put away the extra modules and Netduino boxes etc.) Never mind I move into the Living Room.
Fantastic job Chuck. I just tried out your code, though it took me a bit to get it running at first. I haven't touched VB since the classic ASP days and was pretty rusty. The only change I had to make was
Dim Led As RgbLed
to
Dim Led As NetduinoGo.RgbLed
I also had to use the other constructor for VirtualCanvas, when I could not get rid of errors when using the event handlers. This worked out fine since you are only outputting text to the display.
canvas = New VirtualCanvas()
I was wondering why you decided to use an average for the temperature. I have been trying the TMP-36 in my C# sharp project but was getting thrown off by the sporadic temperature readings that changed by a plus/minus of 3.5 degrees at any given sample per 1000ms. The use of an average temperature certainly smooths things out, but I had assumed that with the new and more accurate ADC on the Netduino Go, that the analog reading wouldn't fluctuate as much. In comparison, my Netduino Plus did not fluctuate nearly as much. Were you finding the same sort of fluctuation on your shield base or is this just an artifact of my shoddy C# code .
I will reproduce and post your code in C# so others can have a much fun we have.
Fantastic job Chuck. I just tried out your code, though it took me a bit to get it running at first. I haven't touched VB since the classic ASP days and was pretty rusty. The only change I had to make was
Dim Led As RgbLed
to
Dim Led As NetduinoGo.RgbLed
I also had to use the other constructor for VirtualCanvas, when I could not get rid of errors when using the event handlers. This worked out fine since you are only outputting text to the display.
canvas = New VirtualCanvas()
I was wondering why you decided to use an average for the temperature. I have been trying the TMP-36 in my C# sharp project but was getting thrown off by the sporadic temperature readings that changed by a plus/minus of 3.5 degrees at any given sample per 1000ms. The use of an average temperature certainly smooths things out, but I had assumed that with the new and more accurate ADC on the Netduino Go, that the analog reading wouldn't fluctuate as much. In comparison, my Netduino Plus did not fluctuate nearly as much. Were you finding the same sort of fluctuation on your shield base or is this just an artifact of my shoddy C# code .
I will reproduce and post your code in C# so others can have a much fun we have.
Thanks,
Steve
Thanks Steve sorry for the delay in getting back to you, I had to fly up from Tampa, Florida to Raleigh, North Carolina for the week.
I don't have my computer with me just a Samsung Tablet.
I believe the reason that you had to make some changes was I had to reference the Nwazet Libraries, I did not have the new ones. I think that the RGBLed was different.
I used an average because when I was using the TMP-36 on a Netduino Plus I was getting a lot of noise in the readings. On the Go! It was a lot more stabile.
I did reduce the average from 60 samples down to 20, You could most likely reduce further or remove it.
I original started writting it in C# but decided to try Visual Basic, mainly because I didn't see anyone trying that.
The code that I had in C# I used a translator on to help with the visual basic code. It saved a lot of time in help looking for proper syntax.
Thank you Chuck. It was a great start for anyone wanting to test the new Netduino Go, Shield Base, Nwazet Display, and RGBLed module.
In case anyone wanted to try to same project out using C# here is the code. Note, that there are some sutle differences, and once gotcha. It would seem that as of the Shield Base Beta realease and .NETMF 4.2 QFE1, it would appear NETMF is creating some dependent objects out of order when trying to create them at the static class level. If you try move a static object outside of the main as such:
public static AnalogInput tempSensor = new AnalogInput(SB.AnalogChannels.ANALOG_0);
your code may throw the error
An unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
If you don't notice this behaviour please let me know what OS and framework version you are using.
Again, thanks Chuck for the code and great example using almost all of the new Netduino Go modules.
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoGo;
using Nwazet.Go.Helpers;
using Nwazet.Go.Fonts;
using Nwazet.Go.Imaging;
using Nwazet.Go.Display.TouchScreen;
using Nwazet.Go.SD;
namespace Basic_go_display
{
public class Program
{
public static NetduinoGo.RgbLed Led = new NetduinoGo.RgbLed(GoSockets.Socket1);
public static NetduinoGo.ShieldBase SB = new NetduinoGo.ShieldBase(GoSockets.Socket5);
public static double tempInput = 0;
public static readonly ushort ColorBackground = (ushort)BasicColor.Blue;
public static void Main()
{
//As of the Shield Base Beta realease and .NETMF 4.2 QFE1, it would appear NETMF is
//creating some dependent objects out of order by creating these at the static class level.
AnalogInput tempSensor = new AnalogInput(SB.AnalogChannels.ANALOG_0); // defines the temperature sensor as being connected to analog pin 0
var canvas = new VirtualCanvas();
canvas.Initialize(GoSockets.Socket4); // Connect the Nwazet Display module to socket 4
while (true)
{
tempInput = tempSensor.Read(); //Read the sensor value.
WriteTemperature(canvas, GetAverageTemperature());
Thread.Sleep(8000);
}
canvas.Reboot();
canvas.Dispose();
}
public static void WriteTemperature(VirtualCanvas canvas, double CTemp)
{
var fontInfo = new Verdana14().GetFontInfo();
double FTemp = CTemp * 9 / 5 + 32;
double KTemp = CTemp + 273.15;
double RTemp = FTemp + 459.6;
var DT = DateTime.Now;
string CString = "Celsius = " + CTemp.ToString("N1");
string FString = "Farenheit = " + FTemp.ToString("N1");
string KString = "Kelvin = " + KTemp.ToString("N1");
string RString = "Rankine = " + RTemp.ToString("N1");
canvas.DrawFill(ColorBackground);
canvas.DrawString(10, 10, (ushort)BasicColor.White, fontInfo.ID, DT.ToString());
canvas.DrawString(10, 50, (ushort)BasicColor.White, fontInfo.ID, CString);
canvas.DrawString(10, 80, (ushort)BasicColor.White, fontInfo.ID, FString);
canvas.DrawString(10, 110, (ushort)BasicColor.White, fontInfo.ID, KString);
canvas.DrawString(10, 140, (ushort)BasicColor.White, fontInfo.ID, RString);
if(FTemp < 72.0)
{
canvas.DrawString(10, 170, (ushort)BasicColor.Cyan, fontInfo.ID, "Damn it's Cold!");
Led.SetColor(0, 0, 75);
}else if (FTemp > 75) {
canvas.DrawString(10, 170, (ushort)BasicColor.Red, fontInfo.ID, "It's too Hot!");
Led.SetColor(75, 0, 0);
} else {
canvas.DrawString(10, 170, (ushort)BasicColor.Green, fontInfo.ID, "It Feels Good.");
Led.SetColor(0, 75, 0);
}
canvas.Execute();
}
public static float getTemperature()
{
float voltage = ((float)tempInput) * 3.3f; // The read value is from 0-1, so this multiplies by 3.3v
// to get the real voltage that was read.
float temp = (voltage - 0.5f); // The datasheet for the sensor indicates there's a 500mV (half a volt)
// offset, this is to allow it to read under 0 degrees
return temp * 100; // Finally, every 10mV indicates 1 degree Celsius, so multiply by 100
// to convert the voltage to a reading
}
public static float GetAverageTemperature()
{
float totalTemp = 0;
float averageTemp;
for(int i = 0; i <= 19; i++)
{
totalTemp += getTemperature();
Thread.Sleep(50);
}
averageTemp = totalTemp/20;
return averageTemp;
}
}
}
The C# code is off. It seems like you want to average 20 samples, but you only take 19. Your FOR loop is off by one. This will lead to a slight underestimation of the temperature.
The C# code is off. It seems like you want to average 20 samples, but you only take 19. Your FOR loop is off by one. This will lead to a slight underestimation of the temperature.
You're exactly right. The VB for loops are a little different and I overlooked the equal sign.
Steve,
Some where back in the threads I had problems with the order that I declared the module, Chris reccommended changing the order and the exception went away.
I also had a version that used 2 potentiometers, 1 changed the setpoint and the other changed the deadband. It would be very easy to drive relays off the sheild base Digital io to control fans, heaters etc.
I will try to post it when I get back home on Saturday.
Chuck
I have to say, the shield was fairly easy to work with. Today I took a couple sensors I had laying around and wired them to the Shield Base Module and after a little coding, was able to get them displaying their values. Very happy with it so far. Next, I'm going to get an SD card module, then see if I can get the shield I made for Pandora's Box Project working with the Netduino GO and the Shield Base Module.
I have to say, the shield was fairly easy to work with. Today I took a couple sensors I had laying around and wired them to the Shield Base Module and after a little coding, was able to get them displaying their values. Very happy with it so far. Next, I'm going to get an SD card module, then see if I can get the shield I made for Pandora's Box Project working with the Netduino GO and the Shield Base Module.
That is fantastic news Dave! If you have any examples that you are willing to share, I would love to see them. Granted I more than likely don't have the vast array of sensors that I'm sure your workbench is cluttered with
I have to say, the shield was fairly easy to work with. Today I took a couple sensors I had laying around and wired them to the Shield Base Module and after a little coding, was able to get them displaying their values. Very happy with it so far. Next, I'm going to get an SD card module, then see if I can get the shield I made for Pandora's Box Project working with the Netduino GO and the Shield Base Module.
You'll probably want to wait a few weeks for the SD go!module. At some point in the future, we may be able to support SD via the shield base (using SPI and a shield) but we haven't enabled that feature quite yet...