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.

RobFromLI

Member Since 16 Nov 2014
Offline Last Active Jun 02 2016 08:39 PM
-----

Topics I've Started

Simple switch monitor - having trouble

20 January 2015 - 01:31 AM

HI All,

 

I'm trying to use a netduino plus 2 to act as a very simple monitor for a momentary switch.  Basically all I'm trying to do is when the switch changes states, post to a URL being monitored by an HTTPListener in an app on a pc on my network.

 

To test this, although I realize it's not the ideal test bench, I have simply put a pulldown resistor between GND and D1 and then used a short length of bell wire to short from 3.3v to D1, just in order to test.  Now, I realize this is not an ideal situation and I have some more supplies on the way in order to test in a better bench environment.  However, I am seeing behavior that seems bizarre, even given the bounce I would expect from using a wire as a switch and I feel like I am just doing something very basic very wrong.  I have attached a picture of my netduino physical setup - I currently am using a 1k 5% pulldown resistor, I started out with a 10k.  My code is below.  What I am seeing is one of several things, somewhat randomly:

 

  • If I do nothing but turn the LED on or off in the interrupt code based on the status of D1, everything is wonderful - every time I touch the wire to the D1 leg of the resistor the light turns on, and every time I take it away the light turns off.
  • If I create a URL and post to it on each interrupt as in the code below:
    • Occasionally, it will work fairly well.  I may get 15 or 20 hits to the HTTPListener each time I touch or take away the wire, which I would expect without debouncing, but it works.
    • Sometimes, I touch the wire once and I get continuous interrupts, with the light constantly flashing and the HTTPListener getting hit over and over again regardless of whether I then take the wire away or touch it
    • Sometimes, the HTTPListener gets the appropriate number of hits when I touch and take away the wire, but the light stays on constantly
    • When I get a constant stream of interrupts, they all seem to have the same time.  I'm not totally positive of this but I saw it at least once

I've been programming for quite a few years and judging by the random behavior I'm getting, I feel like I must be fundamentally misunderstanding the interrupt process, or missing an initialization, or that I am making some sort of grave hardware mistake.  Again, I understand I should have a breadboard and switch but from what I've read of the "experiment with a Netduino" posts out there, what I'm doing doesn't seem that fundamentally flawed that I should be having this many issues.  I'm hoping someone out there can tell me what it is I'm doing wrong.

 

Thanks very much!

 

Rob

 

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

namespace FirstApp
{
    public class Program
    {

        private static DateTime LastInterrupt;  //Part of attempt at filter - see below

        //Originally defined these in main, didn't make a difference when I moved them
        private static OutputPort onboardLED = new OutputPort(Pins.ONBOARD_LED, false);

        //Tried glitch filter true, didn't help
        private static InputPort D1 = new InterruptPort(Pins.GPIO_PIN_D1, false , Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

        private static int reqnum = 0;
        private static String s;
        private static HttpWebRequest test;
        private static uint lastvalue = 0;

        public static void Main()
        {
            D1.OnInterrupt += new NativeEventHandler(button_OnInterrupt);

            LastInterrupt = DateTime.Now.AddDays(-1); //Attempt at debounce - see below

            // Wait forever
            Thread.Sleep(Timeout.Infinite);
        }

        private static void button_OnInterrupt(uint port, uint data, DateTime time)
        {
            //My attempt at debouncing to see if that helps - it didn't seem to.  I tried 50, 100, 500, etc
            //if (LastInterrupt.AddMilliseconds(50 ) > time)
            //    return;
            //LastInterrupt = time;

            onboardLED.Write(data == 1);

            reqnum += 1;
            String s = (data == 1).ToString();

            //My attempt at a simple filter - didn't help
            //if (data == lastvalue)
            //    return;
            //lastvalue = data;

            HttpWebRequest test = (HttpWebRequest)HttpWebRequest.Create(String.Concat("http://192.168.1.80/this?",reqnum.ToString(), "=", s));
            
            //Thought I was getting random network errors at one point - however try/catch does not seem to make a difference
            //try
            //{
                test.GetResponse();
            //}
            //catch (Exception ex)
            //{
            //    Debug.Print(ex.Message);
            //}

        }

    }
}

 

 

Attached File  IMG_2073.JPG   149.64KB   2 downloads


Simple switch detection circuit - don't want to fry board

21 November 2014 - 04:55 PM

Hi all,

 

I am a very experienced programmer who has a little bit of electronics knowledge.  Basically I've fooled around in the past with some simple switches, lights and motors and maybe a resistor or two.

I'm looking to hook my netduino 2 plus to a normally open circuit and trigger it to bang a web service on my pc when the circuit closes.  I have the code roughed out using the on board button and now I want to code/test just using a short wire or switch before I hook it up to the larger circuit. 

I've done a good bit of searching and found this http://arduino.cc/en...utton_schem.pngwhich is part of this tutorial

http://www.arduino.c...Tutorial/Button

 

I just want to make sure before I try this (assuming I hook everything up properly and protect against static and all that) - if I hook a 10k resistor between digital input 1 and ground as a pull "down"(? or up? but I think down?) and then have a switch that connects the pin to 5v, I won't fry anything, is that right?

 

Do I have to have the pin set to the proper mode when I connect the wire in order to avoid frying something?  In other words if I have a bug and the pin's set to output but I put 5v on it, will it fry then?

 

Can I uses 3.3v, is that any safer / better?

 

TIA

 

Rob


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.