Question about having more I/O pins on arduino.

hello guys,
hope you all having a good day
well i am at this stage making experiments and documenting my experiments with the problems that might happen with each one, example expanding the analog input or the digital inputs ... etc
to be able to build my final circuitry for my project without any problem and loss of time.

So i manage to have :
1- more analog input with 4051 IC (4 pins needed from arduino)
2- more Inputs with 4021 IC, (3 pins needed from arduino)
3- controlling Four double digits 7-segments display CA with MAX7219 (3 pins needed from arduino)
4- controlling a CC single digit with another MAX7219 (3 pins needed from arduino)

so i found out that i must add 2 shift registers :
5- the first for 13 LEDs in group of 2 (3 pins needed from arduino)
6- and the other Shift register for 6 individual LEDs. (3 pins needed from arduino)

I still have to add :
7- a Transceiver for the Wireless communication which is this one (lots of pins needed from arduino maybe 6 or 7 i don't know exactly never worked with it):
http://www.aliexpress.com/item/2pcs-lot-LoRa1278-4Km-100mW-433MHz-High-sensitivity-sx1278-chip-Lora-module-ultra-long-range-RF/32276300110.html

So it seems that i run out of I/O to control all of this + the Transceiver

So i am trying to figure out what should i do to run away from adding another arduino and making Serial communication between the 2 using the SoftwareSerial library

what i have in mind is maybe add a shift register between the arduino and every IC expander that will be controlling the pins connected directly to arduino of course digital pins only

So what do you think ? and if you have any other suggestions please that would be better

Thanks a lot for all in advance :slight_smile:

You don't need to. You use a shift register for the displays (MAX7219), the leds and the inputs (4021). They are SHIFTregisters. You shift data trough them. That's the whole idea of those devices :wink:

You can connect the DO of one to the DI of another. So daisy chain all the input shift registers and connect the last one with DO to MISO (use hardware SPI) of the Arduino. Daisy chain all output shiftregisters and connect DI of the first one to MOSI of the Arduino. And you can also share the clock between all shiftregisters. So you just need 3 pins for almost everything. Now you only need 3 extra pins for the analog multiplexing. So just 7 pins in total :wink:

septillion:
You don't need to. You use a shift register for the displays (MAX7219), the leds and the inputs (4021). They are SHIFTregisters. You shift data trough them. That's the whole idea of those devices :wink:

You can connect the DO of one to the DI of another. So daisy chain all the input shift registers and connect the last one with DO to MISO (use hardware SPI) of the Arduino. Daisy chain all output shiftregisters and connect DI of the first one to MOSI of the Arduino. And you can also share the clock between all shiftregisters. So you just need 3 pins for almost everything. Now you only need 3 extra pins for the analog multiplexing. So just 7 pins in total :wink:

can you please slow down i got confused :confused:

first you suggest to daisy chain the 2 MAX7219 together ?
and daisy chain the 2 shift register 595 together ?

ok but what i am doing is a tachometer with the 13 LEDs and the displays the single digit will display the gear number and the double digit will display other things like speed and RPM
so if i daisy chained the shifts would it be possible to make all the data appears independently from each other ?

Yeay, daisy chain thos and even connect the MAX7219 and the 595 together. As long as you connect the DO (Data Out) of one device to the DI (Data In) of the next.

Of course. You read (and sent out) all the data out at once but you only sent it to the correct device. Just Google daisy chain shiftregister. You first shift out the data for the device the farest away, then the next etc untill the last. After that you make the latch (set the latch line high) and tada, they all heve data.

Same goes for the input. And with the hardware SPI of the Arduino you can shift in and shift out at the same time and thus only use one clock :slight_smile: Okay, maybe it's easier to have a latch line for the inputs and one for the outputs but hey, that's a max of 5 lines :slight_smile:

BTW, tacho signals you want to connect to the Arduino directly because timing is important. I think the interrupt pins would be ideal :slight_smile:

septillion:
Yeay, daisy chain thos and even connect the MAX7219 and the 595 together. As long as you connect the DO (Data Out) of one device to the DI (Data In) of the next.

595 and MAX7219 together ?!! how is that ! i know both are shifts registers but why wouldn't that be confusing for the program :confused: ?

septillion:
Of course. You read (and sent out) all the data out at once but you only sent it to the correct device. Just Google daisy chain shiftregister. You first shift out the data for the device the farest away, then the next etc untill the last. After that you make the latch (set the latch line high) and tada, they all heve data.

yes sure i know the daisy chained but it's been a long time since i've worked with it so i need to refresh my memory :smiley:

septillion:
Same goes for the input. And with the hardware SPI of the Arduino you can shift in and shift out at the same time and thus only use one clock :slight_smile: Okay, maybe it's easier to have a latch line for the inputs and one for the outputs but hey, that's a max of 5 lines :slight_smile:

well about the SPI i still don't know how to use that library and i read about it but still don't know why is it used :confused: ! any simple explanation for that, you have ?

septillion:
BTW, tacho signals you want to connect to the Arduino directly because timing is important. I think the interrupt pins would be ideal :slight_smile:

well it's not gonna be directly here no because the tacho will be on the car and i will receive the data by transceiver so i guess about the tacho yes you are right it must be connected to a circuit then to arduino to not damage the arduino :confused:

firashelou:
4- controlling a CC single digit with another MAX7219 (3 pins needed from arduino)

so i found out that i must add 2 shift registers :
5- the first for 13 LEDs in group of 2 (3 pins needed from arduino)
6- and the other Shift register for 6 individual LEDs. (3 pins needed from arduino)

Why not use the second max chip to control the extra leds? I'm not sure what you mean by "13 LEDs in group of 2". Even if that is 26 LEDs, your second max chip can control them, plus the other 6 LEDs, plus the single digit display. Each max chip can control up to 64 LEDs.

And like septilion says, you can daisy-chain the max chips.

Paul

PaulRB:
Why not use the second max chip to control the extra leds? I'm not sure what you mean by "13 LEDs in group of 2". Even if that is 26 LEDs, your second max chip can control them, plus the other 6 LEDs, plus the single digit display. Each max chip can control up to 64 LEDs.

And like septilion says, you can daisy-chain the max chips.

Paul

13 LEDs / 2 = 6+1 = 7

well controlling them with the second MAX won't be an option because i will be controlling a CA single digit and the LEDs are CC + they are 4 green, 5 Reds and 4 blue so different colors means different resistors and the MAX can accept 1 resistor so shift register 595 would be my better choice because i can choose resistors values for each color

about the daisy chain, i am now experiencing with it like septilion said to try and see how to do it and i guess i will daisy chain the 595 registers so right now i will have 6 pins only from arduino to use 3 for max and 3 for 595

4 for the analog 4051
and 3 for the 4021
so it's 13 pins, and i still have 5 analogs which i can use as Digital, but of course if i can make it less on the Digital pins would be better

firashelou:
13 LEDs / 2 = 6+1 = 7

No, sorry, I still don't understand what you mean there! Perhaps a diagram,,,

firashelou:
the LEDs are CC + they are 4 green, 5 Reds and 4 blue so different colors means different resistors and the MAX can accept 1 resistor

So these are not individual leds? A picture or link would help explain.

I believe the outputs of max7219 are constant-current circuits. The resistor sets this current. So the output voltages will automatically adjust themselves to different led colours, if I am right, and different resistors won't be needed. I have never tried this. @Crossroads: am I correct?

firashelou:
about the daisy chain, i am now experiencing with it like septilion said to try and see how to do it and i guess i will daisy chain the 595 registers so right now i will have 6 pins only from arduino to use 3 for max and 3 for 595

While I agree that in hardware terms it is perfectly possible to daisy chain max7219 and 74xx595 together, if you are using libraries like LedControl, these libaries may not work correctly with a hardware setup like that. They expect only identical chips to be daisy-chained.

PaulRB:
No, sorry, I still don't understand what you mean there! Perhaps a diagram,,,

So these are not individual leds? A picture or link would help explain.

i mean i have 13 independent LEDs of different colors but these LEDs are tied up by pair means each 2 LEDs has one pin to connect to register except 1 of them which means 6 pins or pairs + 1 LED alone

PaulRB:
I believe the outputs of max7219 are constant-current circuits. The resistor sets this current. So the output voltages will automatically adjust themselves to different led colours, if I am right, and different resistors won't be needed. I have never tried this. @Crossroads: am I correct?

but it will be different brightness, some will be dimmer than others

PaulRB:
While I agree that in hardware terms it is perfectly possible to daisy chain max7219 and 74xx595 together, if you are using libraries like LedControl, these libaries may not work correctly with a hardware setup like that. They expect only identical chips to be daisy-chained.

then how can that be done ?
that what i assumed that the LedControl library will be needing only MAX chips to be possible to work

firashelou:
but it will be different brightness, some will be dimmer than others

Yes, you could be right about that. Perhaps it would be worth experimenting. You could use pots to adjust the current to each of your different colour leds. Make them all, say, 10mA, and see if the difference in brightness is acceptable or not.

firashelou:
then how can that be done ?
that what i assumed that the LedControl library will be needing only MAX chips to be possible to work

I agree, I think such libraries would not work with a mix of max7219 and 74xx595 chips daisy-chained together. You would either have to change those libraries in some way, or not use libraries at all, but write your own code to send data to the chain of chips, knowing how the chain is constructed. This could be done. I have used max7219 chips without using a library, and 74xx595 chips are easy to use without a library.

PaulRB:
Yes, you could be right about that. Perhaps it would be worth experimenting. You could use pots to adjust the current to each of your different colour leds. Make them all, say, 10mA, and see if the difference in brightness is acceptable or not.

but one more problem, it will be a mix of Common Anode and Common Cathode :confused:
3 MAX7219, 1 for double digits CA displays, 1 for single digit CA display and 1 for LEDs common cathode of course

PaulRB:
I agree, I think such libraries would not work with a mix of max7219 and 74xx595 chips daisy-chained together. You would either have to change those libraries in some way, or not use libraries at all, but write your own code to send data to the chain of chips, knowing how the chain is constructed. This could be done. I have used max7219 chips without using a library, and 74xx595 chips are easy to use without a library.

well that would be a problem :confused: because i can't work with this without the library i am new to it and there is no real tutorials that explains how it really work at least i didn't find so far

i know how to work with the 595 only

firashelou:
there is no real tutorials that explains how it really work

Normally these 'tutorials' are called datasheets or application notes, aren't they? :wink:

And you have the source code of the libraries...

You would have to seperate the data generation from the datatransmission,
concatenate the data in the right order and have a transmitter send all together.

Whandall:
Normally these 'tutorials' are called datasheets or application notes, aren't they? :wink:

And you have the source code of the libraries...

You would have to seperate the data generation from the datatransmission,
concatenate the data in the right order and have a transmitter send all together.

aha but i am just an amateur :confused:

about the library i tried to read it, it's deep C programming which i don't know :frowning: so must learn C first but for now i don't have time because i am working on the structure mechanical part and electronics part ! 1 person 2 functions :stuck_out_tongue:

So missing knowledge costs pins. :wink: You just don't get something for nothing.

Not a big deal, as cascading of identical chips is usally supported in the libraries.

Whandall:
So missing knowledge costs pins. :wink: You just don't get something for nothing.

so far i came a long long way :D, my before prototype contained tones of 595, transistors and capacitors just for the 595s and 3 arduinos but now it shrank :wink:

Whandall:
Not a big deal, as cascading of identical chips is usally supported in the libraries.

what do you mean ?

Daisychaining/cascading of MAX7219s is supported by the library.
Same probably holds true for the shiftregisters but I did not use them yet, so I can not be shure.

So if you do not want to change the libraries you cant concatenate all serial devices,
but only the identical ones (still sparing pins).

To save the biggest number of pins (cascading everything) you can indeed not use the normal libraries. Do it yourself or altering a library required. (Mayby put it into a buffer instead of sending it out.) But indeed, 595 and the MAX7219 are not that hard...

But you can probably get away with using the same Data en clock line for the MAX7219 and 595 but a separate latch line and still use the libaries.

So it's a choice you have to make. A little bit of extra work in coding (but he, the MAX7219 isn't that hard) or use more IO. But with some good code you can use all the 595, 4021 and the MAX7119 with just 4 lines (MOSI, MISO, SCK and Latch).

About the tacho, I did not know this was external data via wireless. All I read was inputs via the 4021 and read tacho data that way is a bad idea :stuck_out_tongue:

you are totally right guys, that's why it seems that i got hit by "Interesting" that i started to search for good books to choose one to learn the C language
i got this one on my hands for now "The C programming Language by Kernighan and Ritchie"

If you have a good book for C, share the title please because i would be interested

firashelou:
i got this one on my hands for now "The C programming Language by Kernighan and Ritchie"

That's the original C bible. But it won't help you much with all the C++ object-oriented stuff.

PaulRB:
That's the original C bible. But it won't help you much with all the C++ object-oriented stuff.

C++ ! you mean i must learn C++ and not C ?