Hello, I wanted to ask a question. I am doing a project in which an arduino mega is communicating with another arduino uno, through serial communication (TX, Rx), several sensors are connected to the arduino mega, and the arduino uno is receiving information from the arduino mega . Now my problem is that I want to add a distance sensor on the arduino mega, but this distance sensor uses serial communication (Tx, Rx), but since a serial port is already occupied (for the arduino uno and arduino mega communication). How can I connect it to my arduino mega, without interfering with the data transmission of the other sensors, and so that this information (distance sensor) can also be sent to the arduino uno?
This is not an installation and troubleshooting issue… read the stickies and post in the correct category.
➜ I moved you post to a better place.
We miss so much information to be able to help. do yourself a favour and please read How to get the best out of this forum and post accordingly, (including necessary documentation for your ask like what is connected to the MEGA, how you linked the MEGA to the UNO, remaining pins unused etc…)
Hello camsysca. But a serial port on the arduino mega is already occupied, to communicate with the arduino uno. If I connect the distance sensor to another port, how can I make this data be sent via serial port to the Arduino Uno?
my question, is it possible to do this?
Hello, I wanted to ask a question. I am doing a project in which an arduino mega communicates with another arduino uno, using Xbee, these Xbees are connected to each arduino, in the serial pins (Rx---0, TX---1), several sensors are connected to the arduino mega and the arduino uno is receiving information from the arduino mega. Now my problem is that I want to add a distance sensor on the arduino mega, but this distance sensor uses serial communication (Tx, Rx), but as a serial port it is already occupied (for arduino uno and arduino mega communication via xbee modules ). I have connected the sensor to another serial port (Rx---19, Tx----18), by doing this, could the distance sensor information be sent, so that the arduino uno can receive it?, without interfering with transmission of data from the other sensors.
On the Mega, there is no need to use the normal serial port (pins 0 and 1) for communication with the Uno. Use one of the other ones (e.g. RX1 and TX1) and adjust your code to use Serial1 for communication with the Uno.
That leaves you RX2/TX2 and RX3/TX3 for communication with the (new) distance sensor; use Serial2 or Serial3 respectively.
Below just a demonstration; it compiles but is not tested
void setup() {
// for debugging on e.g. serial monitor
Serial.begin(115200);
// for communication with the Uno
Serial1.begin(115200);
// for communication with the distance sensor
Serial3.begin(9600);
Serial.println(F("Mega started"));
}
void loop() {
// if data received from Uno
if (Serial1.available()) {
// send to serial monitor
Serial.print(F("Received from Uno: "));
Serial.write(Serial1.read());
Serial.println();
}
// if data received from distance sensor
if (Serial3.available()) {
char ch = Serial3.read();
// send to serial monitor
Serial.print(F("Received from distance sensor: "));
Serial.write(ch);
Serial.println();
// send to Uno
Serial1.write(ch);
}
}
a digital type temperature sensor is connected to the mega, using pin 8, in addition to the ADXL345 acceleration sensor, also the GY30 light sensor, these two sensors, connected by i2C communication. Also connected by serial port Rx and tx an xbee module. All this data from the sensors is being sent to another arduino uno, by means of xbee radiofrequency, in the arduino uno only another xbee module (slave) is connected. Now my question is how to send the sensor data that I want implement a distance sensor (TF mini Plus), taking into account that it is connected by serial communication, that is, it occupies another serial port.
do you understand me?
Thank you very much, for answering my question, the code you have provided me, I have a question, is that the distance sensor data, I also want to send them through the serial port that communicates with Arduino Uno, is it possible to do this?
In the example the distance sensor is connected to RX3/TX3 of the Mega. Data is send to the serial monitor that is connected to the Mega AND to the Uno connected to RX1/TX1.