Thank you for your potential help!
You have a photo and the fritzing file available.
My need is to control 64 A3144 hall sensors positioned in a row and in a column.
The A3144 has a VCD, GND and 1 digital pin.
Each sensor must return to me the magnetism of a magnet and whether or not it is active.
For this, I do not want to use 64 I/O which would require a system with a multiplexer.
My need supports a slight latency time, the wiring principle is that in the photo as well as the fritzing file. It does not respect the test plate except for the red and black power supply...
a) Each line has its own power supply which is powered by the push of the button.
So the hall sensor lines only need 8 pins to turn them on and not 64
b) the lines are powered each in turn. I cannot have more than 1 active line.
c) The digital is connected by column thus reducing the I/O from 64 to 8.
THE PRINCIPLE
When I activate line A with the button, I can determine which of the 8 halls of the line has an active magnet or not. If I did it manually with each of the 8 buttons, it would be possible for me to know the status of the 64 halls
QUESTION AND NEEDS
1°/ I do not want to do it by button but by a code loop which will check each hall coded according to its box
Should I directly connect the red of each line on the card or should I put some kind of power supply in the form of MOSFETs or transistors to quickly turn on the hall sensors of the line? What to wear?
2°/ The digital pin being connected in parallel by column but only waiting for the return of the powered line... to ensure the integrity of the signals should I add a capacitor to filter? If so, what kind ?
3°/ Do you have examples of codes allowing you to make the power supply loop for each line and retrieve the status of each hall in a simple and efficient way to have the variable status of the 64 hall sensors in an infinite loop?
Thank you for your constructive feedback and clear answers.
One problem I can see is that the operating current for each sensor is typically 4.4mA but can be as high as 9mA. With 8 of the sensors powered together, that could be between 35mA and 72mA, which is too much for an Arduino pin. So some high-side drivers will be needed to replace the buttons.
Some pnp transistors such as BC327 might work as high-side drivers. Don't forget current limiting resistors between the pnp base and Arduino pin, e.g. 4K7. The pnp will have the effect of inverting the Arduino output pin, so in your code you will need to set all the pins HIGH and change one pin at a time to LOW to power the row of sensors.
You may also need to pause for some time between powering a row of sensors and reading the outputs. They are probably not designed to work with intermittent power and may need time to settle after power is applied. The data sheet may have some figures on this.
I turn to this type of reflection because with multiplexer type 74HC165, we arrive with the 3 pins at 192 I/O.
So are your points of attention the same with multiplexing?
And from your point of view, am I limiting the risks or increasing them by the row/column approach versus 74HC165?
I would expect that the plan is to power all the sensors all the time. This steps around the question of whether the sensors like being powered up and down.
64 sensors at 10 mA is not a huge power requirement.
So you are only talking about needing to shift register or multiplex 64 bits.
These
would do fine. You'd need four pins for the mux address, and another four to select one of four of the above moduke.
@beback your response is confusing. You replied to my post but seem to be asking questions about shift registers suggested by @david_2018
With shift registers, you would need 8 of them, which can be daisy chained to the same 3 arduino pins. All sensors would be powered full time.
With matrix approach, only 8 sensors at a time would be powered, and your code would power each row in turn, as you have been showing with your buttons. But it may be neccessary to pause for a short time between powering up a row and taking the readings, because the sensors may need time to settle after power is applied.
I recommend you make a prototype with 4 sensors (2 rows, 2 columns) and test that. For this prototype, you will not need the pnp transistors.
My personal preference is: use the least number of components. The Mega has enough in- and outputs for 64 (or 192) sensors.
One resistor plus one transistor per row is inevitable (mind to make only one output low at a time). The open collectors will work fine with the internal pullup resistors of the inputs. Filtering the signals will not be necessary in the shown small setup.
I would write an ISR on TIMER2_OVF that reads the inputs and then switches to the next row. The standard set up of the Arduino IDE makes that timer overflow once per millisecond, which gives the sensors enough time to settle, and doesn’t block the rest of the program.
The Mega has the same voltage regulator as the UNO R3. Worst case scenario: when powered with 12 Volts and the calculated 72mA drawn from the 5V pin, the heat dissipation of the regulator will be considerable, but probably not too high, especially on the workbench with free airflow. When powered with a lower voltage or from USB: no problem.
The '4067 is a multiplexer. By setting the address pins (and the enable lines) you can use four of them to switch between 1 of 64 inputs. Or outputs if you were needing to do outputs. Only one of the two, so here it would be an input multiplexer.
The '23017 is an I2C i/o expander. It adds additional input or output pins. All pins can be either input or output. Setup and addressing is all done over the I2C bus, which process is vastly simpler if you use a library, which libraries exist.
If you could find an MVP23017 module, it would be a toss up which to choose. If you are OK working with bare ICs, it would still maybe be a toss up.
Voting: I'd use the multiplexer, provided I had the 9 pins total it would need. Four address lines, four to select one of the four multiplexer modules and one actual input where you'd read the sensor.
The I2C solution woukd only use two pins, and those would just be the I2C bus lines, where you might also be wanting to park your LCD display or anything else that runs off I2C.
Google your friend should help you find examples of use of either idea. And you can decide for yourself.
Do you need to power up and down the sensors, or was that part of the solution you conceived for getting 64 inputs?
Remark 1: are you aware that with the MCP23017’s you’ll need pullup resistors (64 66)?
Remark 2: start writing the communication program to set them up and to read them. Compare that to:
// hall sensors A3144 8 x 8 bitfield
// rows are addressed by PA0..PA7
// signals from columns to PC0..PC7
volatile uint8_t bitField[8]; // create the bitfield
ISR(TIMER2_OVF_vect) { // refreshes the bitfield in 8ms
static uint8_t rowCounter; // local variable, remembered next time
bitField[rowCounter] = PORTC; // move all 8 columns to the bitfield
rowCounter++; // advance row counter
if (rowCounter > 7) rowCounter = 0; // last row
PORTA = 0xFF; // switch off all rows
PORTA = ~(1 << rowCounter); // make one row output low
}
void setup() {
PORTA = 0xFF; // set row outputs high before making them outputs
DDRA = 0xFF; // make them outputs
PORTC = 0xFF; // switch on the pullups for the inputs
TIMSK2 |= TOIE2; // enable overflow interrupt timer2, doesn't interfere with the PWM signals
}
void loop() {
// put your main code here, to run repeatedly:
}
The I/O's are not exactly according the drawing in the fiirst post, but quite close.
Thanks for your answer and your code.
To be true, I don't know how to use MCP23017 yet.
Do you have link to learn ?
And not clear about pullup resistors too.
Yes. Unless the weak internal pull-ups (100K) of the MCL23017 would suffice.
I would use a lower resisotr value.
The multiplex method only need one pull-up placed on the input line at the microprocessor.
The interrupt mechanism is interesting. On the other hand it uses interrupts (!) which are probably not necessary here.
As for remark 2, a library gives ppl a good head start, no need to struggle setting up much of anything,
@beback if you google either part number and add Arduino you will find libraries for both and example code, if indeed such examples don't come with the library like is often the case.
It just depends on what you are counting and what kind of fun you want to have.
With the expander: 4 chips, 2 resistors and 2 i/o pins, which are usable as I2C otherwise.
With the multiplexer, 4 chips or modules, 1 resistor and 9 i/o pins.
Where comes 8 resistors and 8 transistors? If you need to turn off rows of sensors, don't you need to do that no matter which way you collect the 64 sesnor outputs?
@beback did I miss an answer to the questions - why do you need to turn off the sensors, and have you looked into whether they will power up rapidly and supply meaningful output at the rates you intend to scan and collect their outputs?
The ISR I wrote is based on direct multiplexing by the Arduino, without I/O expanders.
By the way, up to 8 MCP23017’s can be connected to 1 bus, without bus multiplexer, if you really want to use expanders.