Hi ALL!!
I am a complete noob, but this is my predicament, I have a set of hardware that have UART ports on them, the software is written by Victron the solar people, now, the first thing that I can say is the using the softwareSerial.h library with this script…
#include <SoftwareSerial.h>
SoftwareSerial MPPT(3, 5);
void setup() {
// initialize both serial ports:
Serial.begin(19200);
MPPT.begin(19200); // RX 3 TX 5
}
void loop() {
// read from port 1, send to port 0:
if (MPPT.available()) {
int inByte = MPPT.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
MPPT.write(inByte);
}
}
Actually works. The Victron connect software is able to communicate with the device I plug into.
What I want to do is to be able to read and communicate with two devices, one, the MPPT and the other is a BMV, I do understand that this can’t be done at once I know and am good with this, the software can only read one device at a time anyway, so my idea is to use one of the analog inputs when it is high (+ 5V) then it communicates with one device when it goes low(0V) then it stops communication with the one device and starts reading with the other device.
I have come up with the following code, BUT, what happens here is that in the serial monitor is when the intput pin goes low it reads from the BMV this I can see from what is coming in from the BMV, when I change the switch to the high side then the code stops, so I would think not receiving anything from the MPPT for some reason, Also when I close out the IDE software and start up the Victron connect software it does not find any device even when I have the input low and the BMV is sending data.
#include <SoftwareSerial.h>
SoftwareSerial MPPT(3, 5);
void setup() {
// initialize both serial ports:
Serial.begin(19200);
MPPT.begin(19200); // RX 3 TX 5
}
void loop() {
// read from port 1, send to port 0:
if (MPPT.available()) {
int inByte = MPPT.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
MPPT.write(inByte);
}
}
Like I said I am a noob, I do not have money for something like a mega and I have to import stuff so it becomes expensive, I am using an Arduino uno, if that makes any difference.
Any help is welcome.
I hope I have used the insert code button correctly.
Kind regards,
Charles from Namibia.