Simultaneously serial printing from analogRead and from SoftwareSerial Rx Tx

Hi, I am using an Arduino Nano to collect data from different devices, and further plotting with Python. Now I want to plot a potentiometer against a ORP (redox potential) probe. Because I want mV precision from the Redox, I use an EZO ORP Circuit from Atlas Scientific connected to my Rx and Tx of the Nano. The following gives me the precise Redox values printed on my Serial :

#include <SoftwareSerial.h>                           
#define rx 2                                          
#define tx 3      
SoftwareSerial mySerial(rx, tx); 
void setup() {
}
void loop() {
}

Even though no serial print is explicitly code.
However when trying to combine it with the potentiometer through a simple AnalogRead:

int raw = 0;
float Vout = 0;

#include <SoftwareSerial.h>                          
#define rx 2                                          
#define tx 3      //define what pin tx is going to be

SoftwareSerial mySerial(rx, tx); 


void setup() {
  Serial.begin(9600);
}

void loop() { // run over and over

  char c = mySerial.read();
  mySerial.print(c);
 
  
  raw = analogRead(A0);   
 Vout = (5.0 / 1023.0) * raw;
 Serial.println(Vout);
  
 
}

I only get the analog value printed out. Any help on how can I get both of them?

ivino:
The following gives me the precise Redox values printed on my Serial :

Something tells me that you have not posted the correct code (i.e. I looked at the link you gave).

Post the correct code and we may be able to make progress.

...R

It is seriously the correct code :confused: By Uploading that code to the board and going to the serial monitor I do get the correct values.

Hi,

 char c = mySerial.read();[color=#222222][/color]
  mySerial.print(c);

You read from mySerial.
Then print to mySerial???????

How is that going to be sent out Serial.

Tom... :slight_smile:

Thanks Tom! :slight_smile:

No I am getting two different values out, but the one from the SoftwareSerial is a -1, which means it is empty :frowning: .

Any clue on how I can print the data that prints the first code (the one where no printing function is called...)?

Cheers

ivino:
It is seriously the correct code

Oh no it's not - quote from Original Post

#include <SoftwareSerial.h>                           
#define rx 2                                         
#define tx 3     
SoftwareSerial mySerial(rx, tx);
void setup() {
}
void loop() {
}

...R

Hej Robin,

If what you refer to is that the my code is no the same that the one proposed in the link, yes you are right. Is that what you mean?

I have tried the proposed code from the link, but didn't get it to work. After using several hours on it, I came to the point where:

#include <SoftwareSerial.h>                         
#define rx 2                                          
#define tx 3      

SoftwareSerial mySerial(rx, tx); 


void setup() {
 
}

void loop() { 
}

Gave me the values in the serial monitor.
I think I will raise a new topic because I don't think I have posted my question properly. But thanks Anyway.

I use an EZO ORP Circuit from Atlas Scientific connected to my Rx and Tx of the Nano

The only explanation I can think of why your first code prints to serial monitor:

You have swapped RX and TX between the EZO and the nano. Your EZO TX is connected to the Nano TX; the nano TX goes through the USB chip to the PC (and serial monitor).

What is connected to mySerial? Time for a little schematic, I think. Scan/photo of hand-drawn one will do.

Here's a picture :slight_smile:

OK, you don't even need a sketch to get your signal to the PC, only power to the Nano is sufficient.

The TX of the EZO is connected to the TX1 of the Nano; the TX1 of the Nano is connected to FT232 USB chip and that connects to the PC.

So what do you want to achieve? Where does the mySerial come in.

Did you want to connect the EZO to software serial so you can read it with the nano and next send the data to the PC using the hardware serial (USB, which is basically TX1)? And next also read the potentiometer and send its data to the PC?

ivino:
If what you refer to is that the my code is no the same that the one proposed in the link, yes you are right. Is that what you mean?

You need to post the actual code that you are using so we can see what you can see.

And please don't start a new Thread - just keep going with this one so we have all the information in one place.

The code I posted in Reply #5 (and which I copied from your Original Post) has no code either in setup() or in loop() so it cannot do anything.

...R

Robin2:
The code I posted in Reply #5 (and which I copied from your Original Post) has no code either in setup() or in loop() so it cannot do anything.

The code doesn't but the wiring does :wink:

Hi,
This is what we are trying to explain.

The ATLAS is communicating DIRECTLY with the PC.
You have Tx of the ATLAS connected to TX of the 328, No Comms
You have Tx of the ATLAS connected to the RX of the USB interface board, Comms to PC.

Tom... :slight_smile:

Hi,
You need something like this;


Look at this link

It even has two port example code.
Tom... :slight_smile:

TomGeorge:
This is what we are trying to explain.

Well done - that had not occurred to me.

It explains why a seemingly impossible program appeared to be working. - and of course it was not working, the Arduino was just being bypassed.

...R

Thanks a lot TomGeorge, I'll put my electronics into place! Really helpful :slight_smile:

And Robin, this post should not have come into programming....if only I knew it! :-\

Hey Sterretje,

Sorry I oversaw your question:

sterretje:
Did you want to connect the EZO to software serial so you can read it with the nano and next send the data to the PC using the hardware serial (USB, which is basically TX1)? And next also read the potentiometer and send its data to the PC?

Yes, it is my intention of doing so! :slight_smile:

ivino:
Sorry I oversaw your question:

This is meant entirely in a friendly an humorous manner.

English is a weird language. I believe you mean " ... I overlooked your ..." in other words, that you missed the question.

The word "oversaw" means almost the opposite. An "overseer" is the person who watches carefully to ensure the job is done properly.

And just to make matters really confusing "look over" also means almost the opposite of "overlook". "Please look over my program" means please examine it.

:slight_smile: :slight_smile:

...R

ivino:
Hey Sterretje,

Sorry I oversaw your question:

Yes, it is my intention of doing so! :slight_smile:

Don't worry, @Robin2 also missed it :wink:

Anyway, I think that TomGeorge gave you sufficient ammunition to continue.

sterretje:
Don't worry, @Robin2 also missed it :wink:

Anyway, I think that TomGeorge gave you sufficient ammunition to continue.

Yes! I got sufficient ammo to get through the bumps! but I have finally realized that I cannot go on with the EZO board....

The EZO boards only writes once a second, even I set the BaudRate to 9600, as I also have for my other sensors. And since the way I have in Python of knowing which analog Input is which, is through printing them separated by spaces or lines, then I am pretty messed up to catch the EZO spittings!

I have started another thread trying to make my own EZO, i.e. reading a voltage difference from -1000mV to 1000mV from two electrodes.

Thanks for your help guys, I appreciate it. Also the language constructuctive critics :-p