Arduino IO Expansion Basics? *rephrased

Hi guys!

I want to double my Arduino IO. When I search for Arduino Expander, I2C connection is always suggested.
I'm new to I2C and I've only tested Multiple Arduino connections (I used 4 Arduinos: 1Master, 3Slaves).
It took me a week to execute the code I wanted :roll_eyes:

The questions are...
If I will use an expander suggested here Arduino Playground - I2CPortExpander8574,
can I program micro controller without having to upload them to the Arduinos one by one?
What are your suggested expander if I want minimum of 20 IO(analog and digital pins)?

Note: I'm using Arduino uno

Clarify the IO needed. Analog In (ADC), Analog Out (DAC), Digital In, Digital Out?

CrossRoads:
Clarify the IO needed. Analog In (ADC), Analog Out (DAC), Digital In, Digital Out?

Shouldn't the code identify the input/output? (sorry, I don't know)
16 Analog, 24 Digital so...
~ 8 Analog In, 8 Analog Out
12 Digital In, 12 Digital Out

We seem to have lost your plot when you start talking about using multiple Arduinox. That gets to be a rather complex field.

You can add many I2C port expanders to add digital ports, 8 or 16 (ports) at a time. You can also get I2C ADCs and DACs, many of them considerably superior to those in the Arduino itself, and various other devices.

But they generally connect to one Arduino. So what's all this about multiple Arduinox?

Sorry, what I mean in multiple Arduino connection is connecting the SDA and SCL of 4 Arduinos--1 functioning as master and 3 as slaves.

What I want to know is...
Is the process the same in connecting the "multiple arduino" and expander?--where in the "multiple arduino", I connect all of their SDA and SCL and upload the code to each arduino-- because I want to expand my IO without having to upload a code to each arduino.

connect all of their SDA and SCL and upload the code to each arduino

How do you do that? Do you have a bootloader that can handle I2C?

because I want to expand my IO without having to upload a code to each arduino.

I'm lost as well as everyone else seems to be.

If you need more IO on an Arduino just add IO chips, no need for multiple Arduinos. Or is there another reason for them?


Rob

I've not seen a bootloader that can accept sketches via I2C.
The '328P datasheet does say

The Boot Loader program can use any available data interface and associated protocol to read code and write (program) that code into the Flash memory, or read the code from the program memory.

so technically it would seem possible.

Sorry,

@Rob: What I mean is…
When I use the I2C, I first upload different code to each Arduino (diff for master and diff for the slaves)

Master:

 //i2c Master Code(UNO)
#include <Wire.h>
#include <Servo.h>

Servo myservo;  // create servo object to control a servo 
                                // a maximum of eight servo objects can be created 
 
int pos = 0;         // variable to store the servo position

void setup()
{
  Serial.begin(9600);
  
  Wire.begin();
  
  myservo.attach(8);  // attaches the servo on pin 8 to the servo object 
}

void loop()
{
  while(Serial.available())
  {
    char c = Serial.read();
    
    if(c == 'H')
    {
      Wire.beginTransmission(1);
      Wire.write('H');
      Wire.endTransmission();
      
      Wire.beginTransmission(2);
      Wire.write('H');
      Wire.endTransmission();
      
      Wire.beginTransmission(3);
      Wire.write('H');
      Wire.endTransmission();
      
      for(pos = 0; pos < 60; pos += 1)  // goes from 0 degrees to 60 degrees 
      {                                                              // in steps of 1 degree 
        myservo.write(pos);                     // tell servo to go to position in variable 'pos' 
        delay(15);                                          // waits 15ms for the servo to reach the position 
      }
    }
    else if(c == 'L')
    {
      Wire.beginTransmission(1);
      Wire.write('L');
      Wire.endTransmission();
      
      Wire.beginTransmission(2);
      Wire.write('L');
      Wire.endTransmission();
      
      Wire.beginTransmission(3);
      Wire.write('L');
      Wire.endTransmission();
      
      for(pos = 60; pos>=1; pos-=1)     // goes from 60 degrees to 0 degrees 
      {                                
        myservo.write(pos);                     // tell servo to go to position in variable 'pos' 
        delay(15);                                          // waits 15ms for the servo to reach the position 
      }
    }
  }
}

Slave: (I just change the degree for different arduinos)

//i2c Slave Code
#include <Wire.h>
#include <Servo.h>

Servo myservo;  // create servo object to control a servo 
                                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 

void setup()
{
  Wire.begin(3);
  Wire.onReceive(receiveEvent);
  
  myservo.attach(8);  // attaches the servo on pin 8 to the servo object 
}

void loop()
{
}

void receiveEvent(int howMany)
{
  while(Wire.available())
  {
    char c = Wire.read();
    
    if(c == 'H')
    {
      for(pos = 0; pos < 270; pos += 1)  // goes from 0 degrees to 270 degrees 
      {                                                                // in steps of 1 degree 
        myservo.write(pos);                       // tell servo to go to position in variable 'pos' 
        delay(15);                                            // waits 15ms for the servo to reach the position 
      } 
    }
    else if(c == 'L')
    {
      for(pos = 270; pos>=1; pos-=1)     // goes from 270 degrees to 0 degrees 
      {                                
        myservo.write(pos);              // tell servo to go to position in variable 'pos' 
        delay(15);                                   // waits 15ms for the servo to reach the position 
      }
    }
    
  }
}

then, I connect the A4(SDA) and A5(SCL) like the picture above.

My problem is I find it hard to upload the code to each Arduino everytime I make some changes.
What I want to do is use an expander so I can upload a code to just one Arduino.
I don’t know much about these “expanders” or “IO chips” so…and I’m asking you guys If this is possible?
If so, can you link a site for diy Arduino expander?

@CrossRoads:
If I use an expander, do I still have to upload a slave code to the expander?

No, the expander are usually just a collection of chips that do not need programming.

It cannot run servos?

OK, so look up MCP23017, that's a typical IO expander chip (although there are many), it can be SPI or I2C, but no programming of the chip required in the sense that you download code into it like an Arduino.

You do have to setup registers inside it, but there are libraries around to make that painless I think.

It cannot run servos?

First we've heard of servos I think. Minor detail you could have mentioned at the start.

How about you tell us exactly what the project has to do. Forget how you think it should be done.


Rob

I want to connect different types of sensors[10 inputs using analog and digital pins] and motors[10 outputs using analog and digital pins] to the Arduino–sort of a “training module”. Since one Arduino is not enough, I want to use two Arduinos but I don’t want to make different programs for the two that is why I’m considering expanders.

Since one Arduino is not enough

It probably would be if you used a larger Arduino, a Mega for example. And that will be a lot easier than using two boards.


Rob

  1. if you need 10 analog inputs, try MCP3008: http://www.adafruit.com/products/856
  2. if you need 10 digital outputs… emm if u tried #1 you should already have enough pins, but you may try 74595.