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.

dab's Content

There have been 54 items by dab (Search limited from 06-June 23)


By content type

See this member's


Sort by                Order  

#598 PwmSample

Posted by dab on 16 August 2010 - 04:20 PM in Project Showcase

Nice usage of interrupt handler parameter (data2) to get the pin/button state.

Thanks, Chris. To give credit where it's due, I plagiarized copied that from the Event Handlers tutorial.

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 ;)



#2601 PwmSample

Posted by dab on 22 September 2010 - 05:15 AM in Project Showcase

Oooooooooooooo... button-controlled fading. Pretty!

Now to get my head around the code and get it doing something useful.

dab, thanks for publishing useful example. How do you suggest I get a relevant basic command reference? I hate reading (and writing) documentation as much as the next guy but there are times when it really helps...

The community (including me ;) ) would probably benefit enormously from some pointers on how to research the command syntax.


Hi FastEddy,

Thanks for the kind words - I'm glad you find the sample code helpful B).

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:

  • Sample code. Find something here in the Project showcase that looks interesting to you, get the source code, and play with it. Look up the classes / methods that you're not familiar with. Try making small changes to the code and see what happens. Don't be afraid to experiment.
  • Online documentation. Currently, the best available documentation is at the MSDN library site. But be aware that even that is sometimes wrong, or slightly out-of-date for the .NETMF libraries.
  • Books. There are a couple of books that I've found sort of useful. One is "Embedded Programming with the .NET Micro Framework", by Donald Thompson and Rob Miles. The other is "Expert .NET Micro Framework" by Jens Kuhner. Both of these are a bit dated, but have some useful sample code. There's also quite a bit of stuff in both books that I didn't find that useful, but they're worth reading for a couple of chapters (I'd recommend borrowing them if you can find a library that has them, or buy used copies).
  • Community. Right here is a good resource - it's a fairly small (but growing) community, and people I've seen are eager to share and swap advice and ideas. And the Secret Labs folks here are also super-helpful.

I hope that helps get you started.



#563 PwmSample

Posted by dab on 16 August 2010 - 07:12 AM in Project Showcase

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. B)

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();
        }

    }
}



#733 PwmSample

Posted by dab on 18 August 2010 - 08:36 AM in Project Showcase

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.


I did a little research to answer my own question. B)

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).



#597 PwmSample

Posted by dab on 16 August 2010 - 04:14 PM in Project Showcase

Just out of curiosity, do you plan to extend PWM control to compensate the LED brightness non-linearity?


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.



#807 PwmGamma Sample

Posted by dab on 18 August 2010 - 09:49 PM in Project Showcase

Nice! I'm glad I brought a Netduino with me on vacation so I can play with this :)

You mean you actually take vacation? :P



#734 PwmGamma Sample

Posted by dab on 18 August 2010 - 08:50 AM in Project Showcase

As a follow-up to the PwmSample, CW2 suggested extending it to address the non-linear response of the LED.

After a bit of research, I found that this is referred to as "gamma correction", and even found an application note that discusses using gamma correction with PWM:

http://www.maxim-ic....dex.mvp/id/3667

So, here's an update to PwmSample that uses a pre-computed LUT (lookup table) for the PWM output values. These are the gamma-corrected values (for gamma = 2.5) that produce a brightness ramp that looks linear (more or less) to our eye.

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 PwmGamma
{
    public class Program
    {
        const int pwmPeriod = 50;

        // Lookup table for the LED brightness.  The table contains the 
        // gamma-corrected values (for gamma = 2.5).  This approximates
        // a linear increase in the perceived brightness.
        static uint[] gammaTable = {
             0,  0,  0,  0,  1,  1,  1,  2,  2,   3,
             4,  5,  6,  7,  9, 10, 12, 14, 16,  18,
            20, 22, 25, 28, 31, 34, 37, 41, 45,  49,
            53, 57, 62, 67, 72, 77, 82, 88, 94, 100,
        };

        static bool buttonState;
        static int pwmIndex;
        static int pwmIncrement;
        static InterruptPort button;
        static PWM led;

        public static void Main()
        {
            pwmIndex = 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.
                led.SetDutyCycle(gammaTable[pwmIndex]);
                pwmIndex += pwmIncrement;

                Debug.Print(gammaTable[pwmIndex].ToString());

                if (((gammaTable.Length - 1) == pwmIndex) || (0 == pwmIndex))
                {
                    // 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();
        }

    }
}



#1400 Pwm2Color Sample

Posted by dab on 27 August 2010 - 05:40 AM in Project Showcase

Hi Netduino fans,

Here's a fun little project that builds on my previous PwmSample and PwmGamma programs.

The Pwm2Color sample controls a 2-color LED (or 2 individual LEDs, if you wish). It uses 2 pushbutton switches as input; one button controls the intensity of the Red LED, and the other button controls the Green LED.

The buttons gradually ramp the LED intensity up and back down, using Gamma correction to make the ramps more linear.

By using a 2-color LED (which is just 2 LED substrates in the same package), you can mix the red and green components in different proportions, creating intermediate shades of yellow and orange. B)

Please see the comments in the code for a description of the circuit. I'll try to post up a schematic later if there's interest.

I've made a few tweaks since the PwmGamma sample, and tried to streamline the code a bit:

  • The code now makes use of the InterruptPort's glitchFilter parameter, so please make sure you are running Netduino firmware 4.1.0.2 or later.
  • Since I'm now using the glitch filter, there's no need to disable and re-enable the interrupts in the interrupt callback method.
  • Note that the same interrupt callback is used to handle the interrupts from both buttons. The interrupt callback uses the data1 parameter to determine which button generated the interrupt.
  • The Channel class is used to encapsulate the PWM port (for the LED), the InterruptPort (for the corresponding pushbutton), and the state variables. This makes the code much simpler, since it can just iterate over Channel objects. It also makes it much easier to extend the sample to use a 3-color LED (literally a 2-line code change). ;)
Here's the code. Have fun!

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace Pwm2Color
{
    // The Channel class encapsulates the PWM port for an LED, the InterruptPort
    // for the corresponding pushbutton switch, and some state variables.
    public class Channel
    {
        public bool ButtonState { get; set; }
        public int PwmIndex { get; set; }
        public int PwmIncrement { get; set; }

        public PWM Led 
        {
            get { return _Led; }
        }
        private PWM _Led;

        public InterruptPort Button 
        {
            get { return _Button; }
        }
        private InterruptPort _Button;

        public Channel(Cpu.Pin LedPin, Cpu.Pin ButtonPin)
        {
            ButtonState = false;
            PwmIndex = 0;
            PwmIncrement = 1;
            _Led = new PWM(LedPin);
            _Button = new InterruptPort(
                ButtonPin,
                true,
                Port.ResistorMode.Disabled,
                Port.InterruptMode.InterruptEdgeBoth
            );
        }
    }


    public class Program
    {
        const int pwmPeriod = 50;
        const uint MaxDutyCyle = 100;

        // Lookup table for the LED brightness.  The table contains the 
        // gamma-corrected values (for gamma = 2.5).  This approximates
        // a linear increase in the perceived brightness.
        //
        // Declaring it as a byte array makes the assembly a little smaller,
        // and the byte values automatically get promoted to uint when
        // setting the PWM duty cycle.
        static byte[] gammaTable = {
             0,  0,  0,  0,  1,  1,  1,  2,  2,   3,
             4,  5,  6,  7,  9, 10, 12, 14, 16,  18,
            20, 22, 25, 28, 31, 34, 37, 41, 45,  49,
            53, 57, 62, 67, 72, 77, 82, 88, 94, 100,
        };

        static Channel[] channels;

        public static void Main()
        {
            // NOTE: You will need to connect 2 LEDs and an additional pushbutton switch 
            // to the Netduino board.  The circuit is as follows:
            //
            // 1. Connect a 100-ohm resistor between the anode of the Green LED and Digital Pin 5.
            // 2. Connect a 100-ohm resistor between the anode of the Red LED and Digital Pin 6.
            // 3. Connect the LED cathode(s) to GND on the Power header.
            // 4. Connect a 1K pull-up resistor between 3V3 on the Power header and Digital Pin 1.
            // 5. Connect one side of the SPST pushbutton switch to Digital Pin 1. (This switch 
            //    controls the Red LED).
            // 6. Connect the other side of the SPST pushbutton switch to GND on the Power header.
            //
            // I used a 2-color LED which has red and green LEDs in the same package.
            // Electrically, it's the same as 2 separate LEDs, so the circuit is virtually the same.
            // If you use a 2-color LED, be sure to get the common-cathode variety.
            // With a 2-color LED, you can "mix" the colors in varying proportions.
            // When both red and green are on, the resulting color is yellow or orange.
            //
            // It should be almost trivial to modify this program to handle a 3-color LED. ;)

            // Allocate the array to hold 2 Channel references.
            channels = new Channel[2];

            // Create each Channel and add it to the channels[] array.
            channels[0] = new Channel(Pins.GPIO_PIN_D5, Pins.ONBOARD_SW1);  // Green channel
            channels[1] = new Channel(Pins.GPIO_PIN_D6, Pins.GPIO_PIN_D1);  // Red channel

            // Bind the interrupt handler to the pin's interrupt event.
            // The same interrupt handler is used for all the channels.
            // The data1 parameter in the handler will determine which button
            // generated the interrupt.
            foreach (Channel ch in channels)
            {
                ch.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 corresponding button is pushed (true).
            foreach (Channel ch in channels)
            {
                if (true == ch.ButtonState)
                {
                    // Set the pin's new duty cycle.
                    ch.Led.SetDutyCycle(gammaTable[ch.PwmIndex]);
                    ch.PwmIndex += ch.PwmIncrement;

                    Debug.Print(gammaTable[ch.PwmIndex].ToString());

                    if (((gammaTable.Length - 1) == ch.PwmIndex) || (0 == ch.PwmIndex))
                    {
                        // The duty cycle has hit the min or max value.
                        // Start ramping in the other direction.
                        ch.PwmIncrement = -ch.PwmIncrement;
                    }
                }
            }
        }

        // port:  The pin number of the port that generated the interrupt
        // state: The logic state of the port
        // time:  Time of the event
        public static void SwitchInterruptHandler(UInt32 port, UInt32 state, DateTime time)
        {
            foreach (Channel ch in channels)
            {
                if (port == (UInt32)ch.Button.Id)
                {
                    ch.ButtonState = (0 == state);
                }
            }
        }

    }
}



#3236 Power Questions - i.e. Voltage

Posted by dab on 30 September 2010 - 01:59 AM in General Discussion

ummmm didnt think about that.... I dont really know. I guess what I'm asking is what can I do to get a battery with high amps and at least 9V... cuz they sell them for RC model airplanes, but those are crazy expensive

Well, you could put two of the 6V batteries in series to get 12V.

With a regulator, it's fairly easy to *decrease* the voltage. But, in general, it's not easy to increase the voltage of a DC source.

Increasing the voltage generally involves converting DC to AC (or a DC square wave), passing it through a step-up transformer, and converting back to DC.

But if you do that, then the current will decrease proportionally with the voltage increase (actually, you'll lose even more current due to losses in the transformer, etc.).



#2702 Out of memory error

Posted by dab on 23 September 2010 - 10:45 PM in Netduino 2 (and Netduino 1)

I think we'd need to see the rest of the code in order to find the problem. Can you post the complete source code?



#3180 Introducing Netduino Plus -- Notes

Posted by dab on 29 September 2010 - 06:58 AM in Netduino Plus 2 (and Netduino Plus 1)

Chris,

I have no microSD atm, so will need to buy one. Could you post a list of cards that are known to work?

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.



#566 InterruptPort

Posted by dab on 16 August 2010 - 07:30 AM in Netduino 2 (and Netduino 1)

Quick update... We found the problem. A single line of code in the GPIO debouncer code was causing the glitch in the glitchfilter.

We have implemented the GlitchFilter fix in the v4.1.0.2 (4.1.0 patch 2) update along with the AnalogInput bugfix. The updated firmware will be posted by tomorrow.

Chris


Cool, I'll be sure to try it out (tomorrow).



#441 InterruptPort

Posted by dab on 14 August 2010 - 08:36 PM in Netduino 2 (and Netduino 1)

Hi Chris,

Yeah, I know how delegates and events work. I've been coding professional for 10+ years. I found out why my InterruptPort wasn't working!! It was the glitchFilter, I set it to true. I remember reading it somewhere that if you set the glitchFilter to true, that will automatically handle switch debouncing for you. Could you clarify the use of this parameter for me as I am confused now. And thanks for the quick reply. You guys are doing great job helping the Netduino community to get started.

xc2rx


Hi xc2rx,

I found the same thing that you did with the glitchFilter parameter. (BTW, I'm the guy who posted the ToggleButton sample that Chris referred to).

In the ToggleButton sample, if I set the InterruptPort's glitchFilter parameter to true, it seems that the interrupts don't fire (or the event associated with the interrupt doesn't fire - not sure which one).

@Chris - is there a way we can investigate this further?



#627 InterruptPort

Posted by dab on 17 August 2010 - 12:09 AM in Netduino 2 (and Netduino 1)

Perhaps we could "dedicate" bug fixes to our community members? :)

Or maybe you could award Fabulous PrizesTM to the top bug finders (like a Netduino board or a trip to Hawaii). :)



#470 I love this thing, maybe too much...?

Posted by dab on 15 August 2010 - 04:07 AM in Netduino 2 (and Netduino 1)

Yep, generally PC fans are available in the following flavors:

2 wires: Constant speed
3 wires: Constant speed w/ tachometer output
4 wires: Variable speed w/ tachometer output and speed input (PWM)

I recently saw an article on the Make: blog where a guy had connected a 3-wire fan to an Arduino and it displayed the fan's speed on 7-segment displays. I think that would be a good re-make with the Netduino. ;)

http://blog.makezine...th_arduino.html



#3178 How to use the SD card and StreamWriter

Posted by dab on 29 September 2010 - 06:48 AM in Netduino Plus 2 (and Netduino Plus 1)

Chris,
Thanks for looking into this. If you change to use ReadToEnd() the behavior is the same. So this might be memory leak inside the StreamReader itself.

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

Posted by dab on 30 September 2010 - 06:01 AM in Netduino Plus 2 (and Netduino Plus 1)

We have posted updated firmware to address the SD card mounting and memory allocation issues.
http://forums.netdui...patch-4-beta-1/

SD card-related updates in the firmware update:
* Mounting invalid MicroSD cards now throws an exception
* Reduced memory usage when accessing SD cards

Please let me know if this new firmware fixes things for you...

Chris

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. B)



#476 Facebook

Posted by dab on 15 August 2010 - 06:01 AM in Netduino 2 (and Netduino 1)

I think you guys need a facebook page...



#1404 Electronics Books

Posted by dab on 27 August 2010 - 06:16 AM in General Discussion

I'm in the same boat. This book has been fan-freakin-tastic: Make: Electronics

Stacy

+1 on Make: Electronics. Very fun and easy read, with clear explanations and experiments that demonstrate the principles well.

Some of the old Radio Shack books by Forest M. Mims are also quite good. I believe you can still get his classic "Getting Started in Electronics", as well as reprints that combine several of the small "Engineer's Mini Notebook" titles in one book.



#2602 Controlling a LED Intensity

Posted by dab on 22 September 2010 - 05:27 AM in General Discussion

And if you have any questions about the PwmSample, please feel free to post them here or in the Project Showcase forum (I posted the sample code). Let us know when you get the Cylon / Knight Rider circuit working (and share the code if you don't mind). ;)



#3209 Console Output??

Posted by dab on 29 September 2010 - 09:14 PM in General Discussion

Hi Shane and welcome!

The Debug.Print will appear in the Output window within Visual Studio or Express.

Cheers,
Matt.


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??

Posted by dab on 30 September 2010 - 02:03 AM in General Discussion

You can also view the Debug.Print statements through MFDeploy. If you're not running the app from Visual Studio, press F5 in MFDeploy to hook into the Netduino's Debug output.

Chris

Oh, cool - I didn't know that. Thanks for the tip!



#3129 Buying or Acquiring Parts

Posted by dab on 28 September 2010 - 06:24 PM in General Discussion

This is a timely topic ;). It would nice to make this a sticky thread for future reference (and a place to point somebody to when they ask where to find things).

I'll add a couple more:

  • Evil Mad Science Shop: This is the companion store for the Evil Mad Scientist Laboratories blog. A smaller but more eclectic shop. They mainly sell kits of their own design, and also have some good deals on components (like RGB LEDs). Also check out the EggBot.
  • Adafruit Industries: The companion store for the LadyAda.net blog (aka Limor Fried). Like Evil Mad Science, the store carries a lot of kits designed by LadyAda, as well as lots of Arduino boards and shields. There's some overlap with MakerShed and SparkFun, but a lot of cool stuff.



#483 BlinkyTimer sample

Posted by dab on 15 August 2010 - 06:56 AM in Project Showcase

Thanks Chris! And thanks for moving it to the new forum.

One quick note: you don't need to put the infinite sleep inside a loop. It will only execute once...so they while(true) is redundant...


Yeah, I keep meaning to fix that. It was in a sample program from the book "Embedded Programming with the Microsoft .NET Micro Framework", but I agree it seems redundant. It might also make the code a little smaller by removing the while loop(?).



#478 BlinkyTimer sample

Posted by dab on 15 August 2010 - 06:36 AM in Project Showcase

Here's another little sample that I put together called BlinkyTimer.

This basically does the same thing as the Blinky tutorial, but it uses a Timer object with a callback method to turn the LED on and off.

Here's the code. If you think of any cool variations, please share. :D

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace BlinkyTimer
{
    public class Program
    {
        const int blinkPeriod = 250;
        static bool ledState;
        static OutputPort led;

        public static void Main()
        {
            // Set the initial state of the LED to off (false).
            ledState = false;

            led = new OutputPort(Pins.ONBOARD_LED, ledState);

            // Create a System.Threading.Timer instance and pass it the timer callback method.
            Timer blinkTimer = new Timer(
                new TimerCallback(BlinkTimerCallback),
                null,
                blinkPeriod,
                blinkPeriod);

            Thread.Sleep(Timeout.Infinite);
        }

        public static void BlinkTimerCallback(Object obj)
        {
            // Invert the previous state of the LED.
            ledState = !ledState;

            // Set the LED to its new state.
            led.Write(ledState);
        }

    }
}




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.