Hi,
Is it possible to have two arduino's read the value of one distance sensor? I have a project where one arduino controls Servo's when reading the distance. Another arduino controls multiple LED series. The LED-brightness is mapped with the distance.
Thanks!
Hmmmm.... the Arduino doesn't actually read the diatance, in the sense of say a voltage on an analog pin which might work on two Arduinos. It sends a pulse, waits for the response, and measures the time the trip took, so I'd hazard a guess that won't work on two Arduinos at once.
Maybe you could send the value from one to the other?
But my next question has to be.... why can't you control the servos and the LEDs with just one Arduino in the first place?
JimboZA:
Hmmmm.... the Arduino doesn't actually read the diatance, in the sense of say a voltage on an analog pin which might work on two Arduinos. It sends a pulse, waits for the response, and measures the time the trip took, so I'd hazard a guess that won't work on two Arduinos at once.
Maybe you could send the value from one to the other?
But my next question has to be.... why can't you control the servos and the LEDs with just one Arduino in the first place?
That's because I didn't have anough PWM pins on one arduino to control everything. But because I have two arduino's I hoped it might work...
Why don't you experiment and see if you can get it to work.
Regarding comms between the two Arduinos, I'm just reading this about I2C... it may be possible to send the distance as measured on one, to the other.
edit.... in fact reading that Instructable, that looks trivially simple.
Just tested Uno to Uno like in that Instructable, works a treat. (Due to laziness I didn't use pullups. Due to thinking it's not right I didn't join the 5Vs together- had both Unos running off USBs from laptop.)
Dead simple, so you could easily just send the distance as measured on one Uno to the other, like the "x" in the Instructable. (I changed the slave code as shown below, just to print the value of x rather than switching LEDs.)
Slave code:
#include <Wire.h>
//based on this instructable
//http://www.instructables.com/id/I2C-between-Arduinos/#step0
//but it serial prints "x" rather than blinking LEDs
//JimboZA June 2015
#define LED_PIN 13
int x;
void setup() {
Wire.begin(9); // Start I2C Bus as a Slave (Device Number 9)
Wire.onReceive(receiveEvent); // register event
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
Serial.begin(9600);
x = 0;
}
void loop() {
Serial.println(x);
delay(1000);
}
void receiveEvent(int howMany) {
x = Wire.read(); // receive byte as an integer
}