Hey everyone! I am hoping you can help me.
I am currently working on a project where I am making a multiplexer controlled array of sensors that record pressure applied on a x/y co-ordinates of a multi-touch, pressure sensitive square grid. It stores the analog read value into an array, and with 32 rows and 32 columns crossing over each other, it is an int[32][32] array. The problem is, that when I make the array any bigger than int[10][32], my Teensy 3.1 stops working. I know this because the LED pin dies then and no more data is sent out of the Serial port.
Basically, four analog multiplexers (CMOS 16 channel MUX/DEMUX - CD74HC4067) are used to make the circuit. Two are used to power on/off rows and two are used to read the analog values of the columns. One row is turned on, the columns are read one by one and on completion the row is turned off. Then the next row is turned on and the process repeats until all rows/columns have been read. It simply does scanning for data. It then prints the full array out in a single line of Serial (I am looking for a better solution so I am open to suggestions).
I read this data back in MaxMSP so I can play around with sounds and visualizations. In fact, I thought the ideal way to handle the data would be as a greyscale 32x32 video feed but havent figured out how to get that to work.
So! the question is:
is my int[32][32] array too big for internal memory? too big for the Serial port? Am I missing something code-wise to make it work? and is there a way I can export an int[32][32] array as a video feed (that hopefully MaxMSP can understand)?
Thanks so much for any help!
Code:
I am currently working on a project where I am making a multiplexer controlled array of sensors that record pressure applied on a x/y co-ordinates of a multi-touch, pressure sensitive square grid. It stores the analog read value into an array, and with 32 rows and 32 columns crossing over each other, it is an int[32][32] array. The problem is, that when I make the array any bigger than int[10][32], my Teensy 3.1 stops working. I know this because the LED pin dies then and no more data is sent out of the Serial port.
Basically, four analog multiplexers (CMOS 16 channel MUX/DEMUX - CD74HC4067) are used to make the circuit. Two are used to power on/off rows and two are used to read the analog values of the columns. One row is turned on, the columns are read one by one and on completion the row is turned off. Then the next row is turned on and the process repeats until all rows/columns have been read. It simply does scanning for data. It then prints the full array out in a single line of Serial (I am looking for a better solution so I am open to suggestions).
I read this data back in MaxMSP so I can play around with sounds and visualizations. In fact, I thought the ideal way to handle the data would be as a greyscale 32x32 video feed but havent figured out how to get that to work.
So! the question is:
is my int[32][32] array too big for internal memory? too big for the Serial port? Am I missing something code-wise to make it work? and is there a way I can export an int[32][32] array as a video feed (that hopefully MaxMSP can understand)?
Thanks so much for any help!
Code:
Code:
//Mux control pins (Analog Sensing)
int E1_Analog = 8; //A
int E2_Analog = 7; //B
int E3_Analog = 6; //C
int E4_Analog = 5; //D
int F1_Analog = 4; //A
int F2_Analog = 3; //B
int F3_Analog = 2; //C
int F4_Analog = 1; //D
// Mux control pins (Digital Controling)
int G1_Digital = 13; //A
int G2_Digital = 14; //B
int G3_Digital = 16; //C
int G4_Digital = 15; //D
int H1_Digital = 9; //A
int H2_Digital = 10; //B
int H3_Digital = 12; //C
int H4_Digital = 11; //D
// Mux "SIG" pin - The single pin that reads or writes a value to the other 16 pins
int SIG_pin_Analog_E = A8;
int SIG_pin_Analog_F = A9;
// Holds the Array of data gathered
// columns are digital and rows are analog reading
const int Grid_Analog_Half = 32;
const int Grid_Digital = 32;
int pinRowColumn[Grid_Analog_Half][Grid_Digital] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
// Accelerometer info
const int ypin = A3; // y-axis
const int xpin = A4; // x-axis
//#define CPU_8MHz 0x01
void setup(){
// Analog (Scanning) Pins setup
pinMode(E1_Analog, OUTPUT);
pinMode(E2_Analog, OUTPUT);
pinMode(E3_Analog, OUTPUT);
pinMode(E4_Analog, OUTPUT);
pinMode(F1_Analog, OUTPUT);
pinMode(F2_Analog, OUTPUT);
pinMode(F3_Analog, OUTPUT);
pinMode(F4_Analog, OUTPUT);
// Digital (Controling) Pins setup
pinMode(G1_Digital, OUTPUT);
pinMode(G2_Digital, OUTPUT);
pinMode(G3_Digital, OUTPUT);
pinMode(G4_Digital, OUTPUT);
pinMode(H1_Digital, OUTPUT);
pinMode(H2_Digital, OUTPUT);
pinMode(H3_Digital, OUTPUT);
pinMode(H4_Digital, OUTPUT);
// Initiate
digitalWrite(E1_Analog, LOW);
digitalWrite(E2_Analog, LOW);
digitalWrite(E3_Analog, LOW);
digitalWrite(E4_Analog, LOW);
digitalWrite(F1_Analog, LOW);
digitalWrite(F2_Analog, LOW);
digitalWrite(F3_Analog, LOW);
digitalWrite(F4_Analog, LOW);
digitalWrite(G1_Digital, LOW);
digitalWrite(G2_Digital, LOW);
digitalWrite(G3_Digital, LOW);
digitalWrite(G4_Digital, LOW);
digitalWrite(H1_Digital, LOW);
digitalWrite(H2_Digital, LOW);
digitalWrite(H3_Digital, LOW);
digitalWrite(H4_Digital, LOW);
Serial.begin(115200);
}
void loop(){
// Turn on each Digital pin individually to measure each analog row
// e.g. D0 = HIGH, measure all analog. Then D1 = HIGH, measure all analog... etc
// Scanning
for (int i = 0; i < Grid_Digital; i++) { //32
writeMuxDigital(i);
if ((i % 2) == 1) {
for (int j = 0; j < Grid_Analog_Half; j++) { //16
pinRowColumn[j][i] = readMuxAnalog(j*2); // times 2 so that all even ports are selected.
}
}
else {
for(int j = 0; j < Grid_Analog_Half; j++) { //16
pinRowColumn[j][i] = readMuxAnalog((j*2)+1); // times 2 +1 so that all odd ports are selected.
}
}
}
// Package BEGIN Check Values
Serial.print("233 0 233 ");
// Send one packet of Data over Serial.
for(int i = 0; i < Grid_Digital; i++) {
for (int j = 0; j < Grid_Analog_Half; j++) {
Serial.print(pinRowColumn[j][i]);
Serial.print(" ");
}
}
// Acclerometer data X & Y
Serial.print(analogRead(xpin));
Serial.print(" ");
Serial.print(analogRead(ypin));
// Package END Check Values
Serial.println(" 244 0 244");
delay(20);
}
int readMuxAnalog(int channel){
int controlPin_E[] = {E1_Analog, E2_Analog, E3_Analog, E4_Analog};
int controlPin_F[] = {F1_Analog, F2_Analog, F3_Analog, F4_Analog};
int muxChannel[16][4]={
{LOW, LOW, LOW, LOW}, //channel 0
{HIGH,LOW, LOW, LOW}, //channel 1
{LOW, HIGH,LOW, LOW}, //channel 2
{HIGH,HIGH,LOW, LOW}, //channel 3
{LOW, LOW, HIGH,LOW}, //channel 4
{HIGH,LOW, HIGH,LOW}, //channel 5
{LOW, HIGH,HIGH,LOW}, //channel 6
{HIGH,HIGH,HIGH,LOW}, //channel 7
{LOW, LOW, LOW,HIGH}, //channel 8
{HIGH,LOW, LOW,HIGH}, //channel 9
{LOW, HIGH,LOW,HIGH}, //channel 10
{HIGH,HIGH,LOW,HIGH}, //channel 11
{LOW, LOW,HIGH,HIGH}, //channel 12
{HIGH,LOW,HIGH,HIGH}, //channel 13
{LOW,HIGH,HIGH,HIGH}, //channel 14
{HIGH,HIGH,HIGH,HIGH} //channel 15
};
//loop through the 4 SIG pins to program Multiplexer
for(int i = 0; i < 4; i ++){
if (channel < (Grid_Analog_Half/2)) {
digitalWrite(controlPin_E[i], muxChannel[channel][i]);
}
else {
digitalWrite(controlPin_F[i], muxChannel[channel][i]);
}
}
//read the value at the SIG pin
//return the value
if (channel < (Grid_Analog_Half/2)) {
int val = analogRead(SIG_pin_Analog_E);;
val = val/4; // scales 1024 to 256
return val;
}
else {
int val = analogRead(SIG_pin_Analog_F);
val = val/4; // scales 1024 to 256
return val;
}
}
int writeMuxDigital(int channel){
int controlPin_G[] = {G1_Digital, G2_Digital, G3_Digital, G4_Digital};
int controlPin_H[] = {H1_Digital, H2_Digital, H3_Digital, H4_Digital};
int muxChannel[16][4]={
{LOW, LOW, LOW, LOW}, //channel 0
{HIGH,LOW, LOW, LOW}, //channel 1
{LOW, HIGH,LOW, LOW}, //channel 2
{HIGH,HIGH,LOW, LOW}, //channel 3
{LOW, LOW, HIGH,LOW}, //channel 4
{HIGH,LOW, HIGH,LOW}, //channel 5
{LOW, HIGH,HIGH,LOW}, //channel 6
{HIGH,HIGH,HIGH,LOW}, //channel 7
{LOW, LOW, LOW,HIGH}, //channel 8
{HIGH,LOW, LOW,HIGH}, //channel 9
{LOW, HIGH,LOW,HIGH}, //channel 10
{HIGH,HIGH,LOW,HIGH}, //channel 11
{LOW, LOW,HIGH,HIGH}, //channel 12
{HIGH,LOW,HIGH,HIGH}, //channel 13
{LOW,HIGH,HIGH,HIGH}, //channel 14
{HIGH,HIGH,HIGH,HIGH} //channel 15
};
//loop through the 4 SIG pins to program Multiplexer
for(int i = 0; i < 4; i ++){
if (channel < (Grid_Digital/2)) {
digitalWrite(controlPin_G[i], muxChannel[channel][i]);
}
else {
digitalWrite(controlPin_H[i], muxChannel[channel][i]);
}
}
}
Last edited: