Grumpy_Mike:
Sorry I don’t think that will work. You have a resistor with one end to ground and you are connecting 5V and the input of an A/D converter to the other end. I can’t see how this A/D is going to see any more than 5V no matter what the resistor is.
Maybe if you drew just say three columns and rows as a matrix it would be more obvious whether I am wrong or right.
#define BAUD_RATE 9600
#define ROW_COUNT 8
#define COLUMN_COUNT 8
#define PIN_ADC_INPUT A0
#define PIN_SHIFT_REGISTER_DATA 2
#define PIN_SHIFT_REGISTER_CLOCK 3
#define PIN_MUX_CHANNEL_0 4 //channel pins 0, 1, 2,
#define PIN_MUX_CHANNEL_1 5
#define PIN_MUX_CHANNEL_2 6
#define SET_SR_DATA_HIGH() PORTD|=B00000100 // D2 high, rest unchanged, PORTD on the Uno.
#define SET_SR_DATA_LOW() PORTD&=~B00000100 // D2 low, rest unchanged
#define SET_SR_CLK_HIGH() PORTD|=B00001000 // D1 high, rest unchanged, PORTD on the Uno.
#define SET_SR_CLK_LOW() PORTD&=~B00001000 //D2 low, rest unchanged
#define ROWS_PER_MUX 8
#define CHANNEL_PINS_PER_MUX 3
#define PACKET_END_BYTE 0xFF
#define MAX_SEND_VALUE 254 //reserve 255 (0xFF) to mark end of packet
#define COMPRESSED_ZERO_LIMIT 254
#define MIN_SEND_VALUE 1 //values below this threshold will be treated and sent as zeros
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
/**********************************************************************************************************
- GLOBALS
**********************************************************************************************************/
int compressed_zero_count = 0;
/**********************************************************************************************************
- setup()
**********************************************************************************************************/
void setup()
{
Serial.begin(BAUD_RATE);
pinMode(PIN_ADC_INPUT, INPUT);
pinMode(PIN_SHIFT_REGISTER_DATA, OUTPUT);
pinMode(PIN_SHIFT_REGISTER_CLOCK, OUTPUT);
pinMode(PIN_MUX_CHANNEL_0, OUTPUT);
pinMode(PIN_MUX_CHANNEL_1, OUTPUT);
pinMode(PIN_MUX_CHANNEL_2, OUTPUT);
sbi(ADCSRA,ADPS2); //set ADC prescaler to CLK/16
cbi(ADCSRA,ADPS1);
cbi(ADCSRA,ADPS0);
}
/**********************************************************************************************************
- loop()
**********************************************************************************************************/
void loop()
{
compressed_zero_count = 0;
for(int i = 0; i < ROW_COUNT; i ++)
{
setRow(i);
shiftColumn(true);
for(int j = 0; j < COLUMN_COUNT; j ++)
{
int raw_reading = analogRead(PIN_ADC_INPUT);
byte send_reading_in_Pounds = map(raw_reading, 0, 1023, 1, 135);
shiftColumn(false);
sendCompressed(send_reading_in_Pounds);
}
}
if(compressed_zero_count > 0)
{
Serial.write((byte) 0);
Serial.write((byte) compressed_zero_count);
}
Serial.write((byte) PACKET_END_BYTE);
}
/**********************************************************************************************************
- shiftColumn() - Shift out a high bit to drive first column, or increment column by shifting out a low
- bit to roll high bit through cascaded shift register outputs. digitalWrite() has been replaced with direct
- port manipulation macros, as this function performs the vast majority of pin writes
**********************************************************************************************************/
void setRow(int row_number)
{
}
void shiftColumn(boolean is_first)
{
if(is_first)
{
SET_SR_DATA_HIGH();
}
SET_SR_CLK_HIGH();
SET_SR_CLK_LOW();
if(is_first)
{
SET_SR_DATA_LOW();
}
}
/**********************************************************************************************************
- sendCompressed() - If value is nonzero, send it via serial terminal as a single byte. If value is zero,
- increment zero count. The current zero count is sent and cleared before the next nonzero value
**********************************************************************************************************/
void sendCompressed(byte value)
{
if(value < MIN_SEND_VALUE)
{
if(compressed_zero_count < (COMPRESSED_ZERO_LIMIT - 1))
{
compressed_zero_count ++;
}
else
{
Serial.write((byte) 0);
Serial.write((byte) COMPRESSED_ZERO_LIMIT);
compressed_zero_count = 0;
}
}
else
{
if(compressed_zero_count > 0)
{
Serial.write((byte) 0);
Serial.write((byte) compressed_zero_count);
compressed_zero_count = 0;
}
if(value > MAX_SEND_VALUE)
{
Serial.write((byte) MAX_SEND_VALUE);
}
else
{
Serial.write((byte) value);
}
}
}
- I have not got it working yet still trying to figure out the code for it, I did find someone who had a similar idea using this sort of scanning strategy, I’ve been messing with it to see if I could some parts of the code.
Paul__B:
I don’t think you should have individual resistors pulling down the “columns”. That is going to warp the measurements. Put one resistor on the multiplexer common.
Are you saying have all the mux col. have only 1 resistor to ground? Wouldnt that make the readings all the same? What do you mean by it will wrap measurements?
CrossRoads:
Seems to me you are overcomplicating things.
With just 40 inputs, why not feed them direct into 5 analog muxes going to 5 analog inputs?
Make each pad it’s own device, separate from any other.
Set the address lines to 000, read from all 5 muxes with 5 analogRead() from A0,A1,A2,A3,A4.
Set the address lines, to 001, read from all 5.
:
:
Set the address lines to 111, read from all 5.
No need for the output shift registers at all.
If the 40 analogRead() turns out to be too slow, change to 5 of MCP3008 and read the 40 inputs via SPI.
https://ww1.microchip.com/downloads/en/DeviceDoc/21295d.pdf
Well for what I understand the shift registers(Horizontal copper strips) are what send the initial high signal and the mux(vertical copper strips) is what intakes that signal and reads the value. So i would have 1 row turn on 1 at a time and the mux would scan each input reading its voltage values to see if it has changed. Then the same process will happen to the next row. How would I know if someone is stepping in the square if their is no initial high signal? Unless the mux can send the high signal and read it a the same time?