- Netduino Forums
- → Bainesbunch's Content
Bainesbunch's Content
There have been 54 items by Bainesbunch (Search limited from 03-May 23)
#25422 Netduino Firmware v4.2.0 RC4 (Netduino + Netduino Plus)
Posted by Bainesbunch on 12 March 2012 - 08:38 PM in Beta Firmware and Drivers
#22966 Mifare RFID Example Code With I2C LCD Output
Posted by Bainesbunch on 18 January 2012 - 11:30 PM in Visual Basic Support
Hi Pete,
Thanks for the post I was looking into an RFID project myself!
Can you tell me how you found programming in VB on the mircro framework? I still torn between learning C# and just going ahead an using VB which I'm more familiar with?
Thanks
Logicalstep
Hi Logicalstep,
firstly let us start be dispelling a few misunderstandings about VB.
- VB dates back over 15 years and has been about a lot longer than c#.
- C and C++ however have been about almost the same time.
- When MS included it in their first manifestation of Visual Studio it suddenly became accessible to more people.
- You can create Dlls in VB just search for my other posts where I added to Baxters original post on the CLR.
I am a dedicated VB programmer in the .net arena from asp.net to windows application .NET to .net Compact framework and finally to .NET Micro Framework.
There is very little that you cannot do in VB that you can in c# after all they both compile down to the CLR.
If you need help or pointer on how to do things feel free to drop me a PM or post to this thread.
Cheers Pete.
#22950 Mifare RFID Example Code With I2C LCD Output
Posted by Bainesbunch on 18 January 2012 - 05:15 PM in Visual Basic Support
Attached Files
- RFID_YHY502.zip 660.34KB 189 downloads
#25297 Is my netduino faulty? Simple analog test = 1023 constant :(
Posted by Bainesbunch on 09 March 2012 - 07:34 PM in Netduino 2 (and Netduino 1)
It is an excellent tool for designing circuits and sharing them with others.
It has a breadboard build platform that allows you to design your system using a visual interface.
If you get this and design your idea using it you can share the .fz file here on the forum and other can modify it and send it back to you.
This may help us to understand the way you have things wired up and make suggestions on how to fix it.
Cheers Pete.
#25306 Is my netduino faulty? Simple analog test = 1023 constant :(
Posted by Bainesbunch on 09 March 2012 - 09:16 PM in Netduino 2 (and Netduino 1)
#25250 Is my netduino faulty? Simple analog test = 1023 constant :(
Posted by Bainesbunch on 08 March 2012 - 07:54 PM in Netduino 2 (and Netduino 1)
You might want to try adding a simple digital low-pass filter to the output of the ADC to remove the noise..
This is an example of one that I am using in some inclinometer readings to remove the high frequency stuff and just give me the filtered version of the signal.
i have attached the code here to Lowpass.vb 844bytes 1 downloads
Imports System Public Class LowPassFilter Private m_Top As Double Private m_Cutoff As Double Private m_Value As Double Public ReadOnly Property Value() As Double Get Return m_Value End Get End Property Public Sub New(ByVal cutoff As Double) Me.New(cutoff, 0) End Sub Public Sub New(ByVal cutoff As Double, ByVal initialState As Double) If cutoff > 0.75 Then Throw New ArgumentOutOfRangeException("cutoff should be less than 0.75") End If m_Cutoff = cutoff m_Top = 1 - m_Cutoff m_Value = initialState End Sub Public Function Update(ByVal value As Double) As Double m_Value = (m_Value * m_Top) + (value * m_Cutoff) Return m_Value End Function End Class
You call "update" each time you take a reading passing the raw reading to the filter and then use the "value" property of the filter to get the filtered value.
You instantiate the class object with either just a cut-off value or both a cut-off value and an initial value.
Have fun and I hope this helps
<edit for additional ideas >
One way to make this smoothe is to put your code that reads and updates the filter into a thread of its own. You can put a small thread sleep of say 100ms. The faster you read the adc the better the noise rejection of the filter. I have some examples of how I do this in my inclinometer code if you would like to use them drop me a MP and I will send you the code.
<edit end>
Cheers Pete.
#25299 Is my netduino faulty? Simple analog test = 1023 constant :(
Posted by Bainesbunch on 09 March 2012 - 08:12 PM in Netduino 2 (and Netduino 1)
#43374 Multi threading
Posted by Bainesbunch on 14 January 2013 - 09:55 AM in Visual Basic Support
Same as you do in any .NET environment
#28088 ReDim Preserve
Posted by Bainesbunch on 25 April 2012 - 04:53 PM in Visual Basic Support
#23029 Debugging stops
Posted by Bainesbunch on 19 January 2012 - 11:05 PM in General Discussion
public static void Main() { while (true) { System.Threading.Thread.Sleep(1000); } }
This is interesting then what happens if you create and instantiate a new thread. Do all threads terminate when the main loop exits ?
Should you terminate any threads you create after exiting the main loop before the application exits.
Cheers Pete.
#23051 Debugging stops
Posted by Bainesbunch on 20 January 2012 - 10:37 AM in General Discussion
It is my understanding that everything will terminate when the main thread exits. That's why you need to keep it alive for the lifetime of your application run.
That's not to say it has to DO anything. Like I said, it can sleep the whole time and not take up any execution time. In this case, all the work would be done using other threads and events. This approach of event-based programming means your system might go into low power mode because there is nothing that needs attention right at this second. As soon as some interrupt or event is fired, the system will process the instructions then fall back to sleep.
This contrasts with the design of having a single thread that just loops instructions forever. In this case, unless you insert sleep states, you will be using power checking for changes rather than waiting for them to occur and run down your battery very quickly.
-Erik
OK lets separate the principles of threads from events.
Events as we know are raised by several methods, a transition of state on an input pin, a byte arriving at the UART, a timer rolling over of even a user generated event.
Threads are the individual program paths that can run contemporaneously on the device.
Putting the main thread into a sleep is not suspending the CPU and reducing power requirements. The underlying OS is beavering away waiting for events tiding up memory (Garbage collection) etc etc.
So I have some questions.
Are all events in the MF thread safe. In the CF and ordinary frameworks we usually use delegates to handle cross threading events. This does not seem to exists in the MF.
If we do a thread.sleep with a child thread it is blocking sibling threads or the parent thread as well as the thread it is executed on. Take the snippet of code here …
Imports Microsoft.SPOT Imports Microsoft.SPOT.Hardware Imports SecretLabs.NETMF.Hardware Imports SecretLabs.NETMF.Hardware.Netduino Module Module1 Private HeartBeatThread As Thread Private StatusLEDThread As Thread Private watchdogTimer As Timer Private StatusLEDTimer As Timer Private LED_1 As New OutputPort(Pins.GPIO_PIN_D5, False) Private LED_2 As New OutputPort(Pins.GPIO_PIN_D6, False) Sub Main() ' create 2 new threads HeartBeatThread = New Thread(AddressOf StartHeartBeatThread) StatusLEDThread = New Thread(AddressOf StartStatusLEDThread) 'Start them up HeartBeatThread.Start() StatusLEDThread.Start() 'enter main loop and loop forever While True End While End Sub Private Sub StartHeartBeatThread() Dim HeartBeatDelegate As New TimerCallback(AddressOf LED1) watchdogTimer = New Timer(HeartBeatDelegate, Nothing, 1000, 1000) 'enter endless loop in thread While True End While End Sub Private Sub StartStatusLEDThread() Dim StatusLEDDelegate As New TimerCallback(AddressOf LED2) StatusLEDTimer = New Timer(StatusLEDDelegate, Nothing, 250, 250) 'enter endless loop in thread While True End While End Sub Private Sub LED1(ByVal stateInfo As Object) LED_1.Write(Not LED_1.Read) HeartBeatThread.Sleep(500) End Sub Private Sub LED2(ByVal stateInfo As Object) LED_2.Write(Not LED_2.Read) End Sub End Module
So we create two new threads point them at some code and start them. Within the code of each we create a timer and point the event handler at another method. Then in each thread we enter an endless loop. Now in theory each timer is operating within its own thread and the thread is looping endlessly.
Now some questions.
- When we exit the main loop does the system kill the two threads we have created for us [No the threads we have created continue to run even after the main loop has exited, they need to be explicitly stopped in the main thread with a HeartBeatThread.Abort() and StatusLEDThread.Abort()]
- No matter what blocking we have on thread "HeartBeatThread" we should expect the LED2 method on thread "StatusLEDThread" to be called every 250ms. [This does NOT work calls to the Sleep on method in the "HeartBeatThread" thread (HeartBeatThread.Sleep(500) or Thread.CurrentThread.Sleep(500)) cause the whole program to sleep, this is not good as it means that threads can become application blocking, this negates the whole point of threads]
You can also get rid of the infinite loop in te main thread if you wish by executing the following Thread.Sleep(Threading.Timeout.Infinite) Oddly enough however this does not seem to block unlike a sleep in another thread.
Code attached to play with.
Cheers Pete.
Attached Files
- Thread Test.zip 49.61KB 1 downloads
#23053 Debugging stops
Posted by Bainesbunch on 20 January 2012 - 12:19 PM in General Discussion
In the attached code I have removed the timers from the code path and just toggle the LED states within a loop in the individual threads. This seems to work a treat with NO blocking issues. Now i have to re-think my code and instead of timers in threads simply loop with a sleep.
Cheers Pete.
Attached Files
- Thread Test.zip 49.53KB 4 downloads
#25544 Minimum AnalogInput Read value
Posted by Bainesbunch on 15 March 2012 - 01:32 PM in Netduino Plus 2 (and Netduino Plus 1)
So...
...proceed as follows:
- comment the SetRange call, so that the value given by the port won't be elaborated at all;
- point the multimeter on the analog input and give me a stable value;
- at the same time, tell me what's the Read method returns.
I'd also try to swap the photosensor with any trimpot, if you have. Please, tell me if you own any, and -if so- what value is marked on.
Cheers
You might also want to tie the unused analogue inputs to ground. I have had erratic readings when these are alowed to "float"
Cheers Pete.
#25970 PWM Input from the ground up
Posted by Bainesbunch on 25 March 2012 - 06:07 PM in Netduino 2 (and Netduino 1)
#22843 4.2 VB.net String to double conversion
Posted by Bainesbunch on 16 January 2012 - 08:11 PM in Netduino Plus 2 (and Netduino Plus 1)
Imports Microsoft.SPOT Imports Microsoft.SPOT.Hardware Imports SecretLabs.NETMF.Hardware Imports SecretLabs.NETMF.Hardware.NetduinoPlus Module Module1 Sub Main() Dim ErectParkDecerlationPoint As Double = CDbl("10.000") Debug.Print("ErectParkDecerlationPoint = " & ErectParkDecerlationPoint.ToString) '--> ErectParkDecerlationPoint = 10 Dim a As Double = CDbl("12345.6789") Debug.Print("a = " & a.ToString) 'a = 12345.678900000001 Dim b As Double = CDbl("166511.001e9") Debug.Print("b = " & b.ToString) 'b = 166511.00099999999 End Sub End Module
#22832 4.2 VB.net String to double conversion
Posted by Bainesbunch on 16 January 2012 - 03:12 PM in Netduino Plus 2 (and Netduino Plus 1)
I am having some issues converting a string into a double using the CDbl(...) method. It is throwing a System.NotImplementedException.
How do we convert a string into a double without this method ?
I have a configuration file stored on the SD card where i save and retrieve values in an eye readable format so that the user can "edit" them in notepad etc. I.E. 100,10.000,2.5,6 these need to be read back into the application and converted into either bytes integers doubles etc. any help gratefully received.
the offending code looks like this
dim ErectParkDecerlationPoint as double = CDbl("10.000")
Here is the output trace for the call.
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.IsHexOrOctValue' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.IsHexOrOctValue' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.IsHexOrOctValue' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetCultureInfo' Step into: Stepping over non-user code 'System.Globalization.CultureInfo.CurrentUICulture.get' Step into: Stepping over non-user code 'System.Globalization.CultureInfo.CurrentUICulture.get' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetCultureInfo' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble' Step into: Stepping over non-user code 'System.Globalization.CultureInfo.NumberFormat.get' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetNormalizedNumberFormat' Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberDecimalSeparator.get' Step into: Stepping over non-user code 'System.Globalization.CultureInfo.EnsureStringResource' Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberDecimalSeparator.get' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetNormalizedNumberFormat' Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberGroupSeparator.get' Step into: Stepping over non-user code 'System.Globalization.CultureInfo.EnsureStringResource' Step into: Stepping over non-user code 'System.Resources.ResourceManager.GetObjectFromId' Step into: Stepping over non-user code 'System.Resources.ResourceManager.GetObjectFromId' Step into: Stepping over non-user code 'System.Globalization.CultureInfo.EnsureStringResource' Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberGroupSeparator.get' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetNormalizedNumberFormat' Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberDecimalSeparator.get' Step into: Stepping over non-user code 'System.Globalization.CultureInfo.EnsureStringResource' Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberDecimalSeparator.get' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetNormalizedNumberFormat' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetNormalizedNumberFormat' Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberGroupSeparator.get' Step into: Stepping over non-user code 'System.Globalization.CultureInfo.EnsureStringResource' Step into: Stepping over non-user code 'System.Globalization.NumberFormatInfo.NumberGroupSeparator.get' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetNormalizedNumberFormat' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.GetNormalizedNumberFormat' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ToHalfwidthNumbers' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble' Step into: Stepping over non-user code 'double.Parse' Step into: Stepping over non-user code 'System.Convert.ToDouble' Step into: Stepping over non-user code 'System.Convert.ToDouble' Step into: Stepping over non-user code 'System.Convert.ToDouble' Step into: Stepping over non-user code 'System.Convert.ToDouble' Step into: Stepping over non-user code 'System.Convert.ToDouble' Step into: Stepping over non-user code 'System.Convert.ToDouble' Step into: Stepping over non-user code 'System.Convert.ToDouble' Step into: Stepping over non-user code 'System.Convert.GetDoubleNumber' Step into: Stepping over non-user code 'System.Convert.ToDouble' A first chance exception of type 'System.NotImplementedException' occurred in mscorlib.dll Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble' A first chance exception of type 'System.NotImplementedException' occurred in Microsoft.VisualBasic.dll Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble' Step into: Stepping over non-user code 'System.Exception.Message.get' Step into: Stepping over non-user code 'System.Exception.Message.get' Step into: Stepping over non-user code 'System.Exception.Message.get' Step into: Stepping over non-user code 'System.Exception.Message.get' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble' Step into: Stepping over non-user code 'System.InvalidCastException.InvalidCastException' Step into: Stepping over non-user code 'System.SystemException.SystemException' Step into: Stepping over non-user code 'System.Exception.Exception' Step into: Stepping over non-user code 'System.Exception.Exception' Step into: Stepping over non-user code 'System.SystemException.SystemException' Step into: Stepping over non-user code 'System.InvalidCastException.InvalidCastException' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble' A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll Step into: Stepping over non-user code 'System.IO.TextReader.Dispose' Step into: Stepping over non-user code 'System.IO.StreamReader.Dispose' Step into: Stepping over non-user code 'System.IO.Stream.Close' Step into: Stepping over non-user code 'System.IO.FileStream.Dispose' Step into: Stepping over non-user code 'System.IO.FileStream.Dispose' Step into: Stepping over non-user code 'System.IO.FileSystemManager.RemoveFromOpenList' Step into: Stepping over non-user code 'System.IO.FileSystemManager.RemoveFromOpenList' Step into: Stepping over non-user code 'System.Collections.ArrayList.Remove' Step into: Stepping over non-user code 'System.Array.IndexOf' Step into: Stepping over non-user code 'System.Array.IndexOf' Step into: Stepping over non-user code 'System.Collections.ArrayList.Remove' Step into: Stepping over non-user code 'System.Collections.ArrayList.Remove' Step into: Stepping over non-user code 'System.IO.FileSystemManager.RemoveFromOpenList' Step into: Stepping over non-user code 'System.IO.FileStream.Dispose' Step into: Stepping over non-user code 'System.IO.Stream.Close' Step into: Stepping over non-user code 'System.IO.Stream.Close' Step into: Stepping over non-user code 'System.IO.StreamReader.Dispose' Step into: Stepping over non-user code 'System.IO.TextReader.Dispose' Step into: Stepping over non-user code 'System.IO.TextReader.Dispose' Step into: Stepping over non-user code 'System.IO.Stream.Dispose' Step into: Stepping over non-user code 'System.IO.Stream.Close' Step into: Stepping over non-user code 'System.IO.FileStream.Dispose' Step into: Stepping over non-user code 'System.IO.Stream.Close' Step into: Stepping over non-user code 'System.IO.Stream.Close' Step into: Stepping over non-user code 'System.IO.Stream.Dispose' Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.ProjectData.SetProjectError'
#22841 4.2 VB.net String to double conversion
Posted by Bainesbunch on 16 January 2012 - 07:51 PM in Netduino Plus 2 (and Netduino Plus 1)
CDbl works for me in MF 4.2 RC1
Imports Microsoft.SPOT Imports Microsoft.SPOT.Hardware Imports SecretLabs.NETMF.Hardware Imports SecretLabs.NETMF.Hardware.NetduinoPlus Module Module1 Sub Main() Dim ErectParkDecerlationPoint As Double = CDbl("10.000") Debug.Print("ErectParkDecerlationPoint = " & ErectParkDecerlationPoint.ToString) '--> ErectParkDecerlationPoint = 10 Dim a As Double = CDbl("12345.6789") Debug.Print("a = " & a.ToString) 'a = 12345.678900000001 Dim b As Double = CDbl("166511.001e9") Debug.Print("b = " & b.ToString) 'b = 166511.00099999999 End Sub End ModuleI have not experienced many of the problems reported for RC3 using RC1. It might be worthwhile to revert back until these problems are solved.
Baxter
OK so where do I get 4.2 RC1 from for the plus for me to try this out please
A link would be good if you have one.
Cheers Pete
#25903 Seedstudio Keypad Module
Posted by Bainesbunch on 23 March 2012 - 06:04 PM in Netduino 2 (and Netduino 1)
#25859 Seedstudio Keypad Module
Posted by Bainesbunch on 22 March 2012 - 05:36 PM in Netduino 2 (and Netduino 1)
Aha! Ok will I will try that.
do you have a pinout for this keyboard ?
#25852 Seedstudio Keypad Module
Posted by Bainesbunch on 22 March 2012 - 04:16 PM in Netduino 2 (and Netduino 1)
If you look at the Arduino code that is on the webpage for this keypad it looks like a basic 3x3 multiplexed matrix
void setup() { Serial.begin(9600); for(i=0;i<3;i++) pinMode((KeyOPin + i), OUTPUT); for (i=0;i<3;i++) pinMode(( KeyIPin + i), INPUT); } void loop() { scankey(); if (press) { press=0; Serial.print("Keycode is "); Serial.println(oldkey,HEX); } } void scankey() { reg = 1; for (i=0;i<3;i++) { for (n=0;n<3;n++) { if((reg>>n)&1) digitalWrite(KeyOPin+n , HIGH); else digitalWrite(KeyOPin+n , LOW); } for (n=0;n<3;n++) { if(digitalRead(KeyIPin + n)) { key = key | (1<<(4+n)); key = key | reg ; } } reg = reg << 1; } if (key & 0xf8) { if (key!=oldkey) { press = 1; oldkey = key ; } } else oldkey = 0; key = 0; }
it is an easy task to translate this code from the Arduino C++ Variant to C# or VB
It would be useful to know the pin outs on the IDC connector they have attached to the board so you know which pins connect to the 3 ports that are outputs and which should be connected to the inputs.
If you are having problem drop me a PM or ask further here and I can do the translation for you. But it is best to try yourself first.
Cheers Pete.
#23967 Multiple i2C Devices with VB
Posted by Bainesbunch on 08 February 2012 - 01:48 PM in Visual Basic Support
#25817 Bluetooth Communication
Posted by Bainesbunch on 21 March 2012 - 08:40 PM in Netduino Plus 2 (and Netduino Plus 1)
I am using a BT serial adapter connected to my Netduino and talking to my PC through a BT dongle.
Pairing was my first issue. Once i hade the BT to serial paired with my PC then I simply connected the TX and RX lines of the BT to Serial together to make a loopback. I then used a terminal emulator program (http://www.compuphas...are_termite.htm) on my PC to send characters through the serial BT to see if they were echoed back.
Once this was working I then set about writing the code to receive the data on the Netduino and echo it back.
It all worked as expected once I had gone through these steps. One gotchya however it the TX/RX they seem to differ from one manufacturer to another. So it might be worth switching them around if you are not receiving any data at the Netduino end.
Sometimes it is good to set some debug.prints to show what is coming in on the port.
I did notice however that you are trying to read 32 bytes into a buffer. The read will not return until it has read 32 bytes or timed out. Try setting the buffer length to 1 byte. This will echo every byte one at a time and not wait for the buffer of 32 bytes to be read.
Hope this helps ... and good luck.
Cheers Pete.
#28274 Industrial Use Case
Posted by Bainesbunch on 28 April 2012 - 06:58 PM in General Discussion
Thanks for sharing your experience Pete. Impressive use of the Netdruino. Just shows what's possible. Without giving away any details (as I understand your situation) did you have to customize the Netdruino to get the level of reliability up. A simple yes or no would suffice! Thanks
Yes. I basicly built it onto another PCB that took care of the nasty stuff that the outside world can though at it
Pete.
#28035 Industrial Use Case
Posted by Bainesbunch on 24 April 2012 - 05:20 PM in General Discussion
#23027 How to control 220V stuff
Posted by Bainesbunch on 19 January 2012 - 10:57 PM in Netduino 2 (and Netduino 1)
- Netduino Forums
- → Bainesbunch's Content
- Privacy Policy