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

Easy multiplexing with the Netduino


  • Please log in to reply
64 replies to this topic

#1 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 12 April 2011 - 09:39 PM

If you want to skip the blah blah blah and only want to see something or download the schematic and source, scroll to the bottom of this article :)

From the moment I got my Netduino microprocessor board I was thinking, what are it's limitations, and how can I work around them? One of the most obvious limitations is the amount of Input/Output (I/O) ports. This image shows what the board is capable of.

Posted Image

I wanted to look a way around this limitation with quite some success. By adding multiple bitshift IC's it's possible to get virtually unlimited I/O-ports. The only limitation in this is the clock speed, but I haven't reached this limitation yet.

I've used two kinds of IC's, a serial-in/parallel-out, called 74HC595, and a parallel-in/serial-out, called 74HC165. They can be used in chains, so by adding more IC's, you won't need to use more I/O ports on the Netduino board. In my example below I got 32 I/O ports by only occupying 5 I/O's on the netduino.

The schematic is quite simple, I used buttons with pull-up resistor to represent of inputs and leds to represent outputs. The basic idea is that every added IC adds 8 Input or Output ports.
You can see it working at Youtube.

Posted Image

Then we get at the code part. Connecting stuff is one thing, making it work is another. The Netduino is filled with code compiled from C# and uses the .NET MicroFramework.
This framework has a couple of built-in classes, for example, OutputPort, InputPort and InterruptPort. I made copies of those built-in classes to work with the bitshift IC's, so usage would be a simple as the rest of the framework.

The only difference is that we need to define the IC setup first. So we got two input IC's and two output IC's. We define the connected chains first:
Ic74HC165Chain ChainIn = new Ic74HC165Chain(SPI_Devices.SPI1, Pins.GPIO_PIN_D10, 2);
Ic74HC595Chain ChainOut = new Ic74HC595Chain(SPI_Devices.SPI1, Pins.GPIO_PIN_D9, 2);
Both IC chains are connected to the Netduino's SPI bus (Pins 11 to 13) and use a different Chip Select-pin, in this example pins 9 and 10. Both chains contain 2 IC's.

When the chains are defined, we have to make interfaces for the IC's. This is done by this:
Ic74HC165 IcIn1 = new Ic74HC165(ChainIn, 0);
Ic74HC165 IcIn2 = new Ic74HC165(ChainIn, 1);
Ic74HC595 IcOut1 = new Ic74HC595(ChainOut, 0);
Ic74HC595 IcOut2 = new Ic74HC595(ChainOut, 1);
The enumeration starts at 0 as you can see. 0 is the first IC in the chain, 1 the second, 2 the third, etcetera.

Now we can define our Input/Output/InterruptPort classes. They have the same parameters as the regular classes except for the first one, which defines the IC it's connected to:
InterruptPortShift Button0 = new InterruptPortShift(IcIn1, Ic74HC165.Pins.GPI_PIN_D0, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);            
OutputPortShift Led0 = new OutputPortShift(IcOut1, Ic74HC595.Pins.GPO_PIN_D0, false);
Here we defined an InterruptPort and OutputPort using bitshift registers. From this part, the code which follows is exactly the same as it would be using the onboard I/O ports.

Credits
I wouldn't have done this without the help of two very nice guys in the Netduino Community: Mario Vernari and CW2. Thanks again :)
The schematics are made with the free tool Fritzing. Should also be mentioned since the tool is a great help!

Download source at http://netmftoolbox.codeplex.com/

Edited by Stefan, 13 September 2011 - 04:37 PM.
Updated download link

"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#2 Terry Massey

Terry Massey

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationPekin, IL

Posted 12 April 2011 - 09:41 PM

NIce work stefan
Thanks,
Terry Massey

#3 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 13 April 2011 - 01:50 AM

Way da go Stefan! Shiftregisters are really simple, yet extremely potent when one knows how to take advantage of them the way you've done here. Really nice and useful project. Oh, btw Stefan, I downloaded WinPcap based on your tip the other day (used it for both iPhone remote and speedtest thingys) and just downloaded and installed Fritzing which seems to be a very capable piece of sw. Thanks!

#4 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 13 April 2011 - 03:23 AM

The schematics are made with the free tool Fritzing. Should also be mentioned since the tool is a great help!

Great Tool, THANKS FOR SHARING (Sorry about the caps but this is exciting to me !)
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#5 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 13 April 2011 - 04:37 AM

Thanks a lot Stefan for the credit! Now, please, stop yourself and turn yourself back one month ago...where you were just moving few steps. Here you show your own little library to expand Netduino! What else than being proud of that? It's the same thing I always teach my kid (he's 8): don't say "I am not able to do!", just try and try and try again...if you really want it, finally you got it! Congrats again, Stefan! Cheers
Biggest fault of Netduino? It runs by electricity.

#6 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 13 April 2011 - 07:19 AM

Now, please, stop yourself and turn yourself back one month ago...where you were just moving few steps.
Here you show your own little library to expand Netduino!
What else than being proud of that?

Proud, excited, I think more excited ;)
I think the library is very useful for myself and others in the future and I'm glad it's finished.
By the way, I checked, and your month is quite accurate. I got my netduino at the 3rd of Mars and the first bitshift experiment was posted on the 14th of Mars :o

It's the same thing I always teach my kid (he's 8): don't say "I am not able to do!", just try and try and try again...if you really want it, finally you got it!

(no offense, it's a compliment) you sound just like my dad :)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#7 Dezorian

Dezorian

    Member

  • Members
  • PipPip
  • 24 posts

Posted 13 April 2011 - 09:36 AM

Great job Stefan! Just make sure your action figures don't destroy your breadboards ;) (inside joke :P)

#8 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 13 April 2011 - 11:59 AM

The moral of this little story is:
one brick a time, we will rewrite the whole MF!
;)
Biggest fault of Netduino? It runs by electricity.

#9 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 13 April 2011 - 12:01 PM

The moral of this little story is:

one brick a time, we will rewrite the whole MF!
;)

lol indeed :)
still thinking what my next thing will be, I²C or PWM... I see a lot of requests for I²C but I lack materials to test that and have to be careful about the money ;) And PWM will get some changes in NETMF4.2 so ... well... not sure what to do next.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#10 nrc

nrc

    Member

  • Members
  • PipPip
  • 11 posts

Posted 13 April 2011 - 05:25 PM

lol indeed :)
still thinking what my next thing will be, I²C or PWM... I see a lot of requests for I²C but I lack materials to test that and have to be careful about the money ;) And PWM will get some changes in NETMF4.2 so ... well... not sure what to do next.



Good work. For I2C try the MCP23017 I2C 16-port I/O expander. I'm now connecting those to netduino. I'm not sure if I can get interrupts from the expander I/Os.

#11 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 13 April 2011 - 09:23 PM

Good work. For I2C try the MCP23017 I2C 16-port I/O expander. I'm now connecting those to netduino. I'm not sure if I can get interrupts from the expander I/Os.

Interrupts on the 165 are software based, not hardware based. The same could be done for any kind of input I suppose.

When I go into I²C I will try that one, thanks!
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#12 Troll feeder

Troll feeder

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationArizona, USA

Posted 14 April 2011 - 06:36 AM

Way to go! Every Library added makes .netmf that more compelling, and increases it's apeal to businesses as well as us tinkers. :D Mike.

#13 Inquisitor

Inquisitor

    Advanced Member

  • Members
  • PipPipPip
  • 91 posts
  • LocationAtlanta, Georgia, USA

Posted 02 August 2011 - 02:14 PM

Stefan,

The more I read, learn, bookmark and… then… note who the teacher is… your avatar seems to come to mind the most. Thank you for sharing your expertise (and learning curve) here, all over the forum and on your personal web site.

I’m a software type with a real fuzzy picture of the hardware world. I currently have a little science project I want to create. I have scoped it out so far, such that I need…

  • (4) PWM Outputs to control servos
  • (15) Analog inputs to receive various sensory input (if it’s significant, I’m currently looking at a mix of IR Optical Detectors and Ultrasonic Range Finders)
  • (~8) Digital outputs to light various LED’s for status and/or warning indicators.

From my simplistic concept of Multiplexing… it allows me to time slice between far more inputs or outputs than I have on the Netduino. In your example above, you have both inputs and outputs. But before I go and make an ass of myself for assuming something… does you example work for analog inputs?

If I understand correctly, could I move the purple wire from Port 12 of the Netduino… to Port 0? And then in the software read from this analog input instead?

Thanks your your help.
Doing my best to keep the smoke in the little black boxes.
If my message helped you... how 'bout giving me a Posted Image
www.MessingWithReality.com

#14 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 02 August 2011 - 02:18 PM

For servos I also have a solution: http://forums.netdui...n-the-netduino/ My example doesn't work for analog inputs. I have some ICs at my workshop for that purpose but didn't got them working so far :) I'm far from a teacher, I just learn and share my findings on the boards. For analog inputs, perhaps someone can advise a method, I don't have one at this time.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#15 ItsDan

ItsDan

    Advanced Member

  • Members
  • PipPipPip
  • 101 posts

Posted 02 August 2011 - 02:33 PM

Consider using sensors that communicate over a serial protocol such as i2c. You can chain multiple devices on a single bus and not need 15 analog inputs.
Follow the adventures of the Box of Crappy Surplus

Total BOCS Traveled Distance: 9708 miles | States Visited: 5
Track the Box

#16 Inquisitor

Inquisitor

    Advanced Member

  • Members
  • PipPipPip
  • 91 posts
  • LocationAtlanta, Georgia, USA

Posted 02 August 2011 - 03:24 PM

Thank you for your response...

I guess I need to learn how to wire something up like this...Serial/Analog Mux/Demux - 74HC4052 ...
... or better yet... 16 Channel Multiplexer


... it turns out they even have a wiring example with an Arduino for us hardware challenged individuals :rolleyes:
Doing my best to keep the smoke in the little black boxes.
If my message helped you... how 'bout giving me a Posted Image
www.MessingWithReality.com

#17 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 02 August 2011 - 05:35 PM

I’m a software type with a real fuzzy picture of the hardware world.

<***OFF TOPIC***>
Assuming you're a programmer, imagine a world where's just one language to create your applications. That language has no owner than the universe, immutable since the beginning of the time, also will have no upgrades, nor evolution. You'll be granted it keep the same forever.
There are few rules, very well described, together with few tools. You know, few tools, but *good* tools. You may create everything with these tools.
There's no fuzzy depiction of this world: it's a well-ruled world called physics.
Welcome in the hardware world!

EDIT: I forgot to mention that IT HAS NO BUGS AT ALL!

I am an EE, but I love programming as well. I began over 30 years ago with software, and I must confess that I STILL HAVE A FUZZY PICTURE OF THE SOFTWARE WORLD!
</***OFF TOPIC***>

Inquisitor, both Stefan and ItsDan gave you good tips.
Your idea to use a CD4067 (16-1 mpx) is good as well.
Cheers.
Biggest fault of Netduino? It runs by electricity.

#18 Inquisitor

Inquisitor

    Advanced Member

  • Members
  • PipPipPip
  • 91 posts
  • LocationAtlanta, Georgia, USA

Posted 03 August 2011 - 01:00 PM

<***OFF TOPIC***>
Assuming you're a programmer, imagine a world where's just one language to create your applications. That language has no owner than the universe, immutable since the beginning of the time, also will have no upgrades, nor evolution. You'll be granted it keep the same forever.
There are few rules, very well described, together with few tools. You know, few tools, but *good* tools. You may create everything with these tools.
There's no fuzzy depiction of this world: it's a well-ruled world called physics.
Welcome in the hardware world!

EDIT: I forgot to mention that IT HAS NO BUGS AT ALL!

I am an EE, but I love programming as well. I began over 30 years ago with software, and I must confess that I STILL HAVE A FUZZY PICTURE OF THE SOFTWARE WORLD!
</***OFF TOPIC***>

Inquisitor, both Stefan and ItsDan gave you good tips.
Your idea to use a CD4067 (16-1 mpx) is good as well.
Cheers.


Hi Mario,
I enjoyed your “Off Topic” :rolleyes: … I think I detected a little sarcasm… because we all know Microsoft coding is bug free!
I guess I’m your double ganger with 30 years in the software world. … And… with a strong dose in Physics/Engineering. If I could have hooked up my computer to the real world, sensing and moving things in the price range this Netduino does, 30 years ago, I’m sure my life would have way different!

In my simple view of EE, I see… I just “tell” the CD4067 which sensor I want data, and then read the data on the single analog input. I just treat it like a big switch. I can deal with that! :blink:
I really liked Stafan and ItsDan idea as dealing with a com port is second nature to me… and again it would be my hardware limitations that shy me away from it. I don’t see how to get 15 of these little $1.13 sensors into a serial output… OR… having to pay a lot more for some equivalent sensor that does it for me and then get 15 of them.
Doing my best to keep the smoke in the little black boxes.
If my message helped you... how 'bout giving me a Posted Image
www.MessingWithReality.com

#19 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 03 August 2011 - 01:03 PM

I think I detected a little sarcasm… because we all know Microsoft coding is bug free!

Analog sarcasm sensor going 1023 and critical! ;)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#20 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 03 August 2011 - 01:23 PM

I enjoyed your “Off Topic” … I think I detected a little sarcasm… because we all know Microsoft coding is bug free!

There's a very little sarcasm, and absolutely anything related specifically to MS or others. It's simply a consideration of the absolute incapacity of the software world to find some good standards. That's evil, because software was born to answer the "limitation" of the hardware, thus reducing costs. Are you noticed any cost reduction?
I learn electronics in the late '70, and it still perfectly the same. The software of the '70 is dead, and every year there's something new to learn. It looks much more a consumistic- and frustrating-way to work.
That's my opinion, with respect of all of the readers/users/friends.

Analog sarcasm sensor going 1023 and critical!

"Analog" in which sense?...AnalogInput?...AnalogWhatEverElse? :P
Biggest fault of Netduino? It runs by electricity.




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.