FSR MATRIX 32 x 22 arduino/processing TEENSY 3.2

Status
Not open for further replies.

skytrek

New member
salut tous le mondes !
j'ai commencer un projet de FSR (force sensor resitor) matrix homemade 32 colonnes 22 lignes en ma basant sur un projet de 15 colonnes 15 lignes déjà existant et fonctionnelle.
voici le liens :https://www.instructables.com/O-mat/
j'ai modifier le code Arduino pour utiliser 4 16 channel analog multiplexer ( 2 remplit pour les colonnes (16+16 =32) et 2 pour les lignes (16 + 6 = 22 )) au mieux de 2 sur le projet initial.
s'agissant des colonnes tout marche super bien sur l'interface graphique processing (aussi modifier pour marcher en 32 x 22) mais pour les lignes tout marche sauf la dernière de chaque multiplexer (la 16eme et la 22eme) qui active tout l'autre multiplexer des lignes quand on appuis dessus(voir image ci dessous) quelqu'un pourrait t'il m'aider ?


text in english (google trad haha)


hello everybody!
I started a 32 column 22 row homemade matrix FSR (force sensor resitor) project based on an already existing and functional 15 column 15 row project.
here are the links: https://www.instructables.com/O-mat/
I modify the Arduino code to use 4 16 channel analog multiplexer (2 fills for columns (16 + 16 = 32) and 2 for rows (16 + 6 = 22)) to best of 2 on the initial project.
Regarding the columns everything works great on the processing graphical interface (also modify to work in 32 x 22) but for the lines everything works except the last of each multiplexer (the 16th and the 22th) which activates all the other rows multiplex when pressed (see image below) could someone help me?




Screenshot_3.png

Screenshot_1.png

voici mon montage électrique sur breadboard:


IMG_4452.jpg

IMG_4453.jpg

IMG_4455.jpg


voici mon code :
here is my code :

arduino :

PHP:
//Mux control pins for analog signal (SIG_pin) default for arduino mini pro
const byte s0 = 18;
const byte s1 = 19;
const byte s2 = 20;
const byte s3 = 21;
const byte s4 = 13;
const byte s5 = 14;
const byte s6 = 15;
const byte s7 = 16;

//Mux control pins for Output signal (OUT_pin) default for arduino mini pro
const byte w0 = 8; 
const byte w1 = 9;
const byte w2 = 10;
const byte w3 = 11;
const byte w4 = 3; 
const byte w5 = 4;
const byte w6 = 5;
const byte w7 = 6;


//Mux in "SIG" pin default for arduino mini pro 
const byte SIG_pin = 22;
const byte SIG_pin_1 = 17;  

//Mux out "SIG" pin default for arduino mini pro
const byte OUT_pin = 12;
const byte OUT_pin_1 = 7;

//Row and Column pins default for arduino mini pro
const byte STATUS_pin = 1;
const byte COL_pin = 0;

const boolean muxChannel[16][4]={
    {0,0,0,0}, //channel 0
    {1,0,0,0}, //channel 1
    {0,1,0,0}, //channel 2
    {1,1,0,0}, //channel 3
    {0,0,1,0}, //channel 4
    {1,0,1,0}, //channel 5
    {0,1,1,0}, //channel 6
    {1,1,1,0}, //channel 7
    {0,0,0,1}, //channel 8
    {1,0,0,1}, //channel 9
    {0,1,0,1}, //channel 10
    {1,1,0,1}, //channel 11
    {0,0,1,1}, //channel 12
    {1,0,1,1}, //channel 13
    {0,1,1,1}, //channel 14
    {1,1,1,1}  //channel 15
  };

//incoming serial byte
int inByte = 0;

int valor = 0;               //variable for sending bytes to processing
int calibra[22][32];         //Calibration array for the min values of each od the 225 sensors.
int minsensor=254;          //Variable for staring the min array
int multiplier = 254;
int pastmatrix[22][32];

void setup(){
    
  pinMode(s0, OUTPUT); 
  pinMode(s1, OUTPUT); 
  pinMode(s2, OUTPUT); 
  pinMode(s3, OUTPUT);
  pinMode(s4, OUTPUT); 
  pinMode(s5, OUTPUT); 
  pinMode(s6, OUTPUT); 
  pinMode(s7, OUTPUT); 
  
  pinMode(w0, OUTPUT); 
  pinMode(w1, OUTPUT); 
  pinMode(w2, OUTPUT); 
  pinMode(w3, OUTPUT);
  pinMode(w4, OUTPUT); 
  pinMode(w5, OUTPUT); 
  pinMode(w6, OUTPUT); 
  pinMode(w7, OUTPUT);
 
  
  pinMode(OUT_pin, OUTPUT);
  pinMode(OUT_pin_1, OUTPUT);
  
  pinMode(STATUS_pin, OUTPUT);
  pinMode(COL_pin, OUTPUT);

  
  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);
  digitalWrite(s4, LOW);
  digitalWrite(s5, LOW);
  digitalWrite(s6, LOW);
  digitalWrite(s7, LOW);
  
  digitalWrite(w0, LOW);
  digitalWrite(w1, LOW);
  digitalWrite(w2, LOW);
  digitalWrite(w3, LOW);
  digitalWrite(w4, LOW);
  digitalWrite(w5, LOW);
  digitalWrite(w6, LOW);
  digitalWrite(w7, LOW);
  
  digitalWrite(OUT_pin, HIGH);
  digitalWrite(OUT_pin_1, HIGH);
  digitalWrite(STATUS_pin, HIGH);
  digitalWrite(COL_pin, HIGH);
  
 
  
  Serial.begin(115200);
  
  Serial.println("\n\Calibrating...\n");
  
  // Full of 0's of initial matrix
  for(byte j = 0; j < 22; j ++){
    if (j < 16) 
      writeMux(j);
    else
      writeMux1(j-16);    
    for(byte i = 0; i < 32; i ++)
      calibra[j][i] = 0;
  }
  
  // Calibration
  for(byte k = 0; k < 50; k++){  
    for(byte j = 0; j < 22; j ++){ 
      if (j < 16) 
        writeMux(j);
      else
        writeMux1(j-16);
      for(byte i = 0; i < 32; i ++)
      {
        if (i < 16)
          calibra[j][i] = calibra[j][i] + readMux(i);
        else
          calibra[j][i] = calibra[j][i] + readMux1(i-16);
      }   
    }
  }
  
  //Print averages
  for(byte j = 0; j < 22; j ++){ 
    if (j < 16) 
      writeMux(j);
    else
      writeMux1(j-16);
    for(byte i = 0; i < 32; i ++){
      calibra[j][i] = calibra[j][i]/50;
      if(calibra[j][i] < minsensor)
        minsensor = calibra[j][i];
      Serial.print(calibra[j][i]);
      Serial.print("\t");
    }
  Serial.println(); 
  }
  
  Serial.println();
  Serial.print("Minimum Value: ");
  Serial.println(minsensor);
  Serial.println();
  
  establishContact();
 
  digitalWrite(COL_pin, LOW);
}


void loop(){
  //Loop through and read all 16 values
  //Reports back Value at channel 6 is: 346
  if (Serial.available() > 0){
    inByte = Serial.read();
    
    if(inByte == 'A'){
    
      for(int j = 0; j < 22; j++){ 
        if (j < 16) 
          writeMux(j);
        else
          writeMux1(j - 16);        
        for(int i = 0; i < 32; i++){
          if (i < 16)
            valor = readMux(i);
          else
            valor = readMux1(i-16);          
          
          //Saturation sensors
          int limsup = 450;
          if(valor > limsup)
            valor = limsup;
            
          if(valor < calibra[j][i])
            valor = calibra[j][i];  
          
          valor = map(valor,minsensor, limsup,1,254); 
          
          if(valor < 150)
            valor = 0;
          if(valor > 254)
            valor = 254;
          
          Serial.write(valor);
          digitalWrite(COL_pin,!digitalRead(COL_pin));
        } 
      }
    }
        
  }
}


int readMux(byte channel){
  byte controlPin[] = {s0, s1, s2, s3};

  //loop through the 4 sig
  for(int i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }

  //read the value at the SIG pin
  int val = analogRead(SIG_pin);

  //return the value
  return val;
}
int readMux1(byte channel){
  byte controlPin[] = {s4, s5, s6, s7};

  //loop through the 4 sig
  for(int i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }

  //read the value at the SIG pin
  int val = analogRead(SIG_pin_1);

  //return the value
  return val;
}

void writeMux(byte channel){
  byte controlPin[] = {w0, w1, w2, w3};

  //loop through the 4 sig
  for(byte i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }
}

void writeMux1(byte channel){
  byte controlPin[] = {w4, w5, w6, w7};

  //loop through the 4 sig
  for(byte i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }
}

void establishContact() {
  while (Serial.available() <= 0) {
    Serial.print('A');   // send a capital A
    delay(300);
  }
}

processing :

PHP:
// This example code is in the public domain.

import processing.serial.*;
import processing.opengl.*;


int bgcolor;                 // Background color
int fgcolor;                 // Fill color
Serial myPort;                       // The serial port
int[] serialInArray = new int[704];    // Where we'll put what we receive
int[] pastInArray = new int [704];
float[][] colorTarget   = new float[3][255];
float[][] currentColor   = new float[3][255];
PVector[][] vertices = new PVector[32][22];
float[] verticesTZ = new float[32];
float w = 22;
float ease = 0.75; 

int serialCount = 0;                 // A count of how many bytes we receive
int xpos, ypos;                  // Starting position of the ball
boolean firstContact = false;        // Whether we've heard from the microcontroller
int tiempoant;
int render=0;
int dif=0;

void setup() {
  size(960, 600, OPENGL);  // Stage size
  noStroke();      // No border on the next thing draw
  
  
  // Print a list of the serial ports, for debugging purposes:
  println(Serial.list());

  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  
  myPort = new Serial(this, Serial.list()[1], 115200);
  
  for (int j = 0; j < 22; j++) {
        for (int i = 0; i < 32; i++) {
            vertices[i][j] = new PVector( i*w, j*w, 0);
        }
    }
    
  
}

void draw() {

  if (render==1) {
    
    translate(75, 50);
    background(0);
    for (int j=0; j<22; j++) {
      for (int i=0; i<32; i++) {
          stroke(255);
          if(serialInArray[(j*32)+i] < 170){
            fill(0, serialInArray[(j*32)+i], 0);
          }
          if(serialInArray[(j*32)+i] < 200 && serialInArray[(j*32)+i] > 170){
            fill(0, 0, serialInArray[(j*32)+i]);
          }
          else {
            fill(serialInArray[(j*32)+i], 0, 0);
          }
          float x = i*width/36;
          float y = j*height/26;
          rectMode(CENTER);
          rect(x,y,w,w);
          stroke(255);
          fill(255,255,255);
          textSize(10);
          text(serialInArray[(j*32)+i],x-8,y+4);
        }
        //        println();
      }
      render=0;
  }
}

void serialEvent(Serial myPort) {
  // read a byte from the serial port:
  int inByte = myPort.read();
  // if this is the first byte received, and it's an A,
  // clear the serial buffer and note that you've
  // h
  //  ad first contact from the microcontroller. 
  // Otherwise, add the incoming byte to the array:
  if (firstContact == false) {
    if (inByte == 'A') { 
      myPort.clear();          // clear the serial port buffer
      firstContact = true;     // you've had first contact from the microcontroller
      myPort.write('A');       // ask for more
    }
  } else {
    // Add the latest byte from the serial port to array:

      serialInArray[serialCount] = inByte;
      println(inByte);

    serialCount++;

    // If we have 3 bytes:
    if (serialCount > 703 ) {
      println(millis()-tiempoant);
      tiempoant = millis();
      
      render = 1;
    
      // Send a capital A to request new sensor readings:
      myPort.write('A');
      // Reset serialCount:
      serialCount = 0;
    }
  }
}

voici les code originaux :
here is original code :

arduino modifier pour mes pin:

PHP:
//Mux control pins for analog signal (SIG_pin) default for arduino mini pro
const byte s0 = 18;
const byte s1 = 19;
const byte s2 = 20;
const byte s3 = 21;

//Mux control pins for Output signal (OUT_pin) default for arduino mini pro
const byte w0 = 3; 
const byte w1 = 4;
const byte w2 = 5;
const byte w3 = 6;

//Mux in "SIG" pin default for arduino mini pro 
const byte SIG_pin = 22; 

//Mux out "SIG" pin default for arduino mini pro
const byte OUT_pin = 7;

//Row and Column pins default for arduino mini pro
const byte STATUS_pin = 2;
const byte COL_pin = 1;

const boolean muxChannel[16][4]={
    {0,0,0,0}, //channel 0
    {1,0,0,0}, //channel 1
    {0,1,0,0}, //channel 2
    {1,1,0,0}, //channel 3
    {0,0,1,0}, //channel 4
    {1,0,1,0}, //channel 5
    {0,1,1,0}, //channel 6
    {1,1,1,0}, //channel 7
    {0,0,0,1}, //channel 8
    {1,0,0,1}, //channel 9
    {0,1,0,1}, //channel 10
    {1,1,0,1}, //channel 11
    {0,0,1,1}, //channel 12
    {1,0,1,1}, //channel 13
    {0,1,1,1}, //channel 14
    {1,1,1,1}  //channel 15
  };


//incoming serial byte
int inByte = 0;

int valor = 0;               //variable for sending bytes to processing
int calibra[15][15];         //Calibration array for the min values of each od the 225 sensors.
int minsensor=254;          //Variable for staring the min array
int multiplier = 254;
int pastmatrix[15][15];

void setup(){
    
  pinMode(s0, OUTPUT); 
  pinMode(s1, OUTPUT); 
  pinMode(s2, OUTPUT); 
  pinMode(s3, OUTPUT); 
  
  pinMode(w0, OUTPUT); 
  pinMode(w1, OUTPUT); 
  pinMode(w2, OUTPUT); 
  pinMode(w3, OUTPUT); 
  
  pinMode(OUT_pin, OUTPUT); 
  
  pinMode(STATUS_pin, OUTPUT);
  pinMode(COL_pin, OUTPUT);

  
  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);
  
  digitalWrite(w0, LOW);
  digitalWrite(w1, LOW);
  digitalWrite(w2, LOW);
  digitalWrite(w3, LOW);
  
  digitalWrite(OUT_pin, HIGH);
  digitalWrite(STATUS_pin, HIGH);
  digitalWrite(COL_pin, HIGH);
  
 
  
  Serial.begin(115200);
  
  Serial.println("\n\Calibrating...\n");
  
  // Full of 0's of initial matrix
  for(byte j = 0; j < 15; j ++){ 
    writeMux(j);
    for(byte i = 0; i < 15; i ++)
      calibra[j][i] = 0;
  }
  
  // Calibration
  for(byte k = 0; k < 50; k++){  
    for(byte j = 0; j < 15; j ++){ 
      writeMux(j);
      for(byte i = 0; i < 15; i ++)
        calibra[j][i] = calibra[j][i] + readMux(i);
    }
  }
  
  //Print averages
  for(byte j = 0; j < 15; j ++){ 
    writeMux(j);
    for(byte i = 0; i < 15; i ++){
      calibra[j][i] = calibra[j][i]/50;
      if(calibra[j][i] < minsensor)
        minsensor = calibra[j][i];
      Serial.print(calibra[j][i]);
      Serial.print("\t");
    }
  Serial.println(); 
  }
  
  Serial.println();
  Serial.print("Minimum Value: ");
  Serial.println(minsensor);
  Serial.println();
  
  establishContact();
 
  digitalWrite(COL_pin, LOW);
}


void loop(){
  //Loop through and read all 16 values
  //Reports back Value at channel 6 is: 346
  if (Serial.available() > 0){
    inByte = Serial.read();
    
    if(inByte == 'A'){
    
      for(int j = 14; j >= 0; j--){ 
        writeMux(j);
        
        for(int i = 0; i < 15; i++){
            
          valor = readMux(i);
          
          //Saturation sensors
          int limsup = 450;
          if(valor > limsup)
            valor = limsup;
            
          if(valor < calibra[j][i])
            valor = calibra[j][i];  
          
          valor = map(valor,minsensor, limsup,1,254); 
          
          if(valor < 150)
            valor = 0;
          if(valor > 254)
            valor = 254;
          
          Serial.write(valor);
          digitalWrite(COL_pin,!digitalRead(COL_pin));
        } 
      }
    }
        
  }
}


int readMux(byte channel){
  byte controlPin[] = {s0, s1, s2, s3};

  //loop through the 4 sig
  for(int i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }

  //read the value at the SIG pin
  int val = analogRead(SIG_pin);

  //return the value
  return val;
}

void writeMux(byte channel){
  byte controlPin[] = {w0, w1, w2, w3};

  //loop through the 4 sig
  for(byte i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }
}

void establishContact() {
  while (Serial.available() <= 0) {
    Serial.print('A');   // send a capital A
    delay(300);
  }
}

processing :

PHP:
// This example code is in the public domain.

import processing.serial.*;
import processing.opengl.*;


int bgcolor;                 // Background color
int fgcolor;                 // Fill color
Serial myPort;                       // The serial port
int[] serialInArray = new int[225];    // Where we'll put what we receive
int[] pastInArray = new int [225];
float[][] colorTarget   = new float[3][255];
float[][] currentColor   = new float[3][255];
PVector[][] vertices = new PVector[15][15];
float[] verticesTZ = new float[15];
float w = 30;
float ease = 0.75; 

int serialCount = 0;                 // A count of how many bytes we receive
int xpos, ypos;                  // Starting position of the ball
boolean firstContact = false;        // Whether we've heard from the microcontroller
int tiempoant;
int render=0;
int dif=0;

void setup() {
  size(960, 600, OPENGL);  // Stage size
  noStroke();      // No border on the next thing draw
  
  
  // Print a list of the serial ports, for debugging purposes:
  println(Serial.list());

  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  
  myPort = new Serial(this, Serial.list()[5], 115200);
  
  for (int j = 0; j < 15; j++) {
        for (int i = 0; i < 15; i++) {
            vertices[i][j] = new PVector( i*w, j*w, 0);
        }
    }
    
  
}

void draw() {

  if (render==1) {
    
    translate(width/4, 100);
    rotateX(0.5);
    //rotateX(PI/10);
    background(0);
    for (int j=0; j<14; j++) {
      beginShape(QUAD_STRIP);
      for (int i=0; i<15; i++) {
          stroke(255);
     
          fill(serialInArray[j*15+i], 0, 0);
          float x = i*width/15;
          float y = j*height/15;
          verticesTZ[i] = serialInArray[j*15+i];
          
          vertices[i][j].z += (verticesTZ[i]-vertices[i][j].z)*ease;
          vertex( vertices[i][j].x, vertices[i][j].y, vertices[i][j].z);
          vertex( vertices[i][j+1].x, vertices[i][j+1].y, vertices[i][j+1].z);
        }
         endShape(CLOSE);
        //        println();
      }
      render=0;
  }
}

void serialEvent(Serial myPort) {
  // read a byte from the serial port:
  int inByte = myPort.read();
  // if this is the first byte received, and it's an A,
  // clear the serial buffer and note that you've
  // h
  //  ad first contact from the microcontroller. 
  // Otherwise, add the incoming byte to the array:
  if (firstContact == false) {
    if (inByte == 'A') { 
      myPort.clear();          // clear the serial port buffer
      firstContact = true;     // you've had first contact from the microcontroller
      myPort.write('A');       // ask for more
    }
  } else {
    // Add the latest byte from the serial port to array:

      serialInArray[serialCount] = inByte;

    serialCount++;

    // If we have 3 bytes:
    if (serialCount > 224 ) {
      println(millis()-tiempoant);
      tiempoant = millis();
      
      render = 1;
    
      // Send a capital A to request new sensor readings:
      myPort.write('A');
      // Reset serialCount:
      serialCount = 0;
    }
  }
}

milles mercii !!!
 
Last edited:
Status
Not open for further replies.
Back
Top