Go Down

Topic: Comunicating ADC+ Arduino DUE with the protocol 1-wire (Read 17420 times) previous topic - next topic

graynomad

#30
Mar 30, 2014, 01:37 pm Last Edit: Mar 30, 2014, 02:06 pm by Graynomad Reason: 1
Ok now let's look at the program, as I understand it you can get the same strings from either the PC or another Arduino...or maybe not.

The two arrays are different sizes, are the strings expected from the PC and other Arduino also different sizes?

Can you spell out the program requirements in a few lines like,

if I get a string from Serial0, parse it and do X
if I get a string from Serial1, parse it and do Y

EDIT: I see you did describe things fairly well in post #20, I'm trying to get my head around it.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Due88

If I received by serial port 0 from laptop the string "$ADQ,P00,CH1" in the buffer I must have 13 bytes (12 bytes + NULL character)  no?

The laptop send me  by the same serial port differents strings. For example string of Mode ("0" or "1") and the strings like "$ADQ,P00,CH1". How I can differentitate between these strings in the same buffer?  :~

graynomad

Quote
Example: If I want receive sensor's information (microcontroller 1 's channel0)  I will sent to Arduino: "$ADQ,P01,CH0" and Arduino send this information to microcontrollers connected by bus RS485 and Arduino will wait for resply from microcontrollers.

So in this case the data received from the PC is simply echoed to the sensors. Is that the case?

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

graynomad

Quote
The laptop send me  by the same serial port differents strings.
But don't you only handle one at a time?

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Due88

Algorithm of the program:

1- Received datas from PC. PC send to Arduino AUTOMATIC MODE ("0" or "1") and too the strings like "$ADQ,P01,CH01" (Arduino will send to microcontrollers the strings from PC ("$ADQ,P01,CH1") if the automatic mode is "0". If the automatic mode is "1! Arduino send these strings automatically.

2- Arduino receiven datas from microcontrollers (datas like "$DAT,P01,CH2,n" where n is the ADC conversion (0 to 1024) by different serial port (serial port 1)

3- Arduino rentrasmit the microcontrollers' strings (strings like "$DAT,P01,CH2,n") to PC by serial port (serial port 0).

Due88


Quote
Example: If I want receive sensor's information (microcontroller 1 's channel0)  I will sent to Arduino: "$ADQ,P01,CH0" and Arduino send this information to microcontrollers connected by bus RS485 and Arduino will wait for resply from microcontrollers.

So in this case the data received from the PC is simply echoed to the sensors. Is that the case?

______
Rob


Yes, it is a  simple echo .

graynomad

OK, so forgetting auto mode for the moment, it seems that we have  a simple algorithm that echoes serial0 to serial1 and vice versa. Is there any need for more than that?

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Due88


Quote
The laptop send me  by the same serial port differents strings.
But don't you only handle one at a time?

______
Rob


My idea is handle one at a time and differentiate the strings that I received from pc by serial port

graynomad

Posts crossed.

So can't you just do
Code: [Select]

If (Serial0.available()) Serial1.write(Serial0.read();
If (Serial1.available()) Serial0.write(Serial1.read();


Quote
differentiate the strins that I received from pc by serial port

Not sure what that means as there is only a single serial port connected to the PC.Why do you need to differentiate anything?

______
Rob

Rob Gray aka the GRAYnomad www.robgray.com

Due88


OK, so forgetting auto mode for the moment, it seems that we have  a simple algorithm that echoes serial0 to serial1 and vice versa. Is there any need for more than that?

______
Rob



there isn't any need more than that. The algorithm is simply (retransmit strings to microcontrollers when the automatic mode is "0" and send automatically the strings to microcontrollers when the automatic mode is "1". And too received and retransmit the strings from microcontrollers to PC) but I have little time with Arduino and for me is a little complicated. And my english don't  help with this.

graynomad

That's OK, so can you try my example code? Or don't you have the sensors working yet?

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Due88

#41
Mar 30, 2014, 02:37 pm Last Edit: Mar 30, 2014, 02:39 pm by Due88 Reason: 1
PC send to Arduino the mode ("0" or "1") and next (if the automatic mode is "0") the  strings like ("$ADQ,P03,CH4") by serial port 0. I need differentiate these strings no? or it isn't necessary?

When you use : Serial0.read() you have received only 1 byte no?  (the string "$ADQ,P03,CH4" have 13 bytes)

this is a solution from retransmit strings?

Code: [Select]
If (Serial0.available()) Serial1.write(Serial0.read();
If (Serial1.available()) Serial0.write(Serial1.read();



Thanks :)

Due88


graynomad

Quote
When you use : Serial0.read() you have received only 1 byte no?  (the string "$ADQ,P03,CH4" have 13 bytes)
Correct, so you receive and transmit 13 times, I see no need to buffer anything so far.

Quote
I need differentiate these strings no? or it isn't necessary?
I don't see what you mean by "differentiate", it seems that the sensors are smart and they decode the strings, the Arduino does nothing but pass data back and forth. Two wires would work the same.

But I don't get what "automatic" mode is yet. What is mode 1 and 0?

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Due88

#44
Mar 30, 2014, 03:26 pm Last Edit: Mar 30, 2014, 03:29 pm by Due88 Reason: 1
Yes the two wires (two serial ports) works at same time but when the arduino is working with the serial port 0 (serial port that cominicate Arduino-PC) the laptop send to Arduino two types of strings (AutomaticMODE ("1" or "0") and "$ADQ,Pxx,CHx") and I need create a technique for read each one.

Mode is the AutomaticMode "0" or "1". When I speak with you I say Mode (but really is AutomaticMode)


Go Up