multiplexing and max/msp ? a survey

right on man? have poke roll for me ;] i think im gonna quit for the night too. hopefully we can get this crap rolling soon.

hmm what makes you think that the 9600 baud was incorrect. i really have no idea what it should be if thats wrong. i basically just copy pasted the text from the tutorial.

however that said, when i uncommented the this line:
Serial.println(bin[count]); in the serial inspecting window i did get it counting 0 1 10 100 101 110 111 etc.

Lastly i moved the jumpers from the 4051 to only occupy d2 d3 and d4 so that way no more unplugging and plugging back in every time i reprogram the arduino. it also seem according to this code that 2 3 and 4 are the ones hes calling as per this line

  pinMode(2, OUTPUT);    // s0
  pinMode(3, OUTPUT);    // s1
  pinMode(4, OUTPUT);    // s2

hmm what makes you think that the 9600 baud was incorrect.

Like I said, check the reference... there is no "beginSerial" command.

file://localhost/Applications/arduino-0009/reference/Serial_Begin.html

D

whoops. sorry. hopefully this isn't way more hand holding than you counted on? i'm just hoping i haven't bit off more than i can chew. switched that code out. but in looking at the code i don't think there is anything to tell the arduino.app to read the pins when a pots values change. now this is the part i'm confused about do i use an analog read http://www.arduino.cc/en/Reference/AnalogRead which would only check the values coming out of the 4051 into the a0 port. or do i read all the values from the digital pins ? http://www.arduino.cc/en/Reference/DigitalRead. seems like analog since the digital pins are all 1/0 rather than variable.

thanks again for all your help i really do appreciate it. and i think if we get this thing rolling it could serve as a rad tutorial for other folks step by step wise.

hmm

sounds like more work than I have time for, but maybe someone else will jump in here and help you with that part?

D

right on. thanks for your help thus far. to anyone else on the radar heres the code i have running now:

/*
 * codeexample for useing a 4051 * analog multiplexer / demultiplexer
 * by david c. and tomek n.* for k3 / malmö högskola
 *
 */  

int led = 13; //just a led
int r0 = 0; //value select pin at the 4051 (s0)
int r1 = 0; //value select pin at the 4051 (s1)
int r2 = 0; //value select pin at the 4051 (s2)
int row = 0; // storeing the bin code
int count = 0; // just a count

int analogPin = 0;
int val = 0;   // variable to store the read value
int threshold = 512;   // threshold 

int bin [] = {000, 1, 10, 11, 100, 101, 110, 111};//bin = binär, some times it is so easy

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


}

void loop () {

  for (count=0; count<=7; count++) {
    row = bin[count];      
    r0 = row & 0x01;
    r1 = (row>>1) & 0x01;
    r2 = (row>>2) & 0x01;
    digitalWrite(2, r0);
    digitalWrite(3, r1);
    digitalWrite(4, r2);
    //Serial.println(bin[count]);
    delay (100);
    
    val = analogRead(analogPin);   // read the input pin
  if (val >= threshold) {
    Serial.print(val, DEC);
  } else {
    Serial.print("off ");
  }
    
  }  

}

currently it checks the pot to see if its been moved about half way and then it prints the value. otherwise it prints "off" what i need to figure out how to do is get ti to cycle through all the different ports and read out the values individually. im also beginning to think that maybe having the arduino spit out midi itself is a better way to go than have max read the pots and then translate it to midi. this might even be a faster application?

any thoughts on this are welcome in the mean time ill trudge forward.

Hi, got mine from maplin ( HEF 4051 BP ).
At first I tried to follow your pictures and the tutorial but I was confused.
Your pictures relate to the right hand diagram from the tutorial ( logic symbol ). That's what confused me.
I followed the left hand diagram ( pin configuration ) and only the tutorial and now it works like a charm.
Obviously I had to had a analogueRead to read the thing. I think all your trouble scared me :stuck_out_tongue:

Daniel:
I don't understand why the tutorial as a beginSerial instead of the Serial.begin. Is it because of a old version, or the code is for wiring?
And I didn't use any capacitor.

Tomorrow I will try to adapt the capacitive thing to the multiplex.

Do you think that one of us should do a simple tutorial with pictures on how to wire a multiplex and rewrite the code so it actually do something when the arduino is wired properly. I am happy to do it, but I won't do it directly as I have lot of work. I still don't know what pin 6 and 7 (E and Vee) are for, ground access ?

wow thats awesome that you have had so much success? my problems stem strictly from the fact that i am learning all this stuff as i go. if you post your solution for mulitplexing that i can follow i will happily document it and post it. i have alot of work to do too? but frankly this is more fun :wink:

edit: i should mention i did get it working to a degree? i just have no idea how to get the data out of arduino into something useful like max or even midi.

ACTUALLY: could you show me what your analog read looks like? Im mostly curious how you are separating the different inputs since they are all coming in on the same analog input.

Oh I wasn't trying to show of. I am also learning as I am doing it. I think I am so happy to have this working that I had to say it.
It's really a pain when you are a newbee like me and you don't have any pictures to look at in a tutorial. I think I will take the time to do a small one with picts.

Making it talk to Max is also my next step after the capacitive thing. I hope I will be as lucky. Your midi idea might be a good one actually.
Are you going to try with this tutorial ?
http://itp.nyu.edu/physcomp/Labs/MIDIOutput

perhaps. this one is exactly what im doing pretty much. although i want to add a few digital switches in order to change the midi channel

honestly i would rather do all that with software. having to power the board external and have a midi interface seems like a waste of space when the arduino is capable of that itself?

oh but please do share your code. i would love to see what you have rolling.

Daniel? you may be fed up with my lameness by now but if you so happen to be looking to this thread at all do you (or anyone else) have any idea why this code would produce nothing in max?

/*  
 *  Arduino2Max w/ 4051
 *  Send pin values from Arduino to MAX/MSP
 *  
 *  Arduino2Max.pde
 *  ------------  
 *  Latest update: September 2007
 *  ------------
 *  Copyleft: use as you like
 *  by djmatic 
 *  Based on a sketch and patch by Thomas Ouellet Fredericks  tof.danslchamp.org
 *  
 */


int x = 0; // a place to hold pin values

int bin [] = {000, 1, 10, 11, 100, 101, 110, 111}; //bin = binär, some times it is so easy

int r0 = 0; //value select pin at the 4051 (s0)
int r1 = 0; //value select pin at the 4051 (s1)
int r2 = 0; //value select pin at the 4051 (s2)

int row = 0; // storeing the bin code
int count = 0; // just a count

int analogPin = 0;
int threshold = 25;   // threshold 

void setup()
{
  Serial.begin(115200);          // 115200 is the default Arduino Bluetooth speed
  digitalWrite(13,HIGH);       ///startup blink
  delay(600);
  digitalWrite(13,LOW);
  pinMode(13,INPUT);
  
  pinMode(2, OUTPUT);    // s0
  pinMode(3, OUTPUT);    // s1
  pinMode(4, OUTPUT);    // s2
}


void loop()
{ 

if (Serial.available() > 0){         // Check serial buffer for characters
        
    if (Serial.read() == 'r') {       // If an 'r' is received then read the pins
      
    // your code goes here. This is where you would prep the data 
    // by reading it with the 4051 etc.  
    
      for (count=0; count<=7; count++) {
    row = bin[count];      
    r0 = row & 0x01;
    r1 = (row>>1) & 0x01;
    r2 = (row>>2) & 0x01;
    digitalWrite(2, r0);
    digitalWrite(3, r1);
    digitalWrite(4, r2);
    //Serial.println(bin[count]);
    delay (5);
  }  
    x = analogRead(analogPin);
    sendValue (x);                    // this is the statement to send data to Max
  
    Serial.println();                 // Send a carriage returnt to mark end of pin data. 
    delay (5);                        // add a delay to prevent crashing/overloading of the serial port
  
  }

 }
}

void sendValue (int x){              // function to send the pin value followed by a "space". 
 Serial.print(x);
 Serial.print(32, BYTE); 
}

Hey Boli,
I got your comment on my blog regarding the multiplexing. I have not been following this thread, so I don't know exactly what has been happening. However, I have implemented a simple sketch / patch / breadboard combo of multiplexing two 4051s into the Arduino and reading the data in Max/MSP. I am assuming that this is something similar as to what you were asking.

Anyway, you can see what i have done so far in a very simple example with 2 4051s. But i have to run off to work now, so i'm afraid that is it for a while from me at least. But i will be back - hopefully whip up slightly better code etc.

You can see the very basic example here: little-scale: Multiplexy

wow your example looks really good. i may try to wire that up tomorrow. thanks for you help in advance!

just wanted to say i got this up and running in about 20 minutes. thanks so much! any improvements to the code would be super appreciated as well. for now i dont particularly understand how its working haha!

Unfortunately i get the usual flutter from the pots i may put something in the software to smooth that out not sure just yet? i'm already rolling with a 10K resistor on my pot. maybe each port needs a resistor regardless of whether its in use or not.

maybe i got a bit over zealous but i went ahead and built this up on perf board since the bread board version was working so well. i finally understand what you mean by:

a good idea might be to at least incorporate some sort of request byte from the host computer for each packet of 16 bytes received from the Arduino.

this threw me for a loop for a while, i'm looking at the arduini2max patch now to see how it sends those requests and if any of it is relevant.

here is a pic of my board setup:

and one of it working in MAX

hey little-scale i tried setting up the midi example you have here on your site:

the autonomous midi one? but i had no luck i'm just curious but is there a difference between the 4051N and the 4051BP? It doesn't really matter I was just exploring the possibility of doing an autonomous midi version.

ok this is just a comment before i consider this thread dead. i gues everyone lost interest and i dont blame em' but by colluding together several examples on little-scale.com i came up with the following code:

/*
8 to 1 mux
by Sebastian Tomczak
8 June 2007
Adelaide, Australia
//////
Modified by Seth Ferris
29 Sept 2007
*/

// init serial values
byte data_in = 0; // stores incoming byte
byte data_send = 0; // stores outgoing byte
int anPin = 0; // set analog pin

// setup begins here
void setup() {
Serial.begin(57600); // open serial port
DDRD = B00011110;
}

// main program begins here
void loop() {
if(Serial.available() > 0) { // if there is a byte received on RX...
data_in = Serial.read(); // read into variable
if(data_in == 76) { // if the received byte is 76 ("L" is for Listen to Arduino)...

      for(int anPin = 0; anPin < 16; anPin++) {

      PORTD = (anPin % 8) << 2;

      data_send = (analogRead(anPin / 8)) / 4;

      Serial.print(data_send);
      delay(5);
}
Serial.flush();
}
}
}

and it works great with this patch i whipped up again based on little scale and arduino2max:

the only issue is that for whatever reason my pot is still being read on port 3 when it should be read on port 2? its is consistently wrong as opposed before when it would change ports based on where in the loop it started reading the data.

if anyone sees the flaw in my code i would greatly appreciate the input otherwise i only get 15 pots instead of 16! thanks again for everyone's help up to now.

im and idiot i fullt misunderstood the wiring diagram? LAME.

analog sensors 1- 8 (eg. pots, LDRs, etc etc) to pins 13, 14, 15, 12, 1, 5, 2, 4

hence why the "second slot" is reading in the third space the second slot is actually port 15 DUH. thanks again folks.

That's a nice example!

however, it seems that it is possible to send an 8 bit value. Thus, you can have a range from 0 - 255.
I's wondering if anyone knows how you can get a full 10 bit resolution (0-1023)..

thanks

Hey, i was just wondering if there has been any success in 2 years haha.

Im attempting pretty much the same, but the issue i have atm (i can read all my Mux data into max) is reading the pins in order.
For example, if i set my pot to be the first interger and therefore first in the unpacked data, after i reset my arduino it moves from that position and needs to be re-calibrated. is there a way to read each pin in a loop?

sorry if this doesn't make sence, brains turning to mush.

cheers though!
patch