Pages: 1 [2]   Go Down
Author Topic: 4051 Multiplexer example code?  (Read 4452 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I will try the things you mentioned, and I'll let you know how it goes.

Thanks very much for all your help!
Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm interested, because I want to use this mux, but the sample code doesn't seem very complete... can you tell me how it works now and your current code?

Thanks!
« Last Edit: April 14, 2009, 08:46:48 am by tep » Logged

Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just in case anyone reading this needs more analog inputs, I thought I'd pass on a hint that I gleaned from the BeatBearing project in Make (Volume 17):

http://www.beatbearing.co.uk/

That device uses a HEF4067B analog multiplexer with 16 inputs.  It's a Philips (now NXP) part:

http://www.standardics.nxp.com/products/hef/datasheet/hef4067b.pdf

Has anyone used this chip in a similar circuit to the 4051 setup?
Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes : http://fluidforms.eu/de/CassiusHow.php
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't get any of this...
I want to read 25 LDR's but first I can't get it to read anything.

Here is how it is wired:

Code:
5V - LDR -|y0   s0|-  D5
          |y1   s1|-  D6
          |y2   s2|-  D7
          |y3     |
          |y4     |
          |y5     |
          |y6     |
          |y7    z|-  analogInPin

What am I doing wrong? And what is the correct code to read the inputs?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My previous post was completely wrong... following the arduino page I got this wiring:



with my own code:

Code:
int led = 11;    //just a led
int analogIn = 0;
float analogValue;

void setup() {
  pinMode(2, OUTPUT);    // s0
  pinMode(3, OUTPUT);    // s1
  pinMode(4, OUTPUT);    // s2
  
  Serial.begin(9600);
}

void loop () {
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  
  analogValue = analogRead(analogIn);
  analogValue = map(analogValue, 0, 1023, 255, 0);
  analogWrite(led, analogValue);
  Serial.println(analogValue);
}

It works!
(If you are not sure about what pins are where it is the same way up as the playground image.)
« Last Edit: January 08, 2010, 04:10:25 pm by evolutionxbox » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys, I'm using a couple of 4051's. Just wanted to be sure . . the 4051 GND,Vss,Vee and INH goes to the analog ground and so do the 5V pin of Arduino. Right? does it matter if I connect it to the digital ground of Arduino? Thanks ..
Logged

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Check this:

http://www.arduino.cc/playground/Learning/4051

Pins 6, 7 and 8 to ground


Connecting Arduinos 5V pin to ground sounds like a seriously poor idea.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i have a question about the 4051....

if i have 8 pots and run them thru the mux they go into the arduino via a single analog input pin ..... i got that much clear...

but what if i need each one of those pots to feed into 8 separate variables?

currently im doing something like this (not using a mux yet)

int pot1pin=1;
analogRead (pot1pin);

so how would this type of thing work with a mux?.... is it even possible to assign individual vars to each of the 8 pots?

thanks for the help

Mubo....





Logged

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

First you tell the 4051 which of it's inputs should be connected to it's output, then you use analogread. repeat 8 times. with 8 different variables.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33408
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
repeat 8 times. with 8 different variables.

Or the same variable as an array and just increment the array index.

like here:-
http://www.thebox.myzen.co.uk/Hardware/MIDI_Footsteps.html
« Last Edit: July 08, 2010, 07:03:48 am by Grumpy_Mike » Logged

Pages: 1 [2]   Go Up
Jump to: