Hardware switch to switch the software serial pins being "transceived" on.

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.

Like an idiot I posted the wrong code in the second bit Sorry…

#include <SoftwareSerial.h>
 
SoftwareSerial MPPT(3, 5); //Naming Pins And Input
SoftwareSerial BMV(6, 9); //Naming Pins And Input
const int threshold = 800; // Tells when to change state

void setup() {
  // initialize both serial ports:
  Serial.begin(19200);
  MPPT.begin(19200); // RX 3 TX 5
  BMV.begin(19200); // RX 6 TX 9
}

void loop() {
   int analogValue = analogRead(A0);
  // read from port 1, send to port 0:
   if (analogValue > threshold)
   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);
  }

       analogValue = analogRead(A0);
   if (analogValue < threshold)
   if (BMV.available()) {
   int inByte = BMV.read();
    Serial.write(inByte);
  }

 
  // read from port 0, send to port 1:
    if (Serial.available()) {
    int inByte = Serial.read();
   BMV.write(inByte);
  }}

You have to use SoftwareSerial.listen() to tell it which instance is to be used. RTFM

...R
Serial Input Basics

@Robin2: Thank you for answering, may I ask you though, when making a statement could you possibly refrain from using profanities such as the "F" in RTFM. RTM would have sufficed, I will pay more attention to a person who will help me, show me an example that I can relate to I did read the serial statement but it does not make sense to me as I am not that clued up in the language, and as such need an example that I can understand. I as allot of people that ask for help here are weekend tinkerers, we do not spend day in and out programming, we get an idea and then refer to pro's like yourself for correction in what needs to be done. Again, I thank you for taking the time to answer. I will refer back to the statement and try to understand what it says. Thank you kindly...

Kind Regards
Charles from Namibia.

Charles_Gibbs:
could you possibly refrain from using profanities such as the "F" in RTFM.

The 'F' in RTFM stands for "fabulous"

I don't think anyone who is doing programming nowadays treats the acronym as anything other than "the data you need is in the manual"

And people know what RTFM means but may not know what RTM means.

...R

Ha Ha ha ha ha ......... Egg on my face! Nice I have to remember that one then........I DO THEN APOLOGIZE FOR HAVING SAID IT WAS A PROFANITY........ Have read the serial thing again...... I do not want to print anything to Serial.print can I leave that line out or is it mandatory to be in the programming? If I am understanding it correctly, in my instance I will input the following?

void loop() {
   int analogValue = analogRead(A0);
  // read from port 1, send to port 0:
   if (analogValue > threshold)
   MPPT.listen()
  if (MPPT.available()) {
   int inByte = MPPT.read();
    Serial.write(inByte);
  }

And in the next bit how do I stop that port from being listened to? Do I just tell it to listen to the second one? Will it terminate listening to the first port on it's own?

Kind Regards.
Charles from Namibia.

Charles_Gibbs:
And in the next bit how do I stop that port from being listened to? Do I just tell it to listen to the second one?

Yes.

You may eventually conclude that using 2 SoftwareSerial ports does not work well and that an Arduino Mega which has three spare HardwareSerial ports would be a much better solution.

...R

Thanks Robin.

Yes a mega would prove better, but as I have said that means importing and that tends to become expensive when it comes to customs, so I will have to make do with what I have, I will try this and revert back to then either be solved or to look for further info.

Kind Regards.

Charles from Namibia.

Hi Robin2.

Well, half success???

I did the code as below, as I thought, the serial monitor could pick up the change and read both my Mppt data, and the BMV in turn, BUT!.. The Victron software interface could not make heads or tales, I could see the software query the Arduino and it will do that for a couple of secs and then say no device found on both the states, is there a way in which I can write a small bit of code to initialize one set of commands and when the state changes another type? I don’t think I said that well, basically 3 programs, the first one checks the state, high or low, then it sets one or the other program in motion, so that the Victron software will only see the MPPT or the BMV, sorry for all the questions but if you can point me in the right direction I would be grateful, I like to do stuff myself that is how I learn, I am not good with just books, but books and actions good teacher for me…

Thanks for all the help.
Kind Regards.
Charles from Namibia
Ps. Code below:

#include <SoftwareSerial.h>
 
SoftwareSerial MPPT(3, 5); //Naming Pins And Input
SoftwareSerial BMV(6, 9); //Naming Pins And Input
const int threshold = 800; // Tells when to change state

void setup() {
  // initialize both serial ports:
  Serial.begin(19200);
  MPPT.begin(19200); // RX 3 TX 5
  BMV.begin(19200); // RX 6 TX 9
}

void loop() {
   int analogValue = analogRead(A0);
  // read from port 1, send to port 0:
   if (analogValue > 800)
   MPPT.listen();
   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);
  }

       analogValue = analogRead(A0);
   if (analogValue < threshold)
   BMV.listen();
   if (BMV.available()) {
   int inByte = BMV.read();
    Serial.write(inByte);
  }

 
  // read from port 0, send to port 1:
    if (Serial.available()) {
    int inByte = Serial.read();
   BMV.write(inByte);
  }}

Charles_Gibbs:
I did the code as below, as I thought, the serial monitor could pick up the change and read both my Mppt data, and the BMV in turn, BUT!.. The Victron software interface could not make heads or tales, I could see the software query the Arduino and it will do that for a couple of secs and then say no device found on both the states, is there a way in which I can write a small bit of code to initialize one set of commands and when the state changes another type? I don’t think I said that well, basically 3 programs, the first one checks the state, high or low, then it sets one or the other program in motion, so that the Victron software will only see the MPPT or the BMV, sorry for all the questions but if you can point me in the right direction I would be grateful, I like to do stuff myself that is how I learn, I am not good with just books, but books and actions good teacher for me…

I’m afraid you will need to have another go at explaining what you want. It can be useful to write the processes as a series of steps with one step on each line - for example (very crudely) …

listen for mppt()
if message received before timeout
deal with message
if timeout or message processed
switch to listen for bmv()
etc etc

Your Reply #8 implies that the Victron device has some requirements that must be met - what are they?

What is a “BMV” ?

What exactly is the Victron device and what exactly are the roles of it, the mppt(), the bmv() and the Arduino?

…R

Hi Robin2.

Ok, Victron Is a solar power supply manufacturer, so they supply invertors (and more) and solar charge controllers known as MPPT's or Multi Power Point Trackers they take the power generated by your solar panels and in turn charge the batteries in the most effective way possible, the MPPT give info on its UART port that tells you what power is coming from your panels and what is going to the batteries, a BMV a Battery Monitoring Voltmeter, it's UART port gives battery stats, normally to read these devices into the software you need two separet UART to USB dongles, problem with laptops is the lacking number of USB ports that they have, what I would like to do is use one usb port to monitor both these devices in turn, it saves a USB port and the extra 800 bucks for yet another dongle, the other thing is that the software can only monitor one device at a time anyway. So, using Software.Serial seems like right way to go, the role then of the Arduino is to replace the 2 dongles with just the Arduino. I just don't want to unplug and replug on the Arduino as that would mess up its contacts anyway after a bit....

Ps. Allot of Victrons stuff is made open source so they give people the opertunaty to come up with alternative means of monitoring and interfacing with their products it must just be kept open source..

Thanks for hearing me out....
I appreciate it.....

Kind Regards.
Charles from Namibia.

You are still not very clear. I am aware of the Victron company and the sort of products it produces. What I was hoping to find out is exactly what Victron product you are using. I also know what mppt is - I have solar panels on my boat (this laptop is being powered by them right now) but I don't have an mppt myself.

It sounds as if you have a Victron mppt device and a separate BMV device and both of them can send out serial data.

What is not clear is how they send data - for example are they both continuously sending data so that if you listen to one device you miss data from the other? OR, do you have to do something (send a request, for example) to cause one or both devices to send out a message.

You said earlier "The Victron software interface could not make heads or tales, I could see the software query the Arduino and it will do that for a couple of secs and then say no device found on both the states" but I don't understand the underlying context so I can make sense of that or suggest a solution.

...R

Ok. Sorry for that. The MPPT and BMV are constantly sending data, if I use the first code then the rx/tx leds flash breifly once I plug the arduino into the usb port, after that the tx led flashes every couple of seconds as it gets the data from the device plugged in at that time and passes it on (to what I do not know as I have then not opened the Victron connect app).... Once I open the app it starts looking for devices when it does that the arduinos rx/tx leds flash (I suppose a handshake of some sort) where after the tx led on the arduino flashes every few seconds, by then in the software whatever I have plugged in on that UART then appears in the window, I can then click on it and the readings are then displayed in GUI format, the code sent is ASCII format if you would like I can attach the code and a screen shot of the GUI?

The MPPT is a Blue solar 150/35
and the BMV is the BMV700.

Thank you.

Kind Regards.
Charles from Namibia....

Charles_Gibbs:
the Victron connect app

I did not understand until now that you are trying to connect with some Victron software running on your PC. I thought you were trying to connect your Arduino to a Victron hardware device that sends data over a serial link.

Please explain what is the normal (Victron intended) usage of the Victron PC program and what you are trying to do that is different.

Do you have access to the programming interface for the Victron PC program - if not I suspect you are faced with a lot of long nights and a lot of coffee trying to figure it out.

Without the details of the programming interface it might actually be simpler just to write your own PC program to collect and display whatever data you want.

...R

Hi Robin,

It’s the standard Victron connect app, running on windows.

In screenshot 35 this is what I see after start up, it shows only one device but that is because there is only the MPPT, in screenshot 35 this is the info that I get, in screenshot 36 is the serial monitor with the ASCII code, What I want to do is connect both the victron devices to the arduino, and the arduino to the usb on my laptop and then select the devices one at a time and then read what is being sent through via the victron app as it is, I would like to be able to use the arduino as a two input ONE read at a time device but be able to switch between the two via the app.

Hope that explains it, there is an id code that I think the software looks for when it is plugged in, I am going to try and serial print it to see what happens when it is printed to the Victron software.

If you have any ideas, please let me know…

Regards
Charles.

Images from Reply #14 so we don’t have to download them. See this Simple Image Guide

91cc46f45a758e78feabdc87e347c431d8dcbb65.png

3a8d0639784c9b37d2b365bda8b9f4c3de01cf4f.jpg

44d43fe120026787ebbd057325ea5ab01972ea34.png

…R

Charles_Gibbs:
It's the standard Victron connect app, running on windows.

I have no idea what "the standard Victron app" is - I did not even know such thing existed before you mentioned it.

What I want to do is connect both the victron devices to the arduino, and the arduino to the usb on my laptop and then select the devices one at a time and then read what is being sent through via the victron app as it is, I would like to be able to use the arduino as a two input ONE read at a time device but be able to switch between the two via the app.

Your way of describing things is very imprecise. For example you talk about victron devices and victron app without clearly stating what each of them is so it is very hard to understand.

My wild guess is that the Victron program is designed to detect multiple USB connections and can either select between them or show data from both of them.

If so there is no possibility (short of re-writing the Victron program) of getting it to think that one Arduino is two different things because all it will see is one USB connection.

As I mentioned earlier you either need access to the documentation for the Victron programming interface or you need to ignore the Victron program completely and just write your own PC program.

...R

PS... please don't post pictures of text (as in your 3rd image). It is quite unreadable. Just copy and paste text.

Hi Robin2.

Ok sorry for all the hiccups, I do try to be as precise as I possibly can, that is what happens when two different worlds get together, sorry if I have wasted your time, all the ascii code is available for both the devices both query and answer I just do not know how to work with it and how to interperit it all.

Thanks for all your help.

regards
Charles.

What it seems you are describing is a multiplexer - something like a 74HC_HCT4052 . This will allow selection two banks of four unique *analog * or digital signals and route them to/from a single pair of pins. Which of the four signals is connected to the single pin is controlled by two address pins.

If the Arduino controls the address pins you can choose, under program control, which xmit/rcv signal pair is active.

Charles_Gibbs:
Ok sorry for all the hiccups, I do try to be as precise as I possibly can,

I don’t think this is a two-worlds problem at all. You have not responded to confirm or deny my guess as to how the Victron program works.

This has to be a two-way dialogue. I say something, you consider it, you tell me if I am right or correct me if I am wrong. That way I can build up my mental image of the problem and either make a suggestion for a solution or an explanation of why it is not possible.

To follow on from what @dougp has said, I don’t think this is a simple multiplexing issue. I think the inputs to the Victron program have to be the sort of thing the Victron programmers designed it to expect. And we have not been told what that is.

…R