Hello Arduino lovers,
I am trying to get digital inputs from an oxygen monitor using Rx and Tx. I am using Arduino mega2560. How do i write the code for it. I have attached datasheet of the sensor. Please help. Should i use the below code as reference?
#include <SoftwareSerial.h>
SoftwareSerial mySerial(19, 18); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Native USB only
}
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(38400);
mySerial.println("Hello, world?");
}
void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
similar to your code of post #1 but using Mega Serial1
// Arduino Mega serial1 test
// mega pin 18 is Tx
// pin 19 is Rx
// for loopback test connect pin 18 to pin 19
unsigned long time;
void setup() {
Serial.begin(115200); // initialise serial monitor port
Serial1.begin(115200); // initialise Serial1
Serial.write("Arduino Mega Serial1 test - for loopback test connect pin 18 to pin 19\n");
}
void loop() {
if (Serial1.available()) // read from Serial1 output to Serial
Serial.write(Serial1.read());
if (Serial.available()) { // read from Serial outut to Serial1
int inByte = Serial.read();
//Serial.write(inByte); // local echo if required
Serial1.write(inByte);
}
}
you can do a simple loopback test by connecting Mega pin18 to pin 19
a loopback run gives
Arduino Mega Serial1 test - for loopback test connect pin 18 to pin 19
this is a test
1234567890
I understood that it is not I2C communication. But how do i get the data on TX and RX in the serial monitor? I did all the connections. i.e. 12v,gnd,tx,rx