Tried the way you mentioned, it is working fine. I think esp32 will be better option for me.
I got your point.
When i go for 64*64 pins, i need at least 14 pins to control the 4 (32:1) mux, 2 (2:1) mux. Can it be possible with esp32
This is now a paid project, see:
This one closed. If anyone really wants to continue helping here knowing there's a paid topic open for this project then send me a PM.
Thank you.
I have a capacitive sensing matrix in 6464 ( 4096 sensors). I have placed these sensors in 64 columns and 64 rows (128 lines total). The 64 rows are controlled by two 32:1 muxs and the output of these mux goes into 2:1 mux. Similarly, another 64 columns are controlled by two 32:1 mux, and the output of these mux goes into a 2:1 mux. The output of both of these 2:1 mux goes into the Capacitive to digital converter chip, that communicates with arduino using i2c communication protocol. I have developed the code for 6464. But i have been able to test only for 1616. Bcoz in moving to 3232, it requires more memory which arduino does have. I further need to move to 64*64 now. I have written code for this as well. I need help in two things:
- I need 14 digital signals to control multiplxers. Which microcontroller should i use which can be programmed with arduino ide and has sufficient memory
- Fine tunning the already developed code, help it making more efficeint..
Here is my circuitry and code:
#include <Wire.h> //I2C library
double capacitance = 0; // Capacitance reading
int DataReady = B0000; //
const int rowControlPins[] = {3, 4, 5, 6, 7}; // Control pins for the row multiplexer
const int colControlPins[] = {9, 10, 11, 12, 13}; // Control pins for the column multiplexer
void setup() {
Serial.begin(9600);
Wire.begin();
// Set control pins as outputs
for (int i = 0; i < sizeof(rowControlPins) / sizeof(rowControlPins[0]); i++) {
pinMode(rowControlPins[i], OUTPUT);
}
for (int i = 0; i < sizeof(colControlPins) / sizeof(colControlPins[0]); i++) {
pinMode(colControlPins[i], OUTPUT);
}
}
void loop() {
double capacitanceValues[32][32] = {0}; // Initialize all values to 0
for (int row = 0; row < 32; row++) { // Loop through rows
activateRow(row);
delay(15); // Allow time for the row to be activated
for (int col = 0; col < 32; col++) { // Loop through columns
activateColumn(col);
delay(15); // Allow time for the column to be activated
// Read capacitance
capacitance = readCapacitance();
}
}
}
// Print capacitance values in matrix form
Serial.println("Capacitance Matrix:");
for (int row = 0; row < 32; row++) {
for (int col = 0; col < 32; col++) {
Serial.print(capacitanceValues[row][col], 1); // Print capacitance values with 1 decimal place
Serial.print("\t"); // Add tab for spacing
}
Serial.println(); // Move to the next line after printing each row
}
// Delay before next loop
delay(15); // Adjust this delay as needed
}
void activateRow(int row) {
// Iterate through each control pin for the row multiplexer
for (int i = 0; i < sizeof(rowControlPins) / sizeof(rowControlPins[0]); i++) {
digitalWrite(rowControlPins[i], bitRead(row, i)); // Set control pin to the corresponding bit of the row number
}
}
void activateColumn(int col) {
// Iterate through each control pin for the column multiplexer
for (int i = 0; i < sizeof(colControlPins) / sizeof(colControlPins[0]); i++) {
digitalWrite(colControlPins[i], bitRead(col, i)); // Set control pin to the corresponding bit of the column number
}
}
double readCapacitance() {
// Read the status of the AD7746
byte status = statusRead();
// If the capacitive conversion has been completed
if ((status & DataReady) == DataReady) {
// Read capacitance data from AD7746 registers
double capacitanceValue = dataRead();
return capacitanceValue;
// } else {
// Serial.println("Error: Capacitive conversion not complete");
// return -1; // Indicate failure to read capacitance
// }
}
}
When last we heard about this, the subject code and design were supersecret, couldn't be shared. I'm presuming that has changed, and you're now interested in free help? Suggestion. Your code doesn't compile. Please edit it to remove extraneous fluff, or at least put it in /**/, and present a compile-able starting point, along with a list of deficiencies you think need correcting.
We will no doubt come up with deficiencies of our own, as well as suggestions. It's not clear whether this is 1/10 of what you intend to do, or 99%.
The problem was that I was not alone in working on it. Had to discuss it with the team. Got their nod to post it.
Sorry for that.
Thanks for the suggestion. I will remove the extraneous fluff and provide it in a better form.
You had one too many } in your code, probably a cut and paste error.
See what you think of this. Obviously you still have two functions to flesh out.
Please note the change in baud rate; use the same in Serial Monitor. Depending on your processor, you may need to optimize this differently. Read through the comments.
#include <Wire.h> //I2C library
byte DataReady = B0000; //
//pick one row set
//const int rowControlPins[] = {3, 4, 5, 6, 7}; // Control pins for the row multiplexer
//const int rowControlPins[] = {3, 4, 5, 6}; // Control pins for the row multiplexer
//const int rowControlPins[] = {3, 4, 5}; // Control pins for the row multiplexer
const int rowControlPins[] = {3, 4}; // Control pins for the row multiplexer
const int rowpins = sizeof(rowControlPins) / sizeof(rowControlPins[0]);
const int maxrow = 1 << rowpins;
//pick one column set
//const int colControlPins[] = {9, 10, 11, 12, 13}; // Control pins for the column multiplexer
//const int colControlPins[] = {9, 10, 11, 12}; // Control pins for the column multiplexer
//const int colControlPins[] = {9, 10, 11}; // Control pins for the column multiplexer
const int colControlPins[] = {9, 10}; // Control pins for the column multiplexer
const int colpins = sizeof(colControlPins) / sizeof(colControlPins[0]);
const int maxcol = 1 << rowpins;
// mutable data
double capacitance = 0; // Capacitance reading
double capacitanceValues[maxrow][maxcol] = {0}; // Initialize all values to 0; array could be large, compile may fail depending on processor
//delays
const int startPause = 2000;//wait at end of setup
const int rowDelay = 0;//may as well be 0, it's always followed by a columnDelay
const int columnDelay = 1;
const int loopDelay = 200;//throttles data going to Serial; In the present format, Serial will be your bottleneck
//Your data values will likely determine your transmission bottleneck. Do the math!
void setup() {
Serial.begin(1000000);//pushing a lot of data as ASCII needs SPEED; Set Serial Monitor the same
Wire.begin();
// Set control pins as outputs
for (int i = 0; i < rowpins; i++) {
pinMode(rowControlPins[i], OUTPUT);
}
for (int i = 0; i < colpins ; i++) {
pinMode(colControlPins[i], OUTPUT);
}
Serial.print("Hello! Scanning "); Serial.print(maxrow); Serial.print(" rows by "); Serial.print(maxcol); Serial.println(" columns");
delay(startPause);
}
void loop() {
for (int row = 0; row < maxrow; row++) { // Loop through rows
activateRow(row);
if (rowDelay > 0) delay(rowDelay); // Allow time for the row to be activated
for (int col = 0; col < maxcol; col++) { // Loop through columns
activateColumn(col);
if (columnDelay > 0) delay(columnDelay); // Allow time for the column to be activated
// Read capacitance
capacitanceValues[row][col] = readCapacitance();
}
}
// Print capacitance values in matrix form
Serial.println("Capacitance Matrix:");
for (int row = 0; row < maxrow; row++) {
for (int col = 0; col < maxcol; col++) {
Serial.print(capacitanceValues[row][col], 1); // Print capacitance values with 1 decimal place
Serial.print("\t"); // Add tab for spacing
}
Serial.println(); // Move to the next line after printing each row
}
// Delay before next loop
delay(loopDelay); // Adjust this delay as needed to avoid serial flooding
}
void activateRow(int row) {
// Iterate through each control pin for the row multiplexer
for (int i = 0; i < sizeof(rowControlPins) / sizeof(rowControlPins[0]); i++) {
digitalWrite(rowControlPins[i], bitRead(row, i)); // Set control pin to the corresponding bit of the row number
}
}
void activateColumn(int col) {
// Iterate through each control pin for the column multiplexer
for (int i = 0; i < colpins; i++) {
digitalWrite(colControlPins[i], bitRead(col, i)); // Set control pin to the corresponding bit of the column number
}
}
double readCapacitance() {
byte status = statusRead();
// If the capacitive conversion has been completed
if ((status & DataReady) == DataReady) {
// Read capacitance data from AD7746 registers
double capacitanceValue = dataRead();
return capacitanceValue;
// } else {
// Serial.println("Error: Capacitive conversion not complete");
// return -1; // Indicate failure to read capacitance
// }
}
}
double dataRead() {
return -2.0;
}
byte statusRead() {
// Read the status of the AD7746
return DataReady;
}
And back open because @kapple1736 changed their mind.
Thank you very much!
I will try this and let I will let you know the issues if anything crept up.
Should have been
void activateRow(int row) {
// Iterate through each control pin for the row multiplexer
for (int i = 0; i < rowpins; i++) {
digitalWrite(rowControlPins[i], bitRead(row, i)); // Set control pin to the corresponding bit of the row number
}
}
Updated activateCol() but not activateRow(). Sheesh!
Last time, people suggested using esp32 because the dynamic memory of Arduino is less. Now I am trying it o using esp32 and the following error is what I am getting:
ELF file SHA256: d0d18a288e57cb23
Rebooting...
ets Jul 29 2019 12:21:46
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
***ERROR*** A stack overflow in task loopTask has been detected.
Backtrace: 0x40083769:0x3ffc2f50 0x400883b5:0x3ffc2f70 0x4008b25d:0x3ffc2f90 0x40089cb3:0x3ffc3010 0x400884c4:0x3ffc3040 0x40088474:0x3ffb6510 0x3ffc20b5:0x00000108 |<-CORRUPTED
And this is the console of the memory usage.
Using library Wire at version 2.0.0 in folder: C:\Users\dell\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\libraries\Wire
"C:\\Users\\dell\\AppData\\Local\\Arduino15\\packages\\esp32\\tools\\xtensa-esp32-elf-gcc\\esp-2021r2-patch5-8.4.0/bin/xtensa-esp32-elf-size" -A "C:\\Users\\dell\\AppData\\Local\\Temp\\arduino\\sketches\\CA53F10BCF18128D63C806DDDAEFC847/AD7745_final_matrix.ino.elf"
Sketch uses 277149 bytes (21%) of program storage space. Maximum is 1310720 bytes.
Global variables use 21736 bytes (6%) of dynamic memory, leaving 305944 bytes for local variables. Maximum is 327680 bytes.
Someone who uses ESP32 will have to help you with that one.
I tried it wit Arduno but facing the same. Like can we do something to access this data in matrix form anywhere (python etc) without it consuming the memory of arduino).. It may be a naive question.
If you must have the entire array intact in memory at the same time, you're stuck. If you could transmit portions, for example doing 1/4 or 1/16 between sends there are options, but if you need the readout to be complete that's it. But I'm very suspicious that your problem with the ESP32 has to do with something else, it's just that I have no experience to contribute.
I think I can do one row at a time. Will it help?
Just new to this thing as well
Yes. It requires refactoring the code to reduce the data array, fill the array, transmit it, repeat until done, etc. I may be able to help with that, but time is fleeting these days.
For one thing, transmitting the data as ASCII is abysmal, if what's receiving the data is at all capable of receiving binary data instead.
But, I think before I touch the code, I want to know much more about what the bigger plan is. Since you've had issues sharing so far, I would imagine you'll be unwilling to share that, in which case I don't think I can help you much.
The bigger plan is to interface the 64*64 pressure sensing matrix. The application is to map the pressure points.
This is all what we are doing.
I have shared everything with you. If you feel I am still hiding. How will I make you believe that it is all what we are doing.
