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

Using both Analog and Digital on same pin


  • Please log in to reply
4 replies to this topic

#1 lvw

lvw

    Member

  • Members
  • PipPip
  • 11 posts
  • LocationZuid Holland, The Netherlands

Posted 02 December 2012 - 11:20 PM

Hi all,

A little background information;

I'm currently working on a project that uses a Analog/Digital MUX breakout from SparkFun.

The main problem I'm having is that each of these boards have 1 'signal' i/o pin. Since the board can handle both analog and digital signals, I would like to make use of one of the analog pins on the N+.

I tried some short code to switch accordingly between analog and digital, disposing the previous instance of the port before initializing a new one.

After a few times of switching I'm getting 'An unhandled exception of type 'System.Exception' occurred in Microsoft.SPOT.Hardware.dll'

I'm properly disposing the port object AFTER I've retrieved the state/value of the input using the Dispose method of the ports. Im suspecting that somewhere along the way, the object isnt disposed properly in code that is out of my reach (in the .NET framework perhaps).

So my main question is,is there any limitation (think speed wise, number of times, or other..) using this method?
Is this possible at all ( I know it works a few times, but is it possible to have this as permanent solution?)

Thanks

#2 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 03 December 2012 - 12:40 AM

you can just use analog, it can read digital signals too... digital is 0v and 3.3v //edit do not use more than 3.3v on analog pins //edit iam also not sure if you can connect gnd to analog. someone can confrim this?

#3 Arron Chapman

Arron Chapman

    Advanced Member

  • Members
  • PipPipPip
  • 289 posts
  • LocationOregon, USA

Posted 03 December 2012 - 02:34 AM

you can just use analog, it can read digital signals too... digital is 0v and 3.3v

//edit do not use more than 3.3v on analog pins
//edit iam also not sure if you can connect gnd to analog. someone can confrim this?


I'll echo what NooM said about <= 3.3V anything higher is likely to cause damage to the ADC resulting in poor readings in the future. Regarding GND; Connecting GND to an analog input is fine, it should read 0.0 or just 0 depending on your framework version when you read from the port.

When you talk EE use small words, I'm just a Software Developer :)
My Blog/Site and Everything Else

If my post helped you please consider pressing the "Like This" button in the bottom right-hand corner.

 

Oh my. So many things, so little money!!

 


#4 lvw

lvw

    Member

  • Members
  • PipPip
  • 11 posts
  • LocationZuid Holland, The Netherlands

Posted 03 December 2012 - 08:29 AM

Alright, reading should not be a problem then, thanks. I probably should have mention this, but I'm also using it for signaling high to some SPI devices, would there be any solution for that?

#5 lvw

lvw

    Member

  • Members
  • PipPip
  • 11 posts
  • LocationZuid Holland, The Netherlands

Posted 04 December 2012 - 07:18 PM

I'll try to illustrate what i'm trying to accomplish here.
My project needs to become a central place to hook up sensors using RJ45 plugs and UTP cable. It also should allow me to control SPI and I2C devices connected to it.


Basic setup is;
N+,
2 bit shift registers.
2 SparkFun Mux/Demux boards.
Some other components that do not have any effect on the above (PWM driver from AdaFruit, a Nokia 5110 display, a RFID reader, etc.).

I'm using the bit shift registers to control the 2 sparkfun boards, that part works as intended.
My code allows me to put in a integer (1-32, it's 16 pins a board) and it enables the appropriate board, and selects the correct port (32 enables board 2, select pin 15).

At that point, I'll look up what type of sensor or piece of hardware is attached, from a list of custom 'port objects'.
Those objects contain a type (analog or digital) and some other information (IN/OUT/SPI/I2C/PWM, a port number, memory value for the last read value, etc.)

I need (want) to initiate a AnalogInput, InputPort or OutputPort at that point, allowing me to read a analog value, read a digital value or write a digital value.

That value will be logged (storage card, webservice and if needed, texted to my phone). If the device attached to the port is a SPI device, and action needs to be taken, it should write true (high) to the same pin, as that port will be used as CS pin.

Since I have 2 SparkFun boards, I need to connect 2 wires (1 wire per board) from the signal pin to a pin on the N+. I want to use the A pins here, as the SparkFun boards allow both analog, digital and data to be connected to the boards.

In code, there is a Thread that runs a loop (no interrupt on the sparkfun boards) to set the port number (that is in a list, enabled and needs to perform 'a' action at that time)

I'll paste some pseudo code to demonstrate what I'm doing.
while(thePortWatcherIsEnabled) 
{
    switchExpanderBoard(toNextPortThatIsDigital);
    Thread.Sleep(10);

    
        using (InputPort d = new InputPort(Pins.GPIO_PIN_A1, false, Port.ResistorMode.Disabled))
        {
             d.Read();
        }
    

    switchExpanderBoard(toNextPortThatIsAnalog);
    Thread.Sleep(10);

  
        using (AnalogInput a = new AnalogInput(Microsoft.SPOT.Hardware.Cpu.AnalogChannel.ANALOG_1))
        {
            a.Read();
        }
    

    switchExpanderBoard(toNextPortThatIsDigitalAgain);
    Thread.Sleep(10);

   
        using (OutputPort d = new OutputPort(Pins.GPIO_PIN_A1, false))
        {
            d.Write(true);
        }
    
}

After a few loops of this, the error as mentioned in the start post is thrown, and it continues throwing it at 'random' intervals (sometimes it works, most of the time it doesn't after the first exception is thrown).




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.