Netduino home hardware projects downloads community

Jump to content

The Netduino forums have been replaced by new forums at This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.


Member Since 04 Oct 2012
Offline Last Active Mar 20 2019 10:44 AM

Topics I've Started

Extending Analog Input using 4017 and 4066

17 February 2014 - 05:58 PM

My project Goal is "Netduino Read 9 or more Analog Sensor".


Here I'm using Netduino+, with RTC on A4 and A5. so I just have 4 left more analog pin, but I used to read 9 analog sensor continuously. So I come with 4017 and 4066 to drive Analog Reading alternately.


here my schema:

Posted Image


Q0 => Humidity Sensor

Q1 => Distinguish-er (not a sensor... just a voltage divider to return 2.2v )

Q2 => Temperature

Q3 => Air Pressure

Q4 => Reset if you don't attaching any  more sensors.

Q5 - Q9 (we can add more sensor) but in my case I just need to use 3 sensor in a single analog pin.


whenever we trigger 4017,  it will send a 3.3v logic consecutively from Q0 to Q9 (except you reset it on middle).


This is one block of 4017 and 4066 as switcher. we can trigger the 4017 clock by using a single digital pin as output port. here, every 15sec netduino trigger 4017 to switch the analog input.

if (_getDistinguisher){    Distinguisher.Read(); //read analog input    while (Distinguisher.value < 2000) //millivolts    {	Switcher.Switch(); //trigger 4017 to switch the channel (send positive triger 50ms)        Distinghuiser.Read();        Thread.Sleep(490);    }    if (Distinguisher.value > 2000) // if analog input reads 2v    { Switcher.Channel = 0; _getDistinguisher = false; } // then reset the chanel}if (_Second % 15 == 0) //do switch every 15 sec.{    if (_timeToSwitch)    {        Switcher.Switch();        if (Switcher.Channel == 0 || Switcher.Channel == 4) { Switcher.Channel = 0;         _getDistinguisher = true; }        _timeToSwitch = false;    }}else { _timeToSwitch = true; }

and we can read analog input alternately, here I use a simple code: (read 3 Analog sensor in asingle Analog Pin)

switch (Switcher.Channel) //these all Analog Read from Analog_GPIO_A0{   case 0:	Distinguisher.Read();        _currentReadValue = "Ch 0: " + Distinguisher.valueToString;//to display on Lcd        break;    case 1:        AirTemprature.Read();        AirTemprature.Collect(AirTemprature.value);        _currentReadValue = "Ch 1: " + AirTemprature.valueToString;        break;    case 2:        Humidity.Read();        HumidityContainer.Collect(Humidity.value);        _currentReadValue = "Ch 2: " + Humidity.valueToString;        break;    case 3:        AirPress.Read();        AirPressContainer.Collect(AirPress.value);        _currentReadValue = "Ch 3: " + AirPress.valueToString;        break;    default:	break;    }

Here's my note:

4017 is not always start with channel 0 on the start Up. That's why I do this (keep read and switch until we got the distinguish-er. 

    while (Distinguisher.value < 2000)    {	Switcher.Switch(); //trigger 4017 to switch the channel        Distinguisher.Read();        Thread.Sleep(490);    }

I'm still work with the code... so I cant attach it yet :P (sorry)... I will attach it soon.... :)


Cheers ^.^V

Extending Digital Input using game Controller

17 February 2014 - 04:39 PM

hi guys,


I'm developing a sensor station.... it will have more than 20 digital sensor. so in this case, I will using IC's 4066 to switch a USB Game Controller buttons. 




Digital Sensors ==> 4066 ==> Drive USB Game Controller Buttons ==> Send Byte to PC / Netduino



I've got no problem to do it in windows app. but hopefully to do it on Netduino. is any one have an idea how to send byte from USB to netduino? can I solve this by using USB host shield? or maybe FTDI cable?


appreciate any suggestion.


*additional Note:

4066 is just like a relay, it has 4 block switch on 1 IC.

Interrupt Port Fail

11 February 2014 - 09:42 AM

Hi guys,


Lately, I try to use a rotary encoder. I get the code from wiki 


namespace RotaryEncoder{    /// <summary>    /// For use with quadrature encoders where signal A and B are 90 out of phase.    /// </summary>    /// <remarks>    /// For a detented rotary encoder such as    /// Written by Michael Paauwe    /// Tested with .NETMF 4.2RC1 and Netduino Plus FW4.2.0RC1    /// </remarks>    class Encoder    {        private InputPort PhaseB;        private InterruptPort PhaseA;        private InterruptPort Button;        public bool buttonState = false;        public int position = 0;        /// <summary>        /// Constructor for encoder class        /// </summary>        /// <param name="pinA">The pin used for output A</param>        /// <param name="pinB">The pin used for output B</param>        /// <param name="pinButton">The pin used for the push contact (Optional:GPIO_NONE if not used)</param>        public Encoder(Cpu.Pin pinA, Cpu.Pin pinB, Cpu.Pin pinButton = Pins.GPIO_NONE)        {            PhaseA = new InterruptPort(pinA, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);            PhaseA.OnInterrupt += new NativeEventHandler(PhaseA_OnInterrupt);            PhaseB = new InputPort(pinB, false, Port.ResistorMode.PullUp);            if (pinB != Pins.GPIO_NONE)            {                Button = new InterruptPort(pinButton, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);                Button.OnInterrupt += new NativeEventHandler(Button_OnInterrupt);            }        }        void PhaseA_OnInterrupt(uint port, uint state, DateTime time)        {            if (state == 0)            {                if (PhaseB.Read() == true)                    position++;                else                    position--;            }            else            {                if (PhaseB.Read() == true)                    position--;                else                    position++;            }        }        void Button_OnInterrupt(uint port, uint state, DateTime time)        {            buttonState = (state == 0);        }    }} 

the code works fine for a week, but today it's goes fail. I see my encoder just fine when I test it by using LED attached on the Pins (it's still blinking). So I guess that the Interrupt Port doesnt work well anymore.


I put a breakpoint on the If statement(shown below), and debuging never reach this code, even I rotate the encoder.

 void PhaseA_OnInterrupt(uint port, uint state, DateTime time)        {            if (state == 0)

hope someone could see my problem and come up solution.

Sending SMS via GSMshield (icomsat v1.1)...return error

10 September 2013 - 01:14 AM

Hi Guys


lately I'm try to send SMS via GSMshield (using UART port Com1), but I dont know why it always return error as result (the SMS never sent). Can anybody help me to find the way out... :wacko:

Public Class GSM_UART_serial        Private Shared GSM_UART As SerialPort        Private Shared Respons As String        Private Shared bytesTosend As Byte()        Private Shared SendingSMS As Boolean        Public Shared Sub Main()            OnboardLed = New OutputPort(Pins.ONBOARD_LED, False)            D9 = New OutputPort(Pins.GPIO_PIN_D9, False)            SendingSMS = False            D9.Write(True)            Thread.Sleep(500)            D9.Write(False)            GSM_UART = New SerialPort("COM1", 9600, Parity.None, 8, StopBits.One)            AddHandler GSM_UART.DataReceived, New SerialDataReceivedEventHandler(AddressOf RecieveData)            If GSM_UART.IsOpen = False Then                GSM_UART.Open()                Debug.Print("Port Opening" & " : at baudRate= " & GSM_UART.BaudRate)            Else                Debug.Print("Port is ready...")            End If            SendingSMS = True            While SendingSMS = True                Thread.Sleep(250)                GSM_UART_dataWrite("AT+CMGF=1" & vbCr)                Thread.Sleep(250)                GSM_UART_dataWrite("ATE" & vbCr)                Thread.Sleep(250)                GSM_UART_dataWrite("AT+CMGS=")                Thread.Sleep(250)                GSM_UART.WriteByte(34)                GSM_UART_dataWrite("085218877358")                GSM_UART.WriteByte(34)                GSM_UART_dataWrite("" & vbCr)                Thread.Sleep(250)                GSM_UART_dataWrite("Body Massage being so good" & vbCr)                Thread.Sleep(250)                GSM_UART_dataWrite("x1A" & vbCr)                Thread.Sleep(1000)                SendingSMS = False            End While            Debug.Print(Respons & "?")            Thread.Sleep(Timeout.Infinite)        End Sub                Private Shared Sub GSM_UART_dataWrite(ByVal Command As String)            bytesTosend = Encoding.UTF8.GetBytes(Command)            Debug.Print("Send port : " & Command)            GSM_UART.Write(bytesTosend, 0, bytesTosend.Length)            Debug.Print("Port is writing...")        End Sub	    Private Shared Sub RecieveData(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)		    Dim Length As Integer = GSM_UART.BytesToRead		    Dim bufferData As Byte() = New Byte(Length - 1) {}		    GSM_UART.Read(bufferData, 0, Length)		    Respons += New String(Encoding.UTF8.GetChars(bufferData))		    If Respons.IndexOf(vbLf) >= 0 Then			    Respons = Respons.Trim()			    If Respons <> "" Then				    OnboardLed.Write(state:=True)				    Debug.Print(Respons)			    End If			    Respons = ""			    If Respons = "" Then				    OnboardLed.Write(state:=False)				    Debug.Print(Respons)			    End If		    End If	    End Subend class

very appreciate for your help


Best Regards

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.