Custom Arduino Mega? with even more pins

Hello there

The thing is I'm currently working on some automation stuff for which I need about 100 digital pins ( and analog , in total) as I'll be using lots of leds, relays, sensors, buttons and ...
I've also heard about the multiplexing , but apparently it would not be the case for me as it requires me to reprogram the whole project.

So is there a way to make own arduino mega? with a 100 pins( instead of 70) and print the pcb?
and if so what do I need to do ?

BTW, when the project is finished I'd have to get sb to design and print the pcb to connect to my arduino ( or preferably integrate them all on a single board)

Thanks for your time !

You don't get a full 100 pins from the '2560 - with a custom board you can get up to 86 I/O pins - but 2 need to go for the crystal (unless you want to use internal oscillator, which I think is inappropriate on the '2560 since it doesn't give an accurate enough clock for serial to work reliably).

What would you need to do? Design the PCB and lay it out using your preferred PCB design tools, get it made by someone (dirtypcbs is good and cheap) and then solder all the parts down to it.

I've also heard about the multiplexing , but apparently it would not be the case for me as it requires me to reprogram the whole project.

Surely you don't already have code for 100+ pins...
It would probably be worthwhile to rewrite your project anyway, to use things like

lightLED(n);
relayOn(n);
readButton(n);

It would make the code clearer, and it would be relatively easy to say that "hah! LEDs with bit 7 set have a different mechanism for being lit!"

I think you could do two things. First, set another Mega as an Slave and make it do writes and reads on demand of the data input over serial. It’s just to read the serial stream and put some switch case. This is the easier way better than custom making PCBs.

Option B could be to use some multiplexers. For example, one 8 channel multiplexer gives you a gain of 5 inputs, but, if you multiplex multiplexers (A,B,C from different ICs wired together) and select which multiplex use through another multiplexer it gives you the chance to control up to 64 pins with just 7 pins. Bad thing is you can only read or write 1 pin at a time. But, for example, it could help you with sensors or arrange stuff that is meant be “on” one at a time.

Now, if you run the multiplexing at a very high rate, it can’t be perceived by human sense. So you could multiplex leds. Also, for solenoids, is possible to make a gate for them and make that gate stay until another signal is send.

Here’s an example of how to set the pin for reading. So, all my sensors calls are made to the common pin, before this, I had a vector where I stored sensor pins and called it from a loop.

void multiplex(int pin){
  switch (pin){
    case 0:
      digitalWrite(11, LOW);
      digitalWrite(10, LOW);
      digitalWrite(9, LOW);
      break;
  
    case 1:
      digitalWrite(11, HIGH);
      digitalWrite(10, LOW);
      digitalWrite(9, LOW);
      break;

    case 2:
      digitalWrite(11, LOW);
      digitalWrite(10, HIGH);
      digitalWrite(9, LOW);
      break;

  }
}

This is the way it is used

for (byte jtemp = 0; jtemp<3; jtemp++){ //lee los DHT
    multiplex(jtemp);
    int dht_res = DHT.read22(3); //3 is the common pin
}

Simplest, in my opinion, would be the use of multiplexers (e.g. 74HC4067) to expand analog inputs, port expanders (I2C or SPI) or shift registers (74HC595 for output, 74HC165 for input) for the digital IO and e.g. the I2C based PCA9685 for PWM.

This gives you the flexibility to expand exactly to your needs (and within limitations might be future proof); a second Mega (or 2560 chip) might still not give you e.g. sufficient analog pins.

To control the multiplexers with the above, you need some pins (either directly or indirectly).

I've also heard about the multiplexing , but apparently it would not be the case for me as it requires me to reprogram the whole project.

Is this an existing product that needs expansion. Or did the requirements change?

I have no idea why you or your 'client' are reluctant to reprogram the complete project but whatever you have to do to get to more pins will anyway imply new code. I think that if if it's written properly, it should not give too many gray hairs :wink:

Arduino Mega which has I2C connection possibilities will allow you do achieve your goal without pain of designing a new pcb then integrating all the electronic components together which will take a lot of time and resources. What you really need here is a so called "Port Exander based on I2C", you can have as many of those as Arduino Mega offers on behalf of I2C connections, I think there are x2, so you can add 2 x port expanders and that will give you another 2 x 8 = 16 GPIO.

PCF8574 Remote 8-Bit I/O Expander for I2C Bus

David

David_ZI:
you can have as many of those as Arduino Mega offers on behalf of I2C connections, I think there are x2, so you can add 2 x port expanders and that will give you another 2 x 8 = 16 GPIO.

PCF8574 Remote 8-Bit I/O Expander for I2C Bus

It depends on the port expander that you use. If an I2C port expander has 3 address lines, you can hook up 8 (2 pow 3) port expanders on the same I2C bus.

There is also PCF8574A version available which differs in fixed part of address, so you can hook up 16 in total on the same I2C bus.

Budvar10:
There is also PCF8574A version available which differs in fixed part of address, so you can hook up 16 in total on the same I2C bus.

would be interesting to see the system throughput, when 16 of those are hooked up, although you have to consider the BUS capacitance, which is essential for proper communication channels. In my opinion if you need to add up to 8 GPIO and note for serious housekeeping tasks then you might as well choose those parts, but if you need about half of the GPIO the package has, then its definitely a wrong microprocessor you have chosen.
Otherwise spending time to get the suitable MCU for project takes way longer than everything else I guess.

David

Shift register, recode.
Good luck.