Hello ello,
i’m a relative newbie to the arduino environment, and although I have a lot of patience with programming, i’ve come to a dead end after a lot of work (almost done though!).
I’m using a multiplexer with 6 piezo pins connected to analog 0, and then 3 more piezo’s connected to 1, 3 and 4. So I’m using 9 sensors in total.
I need to make the piezo’s values print to the serial ‘matrix style’ in rows, so that max/msp can read it successfully.
Max reads the information fine (and the serial monitor is understandable) when it’s just the multiplexer data being sent, or alternatively, just when the analog pins 1, 3 and 4 are enabled, but as soon as I try and compile the two together it doesn’t work, and the serial monitor goes into overdrive :S
I have tried adding delays into the code (maybe something to do with the different resolutions is messing with it???), testing different Serial.print options and placing the data in different parts of the sketch but nothing else I can think of is working
any help or advice would be masssssively appreciated!
/*
* code example for using a 4051 * analog multiplexer / demultiplexer
* by david c. and tomek n.* for k3 / malm? h?gskola
* modifications by Richard Hoadley & mr osborn
*
*
*/
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; // storing the bin code
int count = 0; // just a count
int bin [] = {000, 1, 10, 11, 100, 101, 110, 111};//bin = bin?r, some times it is so easy
int val = 0; // storage
int val1 = 0; // storage 2 if needs be
void setup(){
// (upload = dev/tty.usbserial-A600bRNW);
pinMode(2, OUTPUT); // s0
pinMode(3, OUTPUT); // s1
pinMode(4, OUTPUT); // s2
digitalWrite(led, HIGH);
// Serial.begin(9600);
Serial.begin(115200);
}
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]);
// ANALOG PINS 1, 3 and 4 in use, 2 & 5 grounded
{
val = analogRead(1);
// Serial.print("x1 "); // analog pin 1 ( X1)
Serial.print(val);
Serial.print("\t");
}
{
val = analogRead(2);
// Serial.print("x2: "); // analog pin 2 nothing (grounded)
Serial.print(val);
Serial.print("\t");
}
{
val = analogRead(3);
// Serial.print("x3: "); // analog pin 3 ( X3)
Serial.print(val);
Serial.print("\t");
}
{
val = analogRead(4);
// Serial.print("x3: "); // analog pin 4 ( X2)
Serial.print(val);
Serial.print("\t");
}
{
val = analogRead(5);
// Serial.print("x3: "); // analog pin 5 (grounded again)
Serial.print(val);
Serial.print("\t");
// Serial.println( );
}
// MUX PINS 0 - 5 in use, 6 & 7 just to ground
// int bin [] = {000, 1, 10, 11, 100, 101, 110, 111};
// yo, y1, y2, y3, y4, y5, y6, y7
if ( bin[count] == 000 ) // yo
{
val = analogRead(0);
// Serial.println("y0 ");
Serial.print(val);
Serial.print("\t");
}
if ( bin[count] == 1 ) // y 1
{
val = analogRead(0);
//Serial.println("y1 ");
Serial.print(val);
Serial.print("\t");
}
if ( bin[count] == 10 ) // y2
{
val = analogRead(0);
// Serial.println("y2 ");
Serial.print(val);
Serial.print("\t");
}
if ( bin[count] == 11 ) // y3
{
val = analogRead(0);
// Serial.println("y3 ");
Serial.print(val);
Serial.print("\t");
}
if ( bin[count] == 100 ) // y4
{
val = analogRead(0);
// Serial.println("y4 ");
Serial.print(val);
Serial.print("\t");
}
if ( bin[count] == 101 ) // y5
{
val = analogRead(0);
// Serial.println("y4 ");
Serial.print(val);
Serial.print("\t");
}
if ( bin[count] == 110 ) // y6 nothing, groundead
{
val = analogRead(0);
// Serial.println("y4 ");
Serial.print(val);
Serial.print("\t");
}
if ( bin[count] == 111 ) // y7 nothing, grarnded
{
val = analogRead(0);
// Serial.println("y5 ");
Serial.print(val);
Serial.print("\t");
Serial.println();
}
// int bin [] = {000, 1, 10, 11, 100, 101, 110, 111};
// yo, y1, y2, y3, y4, y5, y6, y7
{
delay (4);
} // end of for
} // end of loop
}