0

I'm looking to read digital and analog pins on one arduino from another arduino. I believe that as long as they share a common ground connection this should work fine. I'm aware of I2C and I have used it for other projects, but for this I am more interested in just making the connections.

I was wondering

  1. Has anyone had experience with this?
  2. Will I damage anything if I do this?
Gunther
  • 103
  • 4

3 Answers3

3

You're definitely right about the ground.

  1. not this specifically, but it's just two chips talking to each other so it shouldn't be terribly complicated. I have managed to get a couple of micros talking to each other over I2C, SPI, and RS232 on different occasions, but never just to read IO pins.
  2. not if you're careful

One question, though: why do you want to do this? There are devices available called port expanders. The basic idea is that you talk to them over I2C or SPI and they provide access to several IO pins (usually 8 or 16) and possibly some additional interrupt-on-change functionality.

alex.forencich
  • 40,694
  • 1
  • 68
  • 109
1

This should be relatively simple IMO.

If you want to use analog, then the code for Arduino 1 (Writer) would be as follows:

byte myByte=0;
void setup(){
pinMode(3,OUTPUT);
}

void loop(){
if(somethingHappens){
myByte++;
}
analogWrite(3,myByte); 
}

And Aruino 2 (reader) would read it as follows:

byte readByte;
void setup(){
Serial.begin(9600);
}

void loop(){
readByte=analogRead(0);
Serial.println(readByte);
}
Stuyvenstein
  • 161
  • 7
1

Normally, this should work exactly like you would think, and nothing will be damaged. However, some people choose to put a resistor between the pins, just in case a programming error should accidentally set both pins to be outputs. It's not neccesary, but if you do anything where one wire is used bidirectionally and devices change input/output roles it is a good idea. Otherwise, you should be fine.

Also, Stuyvenstein's answer might give slightly odd results, because AFAIK the analogWrite() function on almost all arduino board variations is implemented with hardware PWM, not true DAC. You can use an RC filter to get real analog from the PWM though. IIRC the frequency is something like 490Hz.

EternityForest
  • 691
  • 4
  • 6