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 29-April 23)


By content type

See this member's


Sort by                Order  

#58 Arduino wifi sheilds.

Posted by dab on 04 August 2010 - 10:35 PM in Netduino 2 (and Netduino 1)

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!



#64 Arduino wifi sheilds.

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

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!



#82 Arduino wifi sheilds.

Posted by dab on 05 August 2010 - 07:46 PM in Netduino 2 (and Netduino 1)

There is a .NET Micro Framework extension library project on the Codeplex called Grommet [^] that contains 'Asynchronus API XBee library' to communicate with XBee modules. I have not used it personally, though.


Cool, thanks for the tip!



#145 Unboxing: first impressions?

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

Just curious...when you received and opened your Netduino, what were your first impressions?

Anything we can do better to improve the "unboxing" experience?


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

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.



#167 Reversing the pushbutton state -- feedback?

Posted by dab on 09 August 2010 - 06:07 PM in Netduino 2 (and Netduino 1)

Shouldn't the SW1 button act like all the other GPIO's?

If you start out by using the SW1 for input, but later on decides to use another pin for the button, it wouldn't be good to require further code changes.

The way the button is wired (Pull-Up scenario) is pretty common, and having all GPIO's "inverted" wouldn't be fun is you ask me.

I'd say that a LOW signal on a pin should be FALSE, and a HIGH signal should be TRUE - Including the SW1 input.

Just my 5 cents...

/Thomas


You can make a good case for either option. I think the real problem is that a Port is fairly generic, while connecting a switch to an input port is a specific use case.

A couple of suggestions:

1. Define a new switch-specific enumeration, so that ON corresponds to boolean false, and OFF corresponds to boolean true.


2. Derive a Switch class from the InputPort class, and give the Switch class semantics that make sense for a switch (reading the state as being On/Off, Open/Closed, etc.).


Option 1 is probably simpler, while option 2 may be a "next version" type of thing.

Thanks,
-David



#290 Using InterruptPorts?

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

Hi,

I decided to try modifying the ButtonApp sample to use interrupts instead of polling the state of the pushbutton switch.

I found an example in the book "Embedded Programming with the Microsoft .NET Micro Framework", and kinda mashed up my own ToggleButton app.

The basic idea is to have the pushbutton switch "toggle" the LED on and off with each successive press (i.e., the first time the button is pushed and released, the LED turns on, and the next time the button is pushed, the LED turns off, etc.).

Here's the code that I came up with. There's probably some unnecessary code in here, since I was trying various ways to make it work.

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 InterruptPort button;
        static OutputPort led;
        static bool ledState;

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

            led = new OutputPort(Pins.ONBOARD_LED, ledState);
            button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLevelLow);

            // Bind the interrupt handler to the pin's interrupt event.
            button.OnInterrupt += SwitchInterruptHandler;
            button.EnableInterrupt();

            while (true)
            {
                Thread.Sleep(Timeout.Infinite);
            }
        }

        public static void SwitchInterruptHandler(UInt32 data1, UInt32 data2, DateTime time)
        {
            Debug.Print("+SwitchInterruptHandler");
            button.DisableInterrupt();

            // Invert the previous state of the LED.
            ledState = !ledState;

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

            button.EnableInterrupt();
            button.ClearInterrupt();
            Debug.Print("-SwitchInterruptHandler");
        }

    }
}

The problem is that the code seems to run fine under the debugger, but doesn't work as expected when it's not running in the debugger. :(

Can anybody spot what I'm doing wrong here?

Thanks,
-David



#291 Using InterruptPorts?

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


I decided to try modifying the ButtonApp sample to use interrupts instead of polling the state of the pushbutton switch.


Gaah, never mind. I just found that the Event Handlers tutorial has been posted in the Projects section. :huh:

I'll take a look at that...



#309 Request: New Forum

Posted by dab on 12 August 2010 - 05:53 PM in General Discussion

Do you intend for this forum to be used as a place for examples or mostly just troubleshooting of the main board? Cause I'm always writing and posting my *duino examples and I'd love to post them here (once my netduino shows up) if there were some Examples/Tutorials section that users could post to. Thanks, the product sounds like it should be a hoot and a half.


+1 to this suggestion. I think a place to share code and examples would be a good idea.



#312 Using InterruptPorts?

Posted by dab on 12 August 2010 - 06:26 PM in Netduino 2 (and Netduino 1)

Gaah, never mind. I just found that the Event Handlers tutorial has been posted in the Projects section. :huh:

I'll take a look at that...


Hmm, I seem to have the same issue with the AdvancedButtonApp tutorial. Works as expected under the debugger, but not when I just deploy the solution to the Netduino.

Is there some kind of timing issue that's causing this? Has anybody else got this working outside the debugger?



#315 Using InterruptPorts?

Posted by dab on 12 August 2010 - 06:35 PM in Netduino 2 (and Netduino 1)

Hmm, I seem to have the same issue with the AdvancedButtonApp tutorial. Works as expected under the debugger, but not when I just deploy the solution to the Netduino.

Is there some kind of timing issue that's causing this? Has anybody else got this working outside the debugger?


D'oh! Dumb mistake - I was just selecting the "Deploy Solution" menu option from the Build menu. I needed to select "Start Without Debugging" from the Debug menu to get the solution to actually run. :huh:

Now both programs work as expected.

Move along, nothing to see here...



#339 ToggleButton sample

Posted by dab on 13 August 2010 - 06:39 AM in Project Showcase

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

    }
}



#343 ToggleButton sample

Posted by dab on 13 August 2010 - 06:57 AM in Project Showcase

Have you tried to enable glitch filter: button = new InterruptPort(..., true, ...) ? The debouncing time is controlable via CPU.GlitchFilterTime [^] property.


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

Posted by dab on 13 August 2010 - 06:05 PM in Project Showcase

I have playing with the example on my silly emulator and works great :D

http://forums.netdui...indpost__p__277


Cool, thanks! I've been meaning to try out your emulator. So many projects, so little time... :(



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



#442 Request: New Forum

Posted by dab on 14 August 2010 - 08:40 PM in General Discussion

How about a "Netduino Projects" forum where users can showcase their projects?

And then the Sandbox would be perfect for posting code snippets?

Sounds good!



#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



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



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

    }
}



#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(?).



#487 BlinkyTimer sample

Posted by dab on 15 August 2010 - 07:01 AM in Project Showcase

I just updated it for you. Please let me know if you'd like me to change it back.

You beat me to it. ;) Thanks again, Chris!

(And get some sleep, OK?)



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

    }
}



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



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



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



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




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.