AxelG's Content - Netduino Forums - Page 2
   
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.

AxelG's Content

There have been 52 items by AxelG (Search limited from 28-April 23)


By content type

See this member's


Sort by                Order  

#43999 Multithreading and writing to SD card

Posted by AxelG on 23 January 2013 - 06:40 AM in Netduino Plus 2 (and Netduino Plus 1)

Thanks for this reply. Could you explain what is meant by a "locking scheme"?

Sure:

In my code I open the Filestream once and keep it open.  It would be a bad thing if multiple threads interacted with the the stream at "the same time".  I therefore create an object to lock it (private object LockMe = new object();) and any time I am reading or writing to the filestream I make sure the code holds a lock on this object (lock(LockMe) { //Code here } )

 

This way, you can ensure only one thread is interacting with the filestream at any given time.  Just make sure the scope of LockMe is shared between all threads.

 

I hope this helps.  You can google "C# lock()"  for more reference.




#33219 multi threaded webserver

Posted by AxelG on 07 August 2012 - 01:29 PM in Netduino Plus 2 (and Netduino Plus 1)



I've attached the project. Any help much appreciated.


My ND+ is in use, so I could not run this code. Reading it, I suspect this {below} part of the code might be causing your trouble. From what I can gather in reading the source, this code gets called once to start flashing, and then again to stop flashing. That will create two threads for blinky: once when it gets the "on" command, and then creates a new thread when it gets the "off" command. I suspect that the "off" command does kill the thread started by the "off" command, but the "on" command thread is still running. If you look at the debugger output, you can see when the threads terminate to verify; compare that to when new threads start.

Look for something like the following: "The thread '<No Name>' (0x14) has exited with code 0 (0x0)." in your debug output.

One way to deal with this is to use managed threads and then you can tell which threads are running. {great way to learn about thread pools!} An alternative is to store the state of blinky in a static variable in main() so you can do two things: 1) make sure two "on" commands are not called without first calling an "off", 2) verify blinky is running before you try and kill it. (This will also require that blinkyobject be declared as static in main() as well so you can kill in one thread what was started in another)

[Disclaimer: There will be various opinions as to the best solution; I am just suggesting a couple that come to mind at the moment :) ]

Happy blinking! I hope this blurb helps get this solved for you.

               case "flashled":
                    {
                        
                        bool state = (e.Command.Arguments[0].Equals("on") ? true : false);
                        {
                            blinky blinkyobject = new blinky();
                            Thread blinkythread = new Thread(blinkyobject.blinkygo);

                            if (state == true)
                            {
                                Debug.Print("blinky start");
                                blinkythread.Start();
                                e.ReturnString = "<html><body>You called FlashLed with argument: " + e.Command.Arguments[0].ToString() + "</body></hmtl>";

                            }
                            if (state == false)
                            {
                                //Debug.Print("blinky stop");
                                blinkyobject.RequestStop();
                                Thread.Sleep(500);
                                blinkythread.Join();
                                Debug.Print("main thread: Worker thread has terminated.");
                                e.ReturnString = "<html><body>You called FlashLed with argument: " + e.Command.Arguments[0].ToString() + "</body></hmtl>";
                            }
                        }




#33169 multi threaded webserver

Posted by AxelG on 06 August 2012 - 03:09 PM in Netduino Plus 2 (and Netduino Plus 1)

... So I did. But when I run blinkythread.abort

it throws an exception. Maybe I'm going about it all the wrong way. What I'm hoping to achieve is to be able to send a get

request through a browser like http://ipaddress/setbath/36 .



Hi Grant:
Maybe instead of just aborting the thread you could signal the Blinky thread to shutdown more gracefully. One way is to set up a simple event and trigger that event from your main code. This way the Blinky thread will close and perform any cleanup. You could put a timeout waiting for that thread to end before forcing the abort. Also, make sure the thread is still alive before calling the abort.

This tutorial may be helpful: Events
And this one on threading: Threading

Both of these helped me understand .NET threads and events.



#33919 Love for Chris Walker

Posted by AxelG on 19 August 2012 - 09:29 PM in General Discussion

Hear, Hear...



#46332 Is there a Watchdog breakout out there?

Posted by AxelG on 27 February 2013 - 01:13 PM in Netduino Plus 2 (and Netduino Plus 1)

Yes, but the timer thread can be set up to check for certain conditions being managed by your other thread(s).  Take for example the checking of the LastPing value that the watchdog performs in my basic example.  If that value is not updated regularly by some other process, the watchdog class assumes something is wrong and reboots.  You can get way more creative with inter-thread communications to make sure all the other threads are doing what they are supposed to; and when they are not; force a reboot.

 

There is nothing that says only the timer can update the watchdog either.  You can also just have your main thread (or any thread for that matter) call the StartWatchdog method on a regular basis instead of a timer.  Just make sure you implement proper locking mechanism to ensure thread-safe operations.

 

I have used this in a situation where I need to keep a persistent connection open on the network.  If some condition prevents me from reconnecting, I can change the networking parameters and force a reboot to reconnect to try and resolve.  It is nice to have the ability to reboot your ND on demand!




#46266 Is there a Watchdog breakout out there?

Posted by AxelG on 26 February 2013 - 06:39 PM in Netduino Plus 2 (and Netduino Plus 1)

I have developed a prototype based on the MAX6373 chip.  I wrote a simple software driver (using timers in c#) that uses one GPIO to reset the hardware watchdog periodically.  If it misses a reset, the watchdog will perform a hardware reset on the ND/ND+ (or any other MCU)

 

The board was designed to have the watchdog timeout be selected by jumpers and expose all eight pins on the MAX to your breadboard.  All it needs is power, access to RESET, and one GPIO.

 

I will post the eagle layout and drivers once it is fully tested.  The board just came in from BatchPCB and will solder it this week.




#46288 Is there a Watchdog breakout out there?

Posted by AxelG on 27 February 2013 - 02:51 AM in Netduino Plus 2 (and Netduino Plus 1)

Well, I had some time tonight and soldered and tested the MAX6373 board I made based on this chip:

 

After wiring up the board, I realized I forgot the pullup resistor on the /RESET line, so I created a version 1.1 board that includes one on the board without having to wire one on the breadboard.  (Eagle files available)

 

Attached is the version 1.1 schematic, R4 is new.

 

I have a few spare version 1.0 boards if anybody is interested.  I can also solder a MAX 6373 if you want.  PM me.

 

 

WatchDogSch.JPG

 

Attached File  MAX6373WatchDog.zip   1.34KB   47 downloads

 

2013-02-26_22-08-57_159.jpg




#29505 First chance Socket Exception on socket.Accept()

Posted by AxelG on 22 May 2012 - 02:35 AM in Netduino Plus 2 (and Netduino Plus 1)



Sometimes, Socket.Accept will throw an Exception. It's only sometimes, and it's immediately after the program starts.

I do have a busy loop in to wait for an IP to be assigned, but otherwise I can't figure out what going on here. Ideas?



Chris:
The only way I can get Sockets to work is to catch the 10053 exception, sleep for 100ms and immediately try again. Sometimes it works on second or third try; sometimes more. I am not sure you are getting the same error code; can you post the debug?



#33882 Diagnosing slow deployment with VMware using WinUSB

Posted by AxelG on 18 August 2012 - 11:20 PM in General Discussion

I use Windows 7 Ultimate hosted on a local VM through VMWare Player as my dev environment and had the same issue until I re-flashed my Netduino BIOS. There was an issue with the earlier version of SAM-BA 2.11 that had a problem with slow deployments that may be related to this. Using the new 2.12 version of SAM-BA and flashing the latest 4.2 firmware solved the problem for me. (I do, however, still get BSOD if I hit the reset button on the ND during deployment)



#33885 Diagnosing slow deployment with VMware using WinUSB

Posted by AxelG on 19 August 2012 - 04:28 AM in General Discussion

The BSOD is in the VM. My host is fine. The Service reads "WinUsb" and the Hardware ID is "USB\VID_22B1&PID_1001&REV_0100"



#29351 DHCP issues with Netduino Plus

Posted by AxelG on 17 May 2012 - 10:06 PM in Beta Firmware and Drivers

Hoping to keep the discussion moving on the socket-related questions. I am new to the Netduino Plus with about 2 weeks under my belt of playing with it. A lot of my time is spent in .NET Visual Studio Emulator mode and moving to the hardware when I need to work on the hardware integration parts. I have noticed a few quirks with various differences between emulator and hardware deployed versions; this socket problem is one I am playing with and have not found a reliable workaround; yet. I reset all of my networking settings to static IP through MFDeploy.exe, and make my router aware of the NDP MAC address and reserved IP address; until I get a successful network ping on that static IP address. This sometimes takes a couple router resets to get right so Netduino responds to a ping. I am running a "tried-and-true" windows socket service on port 8484 on a completely different server. It is a basic service listening on port 8484 for a simple "HELLO" to come across the Tcp socket. The following snippet of a program works fine in emulator mode and I can connect 100% of the time. When I deploy to the hardware; no good. It sometimes connects, and generally stays connected; but when it fails to connect - forget it. It just keeps timing out. (this code is in a loop that keeps trying to connect until it does in the "real" software) I am including code and the associated debug output. Any insight on what I can try next would be helpful. Oh, I flashed to 4.1.1 from 4.1.0.6 and fixed my SD card issues; but seemed to make this issue worse (but I may have just been tired and hopped up on Coke Zero...) I have not tried 4.2 yet. -->(snip)<-- public class Program { public static void Main() { int port = 8484; string server = "192.168.5.102"; ShowNetworks(); try { Debug.Print("Defininig new socket "); Socket serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); Debug.Print("Defininig new static endpoint and connecting to "+ server + "on port " + port.ToString()); IPHostEntry hostEntry = Dns.GetHostEntry(server); serverSocket.Connect(new IPEndPoint(hostEntry.AddressList[0], port)); Debug.Print("Sending a HELLO statemnt to the waiting service"); Byte[] bytesToSend = Encoding.UTF8.GetBytes("HELLO\n" + "12345678910\n"); serverSocket.Send(bytesToSend, bytesToSend.Length, 0); } catch (SocketException se) { Debug.Print("SocketException when connecting to " + server + "."); Debug.Print("Socket Error Code: " + se.ErrorCode.ToString()); Debug.Print(se.ToString()); } } private static void ShowNetworks() { NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in adapters) { int i = 0; foreach (string s in adapter.DnsAddresses) { i++; Debug.Print("DNS Address : " + s); } if (i == 0) Debug.Print("No DNS Address"); Debug.Print("Default Gateway: " + adapter.GatewayAddress); Debug.Print("IP Address : " + adapter.IPAddress); Debug.Print("Is DHCP Enabled: " + adapter.IsDhcpEnabled); Debug.Print("Is Dynamic DNS : " + adapter.IsDynamicDnsEnabled); Debug.Print("Interface Type : " + adapter.NetworkInterfaceType.ToString()); Debug.Print("MAC Address : " + ToHexString(adapter.PhysicalAddress)); Debug.Print("SubnetMask : " + adapter.SubnetMask + "\n"); } } } -->(Debug Output)<-- No DNS Address Default Gateway: 192.168.5.1 IP Address : 192.168.5.50 Is DHCP Enabled: False Is Dynamic DNS : False Interface Type : 6 MAC Address : 5C-86-4A-00-4F-1D SubnetMask : 255.255.255.0 Defininig new socket Defininig new static endpoint and connecting to 192.168.5.102on port 8484 #### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) #### #### Message: #### Microsoft.SPOT.Net.SocketNative::connect [IP: 0000] #### #### System.Net.Sockets.Socket::Connect [IP: 001d] #### #### NetduinoPlusApplication1.Program::Main [IP: 0044] #### #### SocketException ErrorCode = 10053 #### SocketException ErrorCode = 10053 A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll #### SocketException ErrorCode = 10053 #### SocketException ErrorCode = 10053 SocketException when connecting to 192.168.5.102. Socket Error Code: 10053 System.Net.Sockets.SocketException The thread '<No Name>' (0x1) has exited with code 0 (0x0). Done. Waiting for debug commands... The program '[3] Micro Framework application: Managed' has exited with code 0 (0x0).



#33383 Debugging Assemblies loaded via Reflection

Posted by AxelG on 10 August 2012 - 06:24 PM in General Discussion

You have 2 projects and the ND startup is 'referencing' your library?

Yes, one project is what you have today (Production) and one new one (debug) that just references the library as a standard .dll

Your deployment grabs the library project and loads it to the flash chip? How are you referencing the library at this point? Standard reference or reflection?


Standard reference, just like any other .dll you include. Yes, at deploy time the .dll will be sent to the flash at the same time as your exe because it is just another .dll.

(At the risk of confusing the issue: an alternative approach might be..)
To make it easier to code, another alternative is to add a "library" subdirectory in this new (call it debug) project and add your library source as links into this subdirectory. That way the compiler knows to recompile the changed "library" code along with your program on any changes at build time. This way you are not dealing with two projects (one to build the dll and one to build your debug program) The downside is that you have to manage "who is calling who" to make sure you don't break your dll by referencing something that will become out of scope in your production build.

What exactly are you doing here differently in your calling startup assembly?

Nothing different. I am sure you are doing this now. I just load the assembly and call the starting method.



#33378 Debugging Assemblies loaded via Reflection

Posted by AxelG on 10 August 2012 - 04:17 PM in General Discussion

I may not understand the question, but I have done this in the past to help debug: I create a simple program that includes the .dll as a library. I then flash this to the ND as a single program (no loading assemblies from sd) I do all of my debugging there as normal. When I am ready to deploy in Production, I just deploy the obj/Release/le/*.pe (Associated to my .dll) to SD and load my "bootloader" program through regular deployment. There is about 3k to 4k of overhead for doing it this way (including a .dll with your main program) until you load your final assembly. Maybe?



#33402 Camera Modules for any Netduino

Posted by AxelG on 11 August 2012 - 05:35 AM in Netduino Plus 2 (and Netduino Plus 1)

I have NGO and no SD card yet

Maybe you could update the driver to send data out a serial port to some receiving system as it is read from the camera. You could get fancy and maybe perform a post to a waiting web server; assuming you have an Ethernet or wifi shield.



#33180 Camera Modules for any Netduino

Posted by AxelG on 06 August 2012 - 09:38 PM in Netduino Plus 2 (and Netduino Plus 1)

Posted Image Ok! Thank


I can confirm that these drivers work very well. Easy to use and bug free (so far ;) ) I trimmed them up a bit as I did not need all of the features written in the driver. Took me about a hour to get everything hooked up and running.

You must also have a ND with a SD card to use the drivers. That means either a ND+ or ND flashed to 4.2 and a SD shield of some kind. If you use the latter, you will have to add the mount and unmount commands to the driver.

Hope you enjoy; I know I did! :)



#47355 Building my own custom Netduino Plus 2 hardware

Posted by AxelG on 18 March 2013 - 09:56 PM in Netduino Plus 2 (and Netduino Plus 1)

Dave:

Thanks for the reply.  We did, and actually still are considering that option. Longer term we want to use the larger 100 pin STM chip to take advantage of extra IO.

 

We also wanted the first generation to tap into SPI3 for the onboard SD card: but I can always mount the SD on SPI1 with ND2.

 

One factor is having a real-time CAN bus capturing OBD data.  Still have not decided on the best approach; but it would be nice not having to add a lot of hardware to do that.

 

Cost is not the only factor; total size is also a design factor, which is why we jettisoned the Ethernet.  There are several add-on devices needed to fit into a total footprint < 3" X 3"

 

As always, thanks for the insight!




#47342 Building my own custom Netduino Plus 2 hardware

Posted by AxelG on 18 March 2013 - 07:01 PM in Netduino Plus 2 (and Netduino Plus 1)

I have been asked to help with a project to build a device based on the Netduino framework and the STM32F405 family of processors.

 

We expect to use the same processor as the Plus 2, but leave off the ethernet hardware (we need the flash, not the ethernet)  There is also a possibility of going to a larger package in the future to expose more peripherals; like a CAN bus.

 

I have two questions for anyone with experience building their own device.

 

1) For the first revision I would like to avoid having to recompile the ND firmware and just flash the current build to the new device.  Is there any problem flashing the ND 4.2 build on a chip that has not implemented the ethernet hardware?

 

2) I would like to get a second set of eyes on the schematics before I build a prototype board. Is there someone interested in reading the schematic to catch my mistakes?




#47373 Building my own custom Netduino Plus 2 hardware

Posted by AxelG on 19 March 2013 - 07:07 AM in Netduino Plus 2 (and Netduino Plus 1)

lol, doing the same with my 2012 Hemi Charger....




#33874 Announcing: .NET MF 4.2 upgrade for all Netduino hardware

Posted by AxelG on 18 August 2012 - 04:55 PM in General Discussion

Great News! I was able up update my ND/ND+ and everything went really well! Easy.... Thanks for the updates!



#44466 Adafruit LCD MCP23017 IC

Posted by AxelG on 29 January 2013 - 01:44 AM in Netduino Plus 2 (and Netduino Plus 1)

Can you post a schematic?

 

I2C is sensitive to the pullup resistor values used on the SDA SCL wires.




#42831 4X20 LCD display with I2C Interface

Posted by AxelG on 05 January 2013 - 10:23 PM in Project Showcase

I attached the driver code to the first post.




#42743 4X20 LCD display with I2C Interface

Posted by AxelG on 04 January 2013 - 11:06 PM in Project Showcase

I updated my code to call the reset() method every time I need to clear the LCD, and that has worked all day today with 1,000+ screen updates an no garbage.  Seems like bruit-force approach but is seems to be working for now.

 

I also posed the driver code if anyone is interested.




#42926 4X20 LCD display with I2C Interface

Posted by AxelG on 07 January 2013 - 06:48 PM in Project Showcase

I have these working just fine on a N+2:

 

Here is a video of it working on my BoxCar:

 

http://sdrv.ms/UwMKxE

 

LMK if you want a code sample.

 

I would love to see the code samples!




#42733 4X20 LCD display with I2C Interface

Posted by AxelG on 04 January 2013 - 07:44 PM in Project Showcase

Thanks for the quick replies.

 

I wrote a reset() method in the driver, and I have attached it to the onboard switch.  Hitting the switch resets the screen.  Seems like there should be a better way...

 

Maybe I will remove the i2c interface and go to a native HD4478 8 bit driver...




#42715 4X20 LCD display with I2C Interface

Posted by AxelG on 04 January 2013 - 02:58 PM in Project Showcase

My holiday present to myself this year was the following 4X20 LCD: (link)

 

It is based on the HD4478 LCD driver chip, front ended with an I2C interface, popular because it only uses two ports on your MCU.

 

The information provided by the vendor is sparse, and in some cases incorrect.  The address of the device is listed as 0X27 but is actually 0x3F.  I was able to locate the Arduino (C++) driver for the I2C interfaced version, so I translated the Arduino driver into C#.

 

I then integrated Stefan Thoolen’s (http://www.netmftoolbox.com/) MultiI2C class to drive the I2C port.

 

After playing with the timing on the initialization a bit, it seems to be working well.  I added some text management methods to the driver to simplify displaying text on four lines.  The LCD is set up in such a way that it is actually driving two 40 character lines of text, wrapped on the screen.  This made it confusing for me to keep straight, so these new methods made it easier to keep track of the text.

 

Hardware connection is a snap.  Netduino (running 4.2) connected with 5v, ground, A4, and A5 to the LCD module.  This LCD is using an I2C interface, so you need pullups on the A5 and A4 wires.  I used 2.2k (corrected to 1.8k below) resistors on the 3V3 port.  Worked great.

 

One nagging issue is that after running for some time, the screen will start displaying garbled data.  I have not been able to pinpoint the reason; maybe bus speed, bad data wires, poor power?  If I figure that out, I will post an update.***

 

Thanks to everyone on the forum for inspiration and ideas to get this working; especially Stefan for a great toolbox.  Let me know what bugs you find or ideas on improvements.

 

***UPDATE: The garbage issue is resolved: I think.

Problem was that my pullup resistors were too high of a value (changed for 1k8.  I remembered my analog circuit class I took 30 years ago and realized these resistors are part of a RC circuit that affect the signal shape on the wire.  To high = smaller slope.  There was also a small bug in the code that was not sending the initialization bytes correctly (I will upload the working copy.  I also moved some of the text management methods out of this class into a separate display class)

Attached Files





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.