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

N+ to N+2 migration issues

DIO

  • Please log in to reply
6 replies to this topic

#1 Douglas

Douglas

    New Member

  • Members
  • Pip
  • 5 posts

Posted 10 July 2013 - 01:19 PM

Hello All,

 

    I have a number of Netduiono plus cards upgraded to the latest firmware programmed with software and deployed in a lab.  My problem is the next batch of cards I received are Netduino Plus 2 cards.  I flashed them to the latest firmware (4.2.2) and deployed my software.  It does not work on the new boards.  It seems to run, but, it does not detect switch state changes.  Below is an example of how I create the "ports".  I read the value with an input.Read() method inside a polling loop.  The card is acting like the ports have been set up for their other uses. i.e. UART1, UART2, etc.  I have nothing in my code that does that and like I said it runs fine on a N+.  Any ideas?

 

Regards,

 

Douglas

 

                case 0:
                    input = new InputPort(Pins.GPIO_PIN_D0, true, Port.ResistorMode.PullUp);
                    break;
                case 1:
                    input = new InputPort(Pins.GPIO_PIN_D1, true, Port.ResistorMode.PullUp);
                    break;
 


#2 Douglas

Douglas

    New Member

  • Members
  • Pip
  • 5 posts

Posted 11 July 2013 - 10:50 PM

Someone has to have some ideas.  Please.  I tried the analog ping and they work as expected.  As I mentioned before it is looking like the board has come up with the other devices enabled instead of as a "blank slate".  As I mentioned this code works fine on the netduino plus.

 

 

 
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
 
 
namespace DummyLoadPortSensor
{
    public class SwitchMonitor
    {
        private Object      switchStateLock;
        private SwitchStateEnum currentSwitchState = SwitchStateEnum.SwitchIsUnknown;
        private SwitchStateEnum previousSwitchState = SwitchStateEnum.SwitchIsUnknown;
        private ushort state;
//        private SecretLabs.NETMF.Hardware.AnalogInput analogInput;
        private Microsoft.SPOT.Hardware.InputPort input;
        private Microsoft.SPOT.Hardware.OutputPort led;
        private int         pollTime;
        private TCPWriterInputQueue tcpWriterInputQueue;
 
        #region Constructor
 
        /// <summary>
        /// This is the constructor for a switch monitor.
        /// It takes 2 arguments, both ints.  The first one
        /// is the general purpose IO number (0-13) and the
        /// second one is the polling interval in ms.  For
        /// debounce purposes it takes 12 polling cycles
        /// with a non changed value before a change from a
        /// prevoius state is registered.  i.e. a polling
        /// interval of 100(ms) would register a change if
        /// the switch were in the new position for about
        /// 1.2 seconds.
        /// </summary>
        /// <param name="gpioLineNumber">The input pin to monitor 0-13</param>
        /// <param name="pollInterval">The input pin to monitor 0-13</param>
        public SwitchMonitor(int gpioLineNumber, int pollInterval, TCPWriterInputQueue tcpWriterInputQueue)
        {
            this.tcpWriterInputQueue = tcpWriterInputQueue;
 
            pollTime = pollInterval;
            switchStateLock = new Object();
            led = new Microsoft.SPOT.Hardware.OutputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.ONBOARD_LED, false);
 
            state = new ushort();
 
            switch(gpioLineNumber)
            {
                case 0:
//                    analogInput = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0);
                    input = new Microsoft.SPOT.Hardware.InputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D0, true, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp);
                    break;
                case 1:
//                    analogInput = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A1);
                    input = new Microsoft.SPOT.Hardware.InputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D1, true, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp);
                    break;
                case 2:
                    input = new Microsoft.SPOT.Hardware.InputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D2, true, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp);
                    break;
                case 3:
                    input = new Microsoft.SPOT.Hardware.InputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D3, true, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp);
                    break;
                case 4:
                    input = new Microsoft.SPOT.Hardware.InputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D4, true, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp);
                    break;
                case 5:
                    input = new Microsoft.SPOT.Hardware.InputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D5, true, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp);
                    break;
                case 6:
                    input = new Microsoft.SPOT.Hardware.InputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D6, true, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp);
                    break;
                case 7:
                    input = new Microsoft.SPOT.Hardware.InputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D7, true, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp);
                    break;
                case 8:
                    input = new Microsoft.SPOT.Hardware.InputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D8, true, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp);
                    break;
                case 9:
                    input = new Microsoft.SPOT.Hardware.InputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D9, true, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp);
                    break;
                case 10:
                    input = new Microsoft.SPOT.Hardware.InputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D10, true, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp);
                    break;
                case 11:
                    input = new Microsoft.SPOT.Hardware.InputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D11, true, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp);
                    break;
                case 12:
                    input = new Microsoft.SPOT.Hardware.InputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D12, true, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp);
                    break;
                case 13:
                    input = new Microsoft.SPOT.Hardware.InputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D13, true, Microsoft.SPOT.Hardware.Port.ResistorMode.PullUp);
                    break;
                default:
                    break;
            }
 
        }
 
        #endregion
 
        #region PrivateParts
 
        /// <summary>
        /// Read the current state of the hardware pin. 
        /// Returns 1 if the switch is closed and 0
        /// if otherwise.
        /// </summary>
        private ushort RawSwitchIsClosed()
        {
//            Debug.Print("Analog " + analogInput.Read());
            if (input.Read() == true)
            {
                Debug.Print("Raw Closed");
                return 1;
            }
            else
            {
                Debug.Print("Raw Open");
                return 0;
            }
        }
 
        /// <summary>
        /// Read the debounced state of the switch. 
        /// The switch has to be stable in its current
        /// state for 12 polling cycles in order to be
        /// reported as open or closed.  Otherwise
        /// unknown is returned.
        /// </summary>
        private SwitchStateEnum DebouncedSwitch()
        {
            state = (ushort)(((state << 1) | RawSwitchIsClosed() | 0xF000) & 0x0000FFFF);
            if (state == 0xFFFF)
            {
                return SwitchStateEnum.SwitchIsClosed;
            }
            else if (state == 0xF000)
            {
                return SwitchStateEnum.SwitchIsOpen;
            }
            else
            {
                return SwitchStateEnum.SwitchIsUnknown;
            }
        }
 
        #endregion
 
        #region WorkerThread
        /// <summary>
        /// The main thread that monitors the changes
        /// in the switch state and send notifications
        /// of the changes to the TCP writer thread.
        /// </summary>
        public void monitorSwitch()
        {
            while(true)
            {
                SwitchStateEnum switchState = DebouncedSwitch();
                switch(switchState)
                {
                    case SwitchStateEnum.SwitchIsClosed:
                        lock (switchStateLock)
                        {
                            currentSwitchState = SwitchStateEnum.SwitchIsClosed;
 
                            if (previousSwitchState == SwitchStateEnum.SwitchIsUnknown)
                            {
                                currentSwitchState = SwitchStateEnum.SwitchIsClosed;
                                previousSwitchState = currentSwitchState;
                                Debug.Print("Initial state Closed");
                                /*
                                 * Not notifying a listener because there should 
                                 * not be one.  There should not be a condition 
                                 * where there is already a listener while this
                                 * thread is starting up.
                                 */
                            }
                            else if (currentSwitchState != previousSwitchState)
                            {
                                Debug.Print("Transition to Closed");
                                tcpWriterInputQueue.notifyWriterOfOutput("SwitchClosedEvent");
                                previousSwitchState = currentSwitchState;
                            }
 
                            led.Write(true); // Turn on LED
                        }
 
                        break;
                    case SwitchStateEnum.SwitchIsOpen:
                        lock (switchStateLock)
                        {
                            currentSwitchState = SwitchStateEnum.SwitchIsOpen;
                            if (previousSwitchState == SwitchStateEnum.SwitchIsUnknown)
                            {
                                currentSwitchState = SwitchStateEnum.SwitchIsOpen;
                                previousSwitchState = currentSwitchState;
                                Debug.Print("Initial state Open");
                                /*
                                 * Not notifying a listener because there should 
                                 * not be one.  There should not be a condition 
                                 * where there is already a listener while this
                                 * thread is starting up.
                                 */
                            }
                            else if (currentSwitchState != previousSwitchState)
                            {
                                Debug.Print("Transition to Open");
                                tcpWriterInputQueue.notifyWriterOfOutput("SwitchOpenEvent");
                                previousSwitchState = currentSwitchState;
                            }
                            led.Write(false); // Turn off LED
                        }
                        break;
                    default:
                        // This handles the unknown case.
                        break;
                }
 
                Thread.Sleep(pollTime);
 
            }
        }
 
        /// <summary>
        /// Returns the current state of the switch (opened or closed)
        /// </summary>
        public SwitchStateEnum getSwitchState()
        {
            SwitchStateEnum result;
 
            lock (switchStateLock)
            {
                result = currentSwitchState;
            }
 
            return result;
        }
 
        #endregion
    }
}
 
 


#3 Anthony Glenwright

Anthony Glenwright

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts

Posted 17 July 2013 - 01:25 AM

For the Netduino plus 2 you need to change your reference from SecretLabs.NETMF.Hardware.NetDuinoPlus to SecretLabs.NETMF.Hardware.Netduino, and your using statement from SecretLabs.NETMF.Hardware.NetduinoPlus to SecretLabs.NETMF.Hardware.Netduino



#4 Douglas

Douglas

    New Member

  • Members
  • Pip
  • 5 posts

Posted 17 July 2013 - 06:59 PM

Been there done that.  It was all *.Hardware.Netduino at the beginning.  It was the same result.  That is why I changed it to this in order to see if it might make a difference.  It did not.



#5 jiwonoh

jiwonoh

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts

Posted 18 July 2013 - 08:16 AM

Dear Douglas

 

I recommed you to check the version of assmebiles - *.Hardware.Netduino as same as MF version. In my case, I tried to migrate NP2 code to NP1, but it was failed, cause the version of those.

 

Regards,

Jiwon.



#6 Anthony Glenwright

Anthony Glenwright

    Advanced Member

  • Members
  • PipPipPip
  • 71 posts

Posted 18 July 2013 - 08:21 AM

Did you try putting SecretLabs.NETMF.Hardware.Netduino.Pins instead of just Pins?  Both the SecretLabs and Microsoft namespaces have a Pins enum (and they are different).

 

Only suggesting this as I have run into it before myself, and the symptoms matched yours.



#7 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 18 July 2013 - 09:08 AM

just Pins. is ok, thats the secretlabs one. the other is CPU.Pins






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

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.