16 channels, just a slight problem

hey all,

been working on getting the controller built, but obviously code is essential for anything to work like this.

i am just working on 80 potentiometers. but instead of having 64 going through just one channel, i am doing 16 channels per analog connection.
the multiplexers i am using are the 4051, although if i did have the 4067 [i think is what they are called] i would not have this sort of thing going on now

the one problem i am having is the code.
i can easily get the 8 channels working through a second 4051 connected to the first connected 4051, through y0, then from z to analog 0. but can not get the third multiplexer which will carry the next 8 channels to read in the first 4051.

had a search on the arduino forum, but had only found ones for the 4067. there were some on the 4051, but no results, from what i could see.

this is the code i am using.

much help would be gracious. i will be looking at doing this all weekend, and may figure it out. bit do need some help beforehand

thanks

lewis

byte data_in = 0;
byte data_send = 0;

int anPin = 0;

byte setPort = 0;

void setup() {
Serial.begin(9600);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
}
void loop() {
if(Serial.available() > 0) {
data_in = Serial.read();
if(data_in == 76) {
for(int i = 0; i <= 7; i ++)
{
setPort = i * 4;
PORTD = setPort;
data_send = analogRead(anPin) / 4;
Serial.print(data_send);
}
Serial.flush();
}
}
}

Do you have a schematic as to how you have your 4051 chips wired? Sparkfun makes an inexpensive board with the 4067 chip.

aye, had a look at the sparkfun board, but i have 25 4051's, so best to use them whilst i have them at hand, if you get me.

shit, dont have a schematic at hand of my design. BUT, the multiplexing pdf on the arduino forum is like what i have set-up, such as the z outputs for the second and third 4051, connect to the y0 and y1 of the first 4051, the z output of the first 4051 connected to the analog 0. so on and so forth.

also the the grounds and 5v are connected as is in the pdf.

Have you verified your hardware works by testing it while not connected to the arduino, or verified the approprriate arduino output pin is at +5v when expected?

Edit:do you have a link to the pdf you reference?

honestly, no.

how would i go about that?
dont mean for that to seem like a stupid question.

Wihout a schematic about all I can say is to trouble shoot it with a multimeter. With the multiplexer connected to the arduino, ensure a pot connected to the multipler point that isn't working is inputting ~+5v to the multiplexer. Then check the voltage at the control points on the multiplexer being supplied with +5v from the arduino to see if the points are actually being supplied. Then check the point where the multiplexer output connects to the arduino to see if there is the ~+5v on the point. Ensure all the chips and the arduino have a common ground.

thanks for that.
i will see about knocking up a schematic now, i have fritzing, which should do.

ok, here are 2 pictures. one of the schematic and one of the breadboard view. this is my first proper time on fritzing, so it does look a bit cack. but hopefully you get the picture [no pun intended]

i did not put in the pots, as they just made everything look harder to see what was going on. but the pots will go in the same way they go in through the multiplexing tutorial given in the arduino website

this multiplexing is just working through 16 channels per analog in, using 4051's

http://www.smokingbunny.co.uk/arduino/breadboard.png

http://www.smokingbunny.co.uk/arduino/schematic.png

many thanks

lewis

Your schematic is a little hard to look at for old eyes. Look at the schematics in the below discussion to see if you have something close to these. You can do like I did and modify these using MS paint. You might also do a board search for 4051 to see if there is a link to the schematic you used. If two of the three 4051 chips work, then the wiring or operating logic for the third ship probably needs to be looked at closely.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1227132571/22

aye, the schematic is not the greatest of drawings, but first time on fritzing.

anyhow, had a check on the page, and your diagram with the four 4051 is what i am looking at and tried to show on the schematic. the problem, is the code.

thanks for the page though...

gah, silly me.
you know when you look at something for so long you can not find what you are looking for.

anyhow, what i was looking for was pretty much right in front of me, but after making some food and having a break and some ghost in the shell, it just hit me. was a simple change of 7 to 15.
there still some minor noise, but none the less, 16 channels through one analog. now to expand it to 4 more channels with 16 for each.

anyhow, what i was looking for was pretty much right in front of me, but after making some food and having a break and some ghost in the shell

ghost in the shell? I followed everything up to this. What is ghost in the shell?

basically the future has people who are fully cybernetic, or half human half cyber. the ghosts are sort of like the soul of the person, or something very much like that. i cant fully remember, as it is the series and second movie i was watching.

it can make your mind bend a little bit to keep up with what they talk about, but great none-the-less. plus amazing animation.

glad too of made you confused with what i said. so its not just in public view that i can confuse people. :slight_smile:

lewis

gah, silly me.
you know when you look at something for so long you can not find what you are looking for.

anyhow, what i was looking for was pretty much right in front of me, but after making some food and having a break and some ghost in the shell, it just hit me. was a simple change of 7 to 15.

Its always good to move all your important parameters out of the body of the code and make them either #defines or parameters to a function, so that you can change them easily and so you change all the related ones in step. Try to always separate code from data, then the code is general purpose and contains fewer assumptions. All unchecked assumptions are bugs waiting to happen.

You might want to check you are calling pinMode for pins 5..7, not just 2..4, and rewriting the code as a single function that takes a channel number and returns an ADC value might be neater. You can then hide the details of addressing the multiplexors and choosing the analog pin within that one place.

thank you for the wise words.

the thing with arduino, or even max for that matter.
is that it can sometimes get to a point where you think on it too much and can not get any further. then the questions in the forums start and you either dont get an answer, or just chatter with no resolution.

its always a good thing to get away from the computer, the code, the patches and anything else for a few hours, cook something, eat something, any thing to get away. the ideas pour back with gusto :slight_smile:

lewis edwards

smokingbunny.co.uk