

![]() |
  | |||||||||||||
![]() |
|
![]() |
||||||||||||
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.
dab's ContentThere have been 54 items by dab (Search limited from 07-July 24) #4193 What is the Netduino Mini?
That is pretty cool. Small and cheap enough to install in a dedicated project
![]() ![]() #3178 How to use the SD card and StreamWriter
I'm getting exactly the same error as Szymon when I try to read a file from the SD card. I actually wrote my sample before I saw this thread, but my code is almost the same. ![]() Here's the sample code where I use a StreamReader object to get the first line of a text file: using System; using System.IO; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; namespace SDCardSample { public class Program { public static void Main() { string currentDir = Directory.GetCurrentDirectory(); Debug.Print("Current directory: " + currentDir); string[] dirs = Directory.GetDirectories(currentDir); foreach (string d in dirs) { Debug.Print("dir: " + d); string[] files = Directory.GetFiles(d); foreach (string f in files) { Debug.Print("file: " + f); StreamReader reader = new StreamReader(f); Debug.Print(reader.ReadLine()); reader.Close(); } } } } } And the exception that gets thrown: Current directory: \ dir: \SD file: \SD\FOO.TXT Failed allocation for 685 blocks, 8220 bytes Failed allocation for 685 blocks, 8220 bytes #### Exception System.OutOfMemoryException - CLR_E_OUT_OF_MEMORY (1) #### #### Message: #### System.IO.StreamReader::ReadLine [IP: 000a] #### #### SDCardSample.Program::Main [IP: 005e] #### A first chance exception of type 'System.OutOfMemoryException' occurred in System.IO.dll An unhandled exception of type 'System.OutOfMemoryException' occurred in System.IO.dll Note that this happens for both ANSI and UTF-8 encoded files (I created the files on the PC). #3261 How to use the SD card and StreamWriter
Cool - thanks for getting the new firmware out so quickly! This seems to fix the problem I was having with the StreamReader.ReadLine() method yesterday: Current directory: \ dir: \SD file: \SD\FOO.TXT The quick brown fox jumps over the lazy dog. Now I need to figure out what to do with 1.83 GB of storage. ![]() #3180 Introducing Netduino Plus -- Notes
I bought this one today, and it seems to work (well, I can read the directories and file names, but there seems to be a problem with reading file contents). SanDisk Mobile microSD Card 2GB $9.99 at Office Depot in the US. #1403 Soldering Temperature for IC's, etc...
I'd say it also depends a lot on the type of solder you're using.
I learned to solder back when Pb/Sn solder wasn't considered hazardous
![]() ![]() #145 Unboxing: first impressions?
I just received mine this weekend from the Maker Shed. I'm not sure exactly when it arrived, since I was out of town this weekend, but it was waiting patiently for me in the mailbox when I got home Sunday evening. ![]() Around 9:00 PM I finally got a chance to open the box. I had ordered another item from Maker Shed, and at first I thought the Netduino had been back-ordered. After looking closer, I saw its little black anti-static bag with the blue label. It's a little smaller than I expected (exact same footprint as Evil Mad Science's Diavolino board). I also found the little rubber feet and the tag, but I don't have a phone that will read it ![]() I got VS2010 Express installed on my machine, then the .NETMF, and finally the Netduino package. I jumped right into the blinkenlight tutorial, and plugged in the Netduino. FWIW, mine didn't come with the micro-USB cable, but I have plenty from other devices, so it wasn't a show stopper for me. At first, Win7 didn't install the driver - then I closed VS2010, unplugged and re-connected the Netduino, and the drivers installed fine. Then I deployed the project to the board, and basked in the glow of the blinking blue light ![]() I must say, it's a better OOBE than my recent foray into the Arduino world (about a month ago). Arduino is cool and all, and I'm sure in many ways it made the Netduino possible. But the Arduino tools feel hacked together, and I've spent way more time futzing around with the tools than actually working on hardware. This is what Arduino should have been, IMO. Leveraging Visual Studio, .NET MF, and C# was an inspired choice. It puts professional-quality development tools in the hands of hobbyists and startups. This is very cool, and I can't wait to spend more time playing with it. #343 ToggleButton sample
I haven't tried the Glitch filter yet, thanks for the suggestion. Do you happen to know what the default glitch filter time is (or what value is appropriate to debounce a pushbutton)? #365 ToggleButton sample
Cool, thanks! I've been meaning to try out your emulator. So many projects, so little time... ![]() #339 ToggleButton sample
OK, here's my ToggleButton sample from the other thread "Using InterruptPorts".
This is basically like the Event Handlers tutorial on the Projects page. The main difference is that the pushbutton acts like a toggle - push once to turn off the LED, then push again to turn it back on. Another slight modification - the interrupt handler method calls DisableInterrupt() at the start of the method, and EnableInterrupt() at the end. This seems to fix an issue where pressing and holding the button would sometimes cause the LED to change state when the button was released. I think this might be due to switch bounce, so multiple interrupts were getting "stacked up" and handled after the first interrupt method returned. Anyway, here's the code. Let me know if there's interest in posting the entire VS solution. Enjoy! using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; namespace ToggleButton { public class Program { static bool ledState; static InterruptPort button; static OutputPort led; public static void Main() { // Set the initial state of the LED to on (true). ledState = true; led = new OutputPort(Pins.ONBOARD_LED, ledState); button = new InterruptPort( Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow); // Bind the interrupt handler to the pin's interrupt event. button.OnInterrupt += new NativeEventHandler(SwitchInterruptHandler); while (true) { Thread.Sleep(Timeout.Infinite); } } public static void SwitchInterruptHandler(UInt32 data1, UInt32 data2, DateTime time) { button.DisableInterrupt(); // Invert the previous state of the LED. ledState = !ledState; // Set the LED to its new state. led.Write(ledState); // Un-comment the following line if using level interrupts. // button.ClearInterrupt(); button.EnableInterrupt(); } } } #3209 Console Output??
And you need to have the debugger attached. In VS2010, go to Debug | Start Debugging, which will run the solution in the debugger. If the debugger isn't attached, the Debug.Print() statements will have no effect. #3237 Console Output??
Oh, cool - I didn't know that. Thanks for the tip! #2653 Stay close to your computer (or come to MakerFaire)...
Removing the rest of the evidence
![]() #3131 Stay close to your computer (or come to MakerFaire)...
As a member of the community, I'd be interested in the project to expand the microSD capacity... #2643 Stay close to your computer (or come to MakerFaire)...
Flying rugs are so old world. I vote for flying cars ![]() #3184 Stay close to your computer (or come to MakerFaire)...
Sure. Uuhm, depends on what you mean by "team". ![]() #2642 Stay close to your computer (or come to MakerFaire)...
Sorry, I'm voluntarily deleting my previous remark, since it was somewhat inappropriate. I don't mean to detract from the Secret Labs announcement.
#597 PwmSample
Hi CW2, Thanks for the suggestion - I think that would be a good follow-on sample. For the time being, I just wanted to create something equivalent to the Arduino "Fading" sample, but showcase some of the Netduino / NETMF features (like timer callbacks, and a "real" Sleep() function). The Arduino sample also just folows a linear PWM ramp, which as you mention, doesn't correspond to a linear brightness at the LED ![]() A more advanced exercise might use a lookup table to compensate for the non-linear response of the LED. BTW, does anybody happen to know what the response curve of a typical LED looks like? I'm curious if it's a logarithmic function (like audio), or if it's something completely different. #563 PwmSample
Hi Netduino fans,
Here's a little sample that uses a PWM pin to control the brightness of an LED. I like to call it PwmSample, for lack of a better name. ![]() What it does: When you press and hold the pushbutton, a connected LED will gradually brighten and dim. If you release the pushbutton, the LED stays at its current brightness. Pushing the button again will resume the brighten/dim cycle from the current value. How it works: This sample combines several techniques from the previous samples. It uses an InterruptPort for the pushbutton input; the SwitchInterruptHandler() method is called when the InterruptPort detects a rising or falling edge due to the pushbutton. The sample also uses a Timer callback to do the actual LED brightness control. Every 20 milliseconds, the PwmTimerCallback() method is called. This method checks whether the pushbutton is closed (the buttonState variable). If so, then it increments (or decrements) the PWM pin's duty cycle. Circuit: Note that you'll need to connect an external LED to the Netduino board (it won't work with the built-in LED, since it's not connected to a PWM-enabled pin). I used Digital Pin 5 in the sample; you can use any PWM-enabled pin (5, 6, 9, or 10), but make sure to change the Pin definition on line 34. I don't have a schematic editor handy, but the circuit is simple enough. Just connect one end of a 100-ohm resistor to Digital Pin 5. Connect the other end of the resistor to the anode (+) lead of your LED. Then connect the cathode (-) lead of the LED to one of the GND pins on the Netduino Power header. Here's the code: using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; namespace PwmSample { public class Program { const int pwmPeriod = 20; const uint MaxDutyCyle = 100; static bool buttonState; static int pwmDutyCycle; static int pwmIncrement; static InterruptPort button; static PWM led; public static void Main() { pwmDutyCycle = 0; pwmIncrement = 1; buttonState = false; // NOTE: You will need to connect an LED to Digital Pin 5 on the Netduino board. // Use a 100-ohm (brown-black-brown) resistor between the LED anode (+) and Digital Pin 5. // Connect the LED cathode (-) to one of the GND pins on the Power header. // // You can use any other PWM-enabled pin (5, 6, 9 or 10), but also remember to change // the Pin parameter in the PWM constructor below. led = new PWM(Pins.GPIO_PIN_D5); button = new InterruptPort( Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth); // Bind the interrupt handler to the pin's interrupt event. button.OnInterrupt += new NativeEventHandler(SwitchInterruptHandler); // Create a System.Threading.Timer instance and pass it the timer callback method. Timer pwmTimer = new Timer( new TimerCallback(PwmTimerCallback), null, pwmPeriod, pwmPeriod); Thread.Sleep(Timeout.Infinite); } public static void PwmTimerCallback(Object obj) { // Only change the LED brightness when the button is pushed (true). if (true == buttonState) { // Set the pin's new duty cycle. pwmDutyCycle += pwmIncrement; led.SetDutyCycle((uint)pwmDutyCycle); Debug.Print(pwmDutyCycle.ToString()); if ((MaxDutyCyle == pwmDutyCycle) || (0 == pwmDutyCycle)) { // The duty cycle has hit the min or max value. // Start ramping in the other direction. pwmIncrement = -pwmIncrement; } } } public static void SwitchInterruptHandler(UInt32 data1, UInt32 data2, DateTime time) { button.DisableInterrupt(); buttonState = (0 == data2); button.EnableInterrupt(); } } } #2601 PwmSample
Hi FastEddy, Thanks for the kind words - I'm glad you find the sample code helpful ![]() You raise a good point about getting up to speed on the technology. I consider myself pretty much a newbie to C# and the .NET framework (until relatively recently, I was a C++/Win32 API kind of guy). For me, the biggest challenge is the .NET framework itself. It's huge (even .NETMF), and a lot of classes aren't very discoverable. I always find myself thinking "I know there's a class/method to do 'x', but where?". Here are some things I've found helpful:
I hope that helps get you started. #598 PwmSample
Thanks, Chris. To give credit where it's due, I TBH, I couldn't find much in the way of documentation of how data1 and data2 are used in the callback. The .NETMF documentation mentions that data1 is the port, and data2 is the state, but "state" in this context was a little unclear. Apparently it refers to the logic state of the pin that generated the interrupt, but having that documented explicitly might be a good thing ![]() #733 PwmSample
I did a little research to answer my own question. ![]() It appears that LEDs have a gamma relationship between the voltage and perceived brightness. I found this application note that explains it nicely: http://www.maxim-ic....dex.mvp/id/3667 So, I've posted an updated version of the PwmSample (under the "PwmGamma" topic in this forum) that uses a LUT (lookup table) to implement the gamma correction. The PwmGamma sample ramps the LED brightness in a way that looks more linear (still not perfect, but much better than before). #442 Request: New Forum
Sounds good! #309 Request: New Forum
+1 to this suggestion. I think a place to share code and examples would be a good idea. #64 Arduino wifi sheilds.
Thanks, Chris, I'll take a look at the mftoolkit.
Worst case, I suppose it probably wouldn't be too difficult to port an existing Arduino XBee library (although I haven't seen the source code).
Thanks!
#58 Arduino wifi sheilds.
Hi folks,
I'm also very excited about the Netduino and the .NET goodness that it brings to the AVR microcontrollers ![]() Along the same lines as nirav's question - is there (or will there be) support for the XBee wireless Arduino shields? For example: http://www.sparkfun....roducts_id=8664 Thanks, and I can't wait until my Netduino board arrives!
| ||||||||||||||
![]() |
||||||||||||||
![]() |
|
![]() |
||||||||||||
![]() |
This webpage is licensed under a Creative Commons Attribution-ShareAlike License. | ![]() |
||||||||||||
![]() |