Connecting multiple Arduino Micros

I'm wondering if it is feasible to connect a number of Micros together.

I want to get into electronics as a hobby. I'd like to control an RGB matrix. I'm brainstorming.

Normally, one would have to have an LED driver board between the Arduino & the matrix. But, I'm wondering about using a number of Micros connected together to control a group of LEDs. Each Micro can output 40 mA on each I/O pin. So, I'm wondering if each Micro can directly control a number of LEDs in the matrix & act as an LED driver. The Micro supports I2C, SPI & U(S)ART & it has an external interrupt pin. A Micro would replace an LED driver. So, for example, an 8X8 matrix would have 64 LEDs. A Micro could control a sub-matrix of 4X4. So, 4 Micros would be needed to control all 64 LEDs. I assume that this is feasible. But how would one synchronize all of the Micros? Would they have to be the slaves & a Mega 2560, for example, be the master?

Each Micro would have to be loaded with a sketch but would each one have the same sketch or a different sketch?

As I stated, I'm brainstorming.

Hi, taking your idea to the extreme, you could have one chip controlling each rgb led. It could be controlled by some kind of serial communication and, to keep wiring simple, daisy-chained together with many others. To keep things neat and compact, the chip could be integrated into the led itself. Well, its already been done and one such example is the ws2812b. Chips like these have caused a revolution in design of rgb led circuits in hobbyist circles, making other designs seem very cumbersome by comparison.

Paul

Macnerd: I'm wondering if it is feasible to connect a number of Micros together.

Each Micro can output 40 mA on each I/O pin.

Your statement about current is not correct. First of all 40mA is the absolute maximum and it would be unwise to work at that regularly. Secondly, there are other limits for the total current per I/O port - read the Atmel datasheet.

Apart from that there is no reason not to connect several Arduinos together if it makes economic sense.

A lot depends on how often the leds need to change and how closely coordinated they need to be. You could connect them all to a master using the serial connection - assuming the slaves do not need to talk to the master so that they are only connected to Tx from the master (and GND). Then send data with an ID number so each slave knows whether the data is for it.

A Mega or Leonardo would be convenient for the master during development simply because they have more than one Hardware serial so you can be connected to the PC for debugging and connected to the slaves.

...R

I googled connecting multiple Arduinos together & most websites recommended using I2C. I didn't completely understand one website's comment about using the Rx & Tx pins. Something about the Rx & Tx pins are used by the UART which is used by the USB. So, does that mean that the Arduinos cannot be daisy-chained together using the Rx & Tx pins?

I also read about I2C using 7-bit & 10-bit addresses. Do the Arduinos use both the 7-bit & the 10-bit addresses? What's the maximum speed of the I2C?

None of the websites that I went to recommended using SPI. I know that the hardware for I2C is simpler than SPI, but it is slower than SPI.

How does each slave get its address? Is it hardwired into it or is it assigned to each slave by software?

I'm not exactly sure what I want to do. That's why I'm brainstorming. I guess what I want to do is either enable or disable each slave.

What is the external interrupt pin used for?

Macnerd: I googled connecting multiple Arduinos together & most websites recommended using I2C. I didn't completely understand one website's comment about using the Rx & Tx pins. Something about the Rx & Tx pins are used by the UART which is used by the USB. So, does that mean that the Arduinos cannot be daisy-chained together using the Rx & Tx pins?

You can - but not in the naive manner; if you want to do this - look into "microcontroller serial bus" implementations - for example (slow - but works for the purpose the author designed it for):

http://www.romanblack.com/blacknet/blacknet.htm

You could also instead use software serial to define 2 seperate serial ports (2 pins needed for each port) - designate one "in" and the other "out" - and use a protocol to look at the data to know whether to shuffle it forward, or use it at the node indicated (via an address setting).

Macnerd: I also read about I2C using 7-bit & 10-bit addresses. Do the Arduinos use both the 7-bit & the 10-bit addresses? What's the maximum speed of the I2C?

You'll need to look into whatever library allows for I2C interface usage.

Macnerd: None of the websites that I went to recommended using SPI. I know that the hardware for I2C is simpler than SPI, but it is slower than SPI.

I would keep looking - the information is definitely out there.

That said - note that I2C and SPI are only intended for very limited distances - if you want greater distances, you'll need to use a different serial approach (RS-422 or RS-485 for instance) - or a different communications platform (fiber, wifi, ethernet, rf, etc).

Macnerd: How does each slave get its address? Is it hardwired into it or is it assigned to each slave by software?

Usually it is done via software. You can hard code this into each controller - or you can be more intelligent about it: Have all nodes listen for an "address request" - when they hear it (from the master) - have each wait a random amount of time. When a node's time has expired - it checks to see if it already has an address - if it doesn't, it picks a random address, then sends it to the master. The master records it, and then sends back an acknowledgement to the node - the node then notes that it has an address.

If a collision occurs (on the random chance that two nodes communicate to the master at the same time, or other reasons to prevent things from working) - the acknowledgement never comes back to the node. The master continues to send a request for addresses until it knows all nodes have notified it (or you can come up with some other logic).

This is just a brief overview of how to do things (and I am certain that I have missed or goofed on the logic somewhere) - but you can see how you could implement things so that neither the master nor the nodes have to know anything about each other - just try to think of it as if you were blind and in a room with other people (who are also blind) - how would you determine how many of you there are (especially if you are shouting over each other - ie collisions)? That same discovery logic can be applied for a serial network.

Macnerd: What is the external interrupt pin used for?

Interrupts are used to tell a processor that "something has occurred - take care of it now" - when such an interrupt occurs, the processor stops what it is doing (making note of where it was) - executes a special routine (called an "interrupt service routine" - or ISR) - which MUST be very short and very fast (don't dilly-dally in the routine!) - this routine does something for the interrupt (generally sets a flag or increments/decrements a counter or takes a reading or similar - short-n-sweet!) - then the processing continues immediately from where it left off. All of this happens in micro-seconds - very quickly. Note that while it is in the ISR - the processor can't service other interrupts should they occur (actually - that all depends on the architecture and how the interrupts are defined).

Macnerd: I googled connecting multiple Arduinos together & most websites recommended using I2C. I didn't completely understand one website's comment about using the Rx & Tx pins. Something about the Rx & Tx pins are used by the UART which is used by the USB. So, does that mean that the Arduinos cannot be daisy-chained together using the Rx & Tx pins?

On an Uno pins 0 and 1 connect to the hardware serial (usart) which is also used to communicate with the PC over th e USB cable. A Mega has 4 hardware serial ports.

The SoftwareSerial library allows an Uno to add another serial port on another pair of pins.

If all you want to do is send data from a master to a few slaves you can connect the master's Tx pin to all of the slave Rx pins. (You also need a common GND connection). That way every slave can hear the transmitted message, but cannot reply. It is possible to connect the Tx pins from several slaves to the master Rx but it requires some extra components to prevent them interfering with each other.

If, when writing the slave program, you create a variable to hold an ID value you can put a different value in that variable before you upload the code to each slave.

Don't bother with interrupts until you are more familiar with Arduino programming. They are not necessary for this application.

The examples in serial input basics may be useful.

...R

In the course of my research, I learned that SPI requires a chip select pin for each slave. So, I2C is definitely easier to implement!

I've wondered about RS-422 or RS-485.

I'm not sure if I want to send & receive data to the slaves using I2C. How do I enable & disable the I2C slaves? I don't want to turn them off or reset them. Maybe use Tri-State logic to disconnect one or more slaves.

I researched the WS2812B chips. That's pretty simple.

Maybe an external lookup table. Each LED in the matrix has an X & Y coordinate. Maybe a lookup table instead of shift registers. As I stated, I'm brainstorming.

Macnerd: I'm not sure if I want to send & receive data to the slaves using I2C. How do I enable & disable the I2C slaves? I don't want to turn them off or reset them. Maybe use Tri-State logic to disconnect one or more slaves.

You don't need to. Each slave has a different address number on the i2c bus. If you are making many slaves out of Arudinos, you can give each one a different slave address. When the master Arduino needs to send or receive to a particular slave, the message contains this address and only the correct slave responds. However, only 127 max possible addresses, and some of those are not usable, I believe.

Macnerd: I researched the WS2812B chips. That's pretty simple.

Told you so! 100 times simpler than connecting multiple Arduinos, by whatever means.

Macnerd: Maybe an external lookup table. Each LED in the matrix has an X & Y coordinate. Maybe a lookup table instead of shift registers.

Don't understand that, are you still talking about ws2812b or multiple Arduinos? What is this "external lookup table" exactly, and what shift registers is it replacing?

Maybe an external lookup table. Each LED in the matrix has an X & Y coordinate. Maybe a lookup table instead of shift registers. Don't understand that, are you still talking about ws2812b or multiple Arduinos? What is this "external lookup table" exactly, and what shift registers is it replacing?

According to Wikipedia: In computer science, a lookup table is an array that replaces runtime computation with a simpler array indexing operation. The savings in terms of processing time can be significant, since retrieving a value from memory is often faster than undergoing an 'expensive' computation or input/output operation. The tables may be precalculated and stored in static program storage, calculated (or "pre-fetched") as part of a program's initialization phase (memoization), or even stored in hardware in application-specific platforms. Lookup tables are also used extensively to validate input values by matching against a list of valid (or invalid) items in an array and, in some programming languages, may include pointer functions (or offsets to labels) to process the matching input.

The LED matrix can be thought of as a 2-dimensional array in code. The location of each LED would correspond to an XY coordinate. In code, choose an XY coordinate (known as an element of the array) from the array & enable the LED by applying voltage & ground. The array would be stored in SRAM(or is it EEPROM?) in the Arduino. That's fine for a single-color LED. I'm not sure how to implement an array of RGB LEDs in code.

Speaking of code, each slave would have to have code in it as well as the master. Would the slave code be identical in all slaves or different? Would the master code be the same as the slave code or different?

It's an intriguing idea & it's feasible, but it has a number of disadvantages. Maybe someone who's reading this post is up to the challenge, but not me. It would be a wiring nightmare. Each slave's USB port would have to be accessible so that code could be loaded. If there's a wiring problem, debugging it would be a nightmare. If there's a coding problem, debugging it would be a nightmare. I was just wondering about different ways of lighting RGB LEDs in a matrix.. That's why I started this post.

Indeed! I refer you back to my first reply.

Have you seen these?