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.

cce1911

Member Since 15 Apr 2013
Offline Last Active Jun 19 2014 05:25 PM
-----

Topics I've Started

Button Interrupts

15 December 2013 - 03:32 PM

I'm seeing some odd behavior for what should be a simple project. Maybe I'm missing something and someone can point out the error of my ways?

 

What I'm trying to do is capture a sensor input. To test my code I've simulated the sensor with a simple momentary push button. See the schematic attached.

 

The problem is when I push one button, it triggers the interrupt for the other buttons. Here is my code:

public class Program2        {        static DateTime dtLastPress;        static int intBounceWait = 200;        public static void Main()            {            InterruptPort ipT1 = new InterruptPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);            ipT1.OnInterrupt += T_OnInterruptT1;            InterruptPort ipT2 = new InterruptPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);            ipT2.OnInterrupt += T_OnInterruptT2;            InterruptPort ipT3 = new InterruptPort(Pins.GPIO_PIN_D2, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);            ipT3.OnInterrupt += T_OnInterruptT3;            InterruptPort ipT4 = new InterruptPort(Pins.GPIO_PIN_D3, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);            ipT3.OnInterrupt += T_OnInterruptT4;            Thread.Sleep(Timeout.Infinite);            }        static void T_OnInterruptT1(uint data1, uint data2, DateTime time)            {            if (dtLastPress.AddMilliseconds(intBounceWait) > time)  // prevent bounce                {                Debug.Print("T1 = bounce wait");                return; // prevent bounce                }            dtLastPress = time;            RecordPress(1, time);            }        static void T_OnInterruptT2(uint data1, uint data2, DateTime time)            {            if (dtLastPress.AddMilliseconds(intBounceWait) > time)  // prevent bounce                {                Debug.Print("T2 = bounce wait");                return; // prevent bounce                }            dtLastPress = time;            RecordPress(2, time);            }        static void T_OnInterruptT3(uint data1, uint data2, DateTime time)            {            if (dtLastPress.AddMilliseconds(intBounceWait) > time)  // prevent bounce                {                Debug.Print("T3 = bounce wait");                return; // prevent bounce                }            dtLastPress = time;            RecordPress(3, time);            }        static void T_OnInterruptT4(uint data1, uint data2, DateTime time)            {            if (dtLastPress.AddMilliseconds(intBounceWait) > time)  // prevent bounce                {                Debug.Print("T4 = bounce wait");                return; // prevent bounce                }            dtLastPress = time;            RecordPress(4, time);            }        static void RecordPress(int intTarget, DateTime time)            {            Debug.Print("T" + intTarget.ToString() + " = " + DateTime.Now.ToString("MM/dd/yy H:mm:ss.fff"));            }        }

If I run the code and press the buttons in order (T1, T2, T3, T4) I get the following output:

T3 = 06/01/11 0:00:10.259
T4 = bounce wait
T3 = bounce wait
T4 = bounce wait
T2 = bounce wait
T1 = bounce wait
T2 = 06/01/11 0:00:12.705
T3 = 06/01/11 0:00:16.861
T4 = bounce wait
T2 = bounce wait
T1 = bounce wait
 
 
Any insight into what I'm doing wrong would be appreciated.

How to drive multiple lasers?

22 November 2013 - 06:07 PM

So I have gotten my shift register to work with my N+2, but the lasers I'm trying to drive require 300mA of current each. So to drive 9 of these, I need almost 3A at 2.5 - 4.5 vdc.  This is way too much for the N+2 and the 74HC595. I've been looking at some transistor arrays, but I'm not sure how to wire them. Can anyone point me to a circuit that uses this 8ch Darlington Sink driver(or something similar)?


Sparkfun Shift Register Breakout - 74HC595

17 November 2013 - 08:45 PM

Can someone point me to an example of using this breakout board with the Netduino?

https://www.sparkfun.../products/10680

 

I would like to use the .Net Microframework Toolbox, but it's not obvious to me how to wire it up.

 

 


Interrupt event handler conflicts

21 August 2013 - 01:47 PM

I have a N+2 driving 2 stepper motors with the Sparkfun Easydriver. I have wired up several external buttons

InterruptPort ipT1 = new InterruptPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);ipT1.OnInterrupt += Target_OnInterruptT1;InterruptPort ipT2 = new InterruptPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);ipT2.OnInterrupt += Target_OnInterruptT2;

?

 

Here are my event handlers

        static void Target_OnInterruptT1(uint data1, uint data2, DateTime time)            {            if (dtLastHit.AddMilliseconds(intBounceWait) > time) return; // prevent bounce            dtLastHit = time;            Debug.Print("Hit T1 = " + DateTime.Now.ToString("MM/dd/yy H:mm:ss.fff"));            }        static void Target_OnInterruptT2(uint data1, uint data2, DateTime time)            {            if (dtLastHit.AddMilliseconds(intBounceWait) > time) return; // prevent bounce            dtLastHit = time;            Debug.Print("Hit T2 = " + DateTime.Now.ToString("MM/dd/yy H:mm:ss.fff"));            }

My problem is that when I press button T1 it randomly executes Target_OnInterruptT2 or Target_OnInterruptT1. No rhyme or reason. The same thing happens if I press button T2.

 

What is odd is that I've used this same exact board with 5 buttons, in the past, and had no problems. Any idea what is happening? I thought it might be EMI from the Easy driver, but I still get the same behavior even if I disconnect power to the stepper motors.

 

I'm scratching my head...


Failed allocation while writing text file

14 August 2013 - 01:42 AM

In my N+2 app, I log things to a text file for later debugging. I use this code in a function:

using (var filestream = new FileStream(@"SDrunlog.txt",FileMode.Append))                    {                    StreamWriter streamWriter = new StreamWriter(filestream);                    streamWriter.WriteLine(DateTime.Now.ToString("MM/dd/yy H:mm:ss.fff") + ": " + strMsg);                    streamWriter.Close();                    //Debug.Print(DateTime.Now.ToString("MM/dd/yy H:mm:ss.fff") + ": " + strMsg);                    }

When my log file gets over 33k I get a failed allocation error when creating the new streamwriter:

StreamWriter streamWriter = new StreamWriter(filestream);

 

Any idea on what is causing this and how to avoid it?  


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.