Arduino Forum

Products => Arduino Due => Topic started by: Due88 on Mar 14, 2014, 11:22 pm

Title: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 14, 2014, 11:22 pm
Hi everyone, sorry if I don't express correctly. I've got an Arduino Due and I'd like to comunicate 10 ADCs with the Arduino DUE by the 1-wire protocol. I don't know if is possible cominicate the ADCs with the Arduino by this protocol (and I doubt if there are ADC that can use this comunication). Are there  any Arduino library for this? I'm novel in this matter.

Thankkssss  :) :)
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 15, 2014, 02:54 pm
I need help please  :(
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 16, 2014, 01:48 am
Quote
(and I doubt if there are ADC that can use this comunication)

I don't understand, do you have 1-wire ADCs or not? You are saying that you doubt they even exist, in which case the entire question is moot.

______
Rob
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 16, 2014, 10:24 am

Quote
(and I doubt if there are ADC that can use this comunication)

I don't understand, do you have 1-wire ADCs or not? You are saying that you doubt they even exist, in which case the entire question is moot.

______
Rob



Sorry... I don't express in english very well. I was researching about 1-wire ADC and now I have some information about it.  This protocol is property of Dallas Semiconductor. Now, I need comunicate my Arduino Due with 10 ADC 1-wire.  My idea is connect this 10 ADC in the same Bus that will be managed by the Arduino Due.

I need implement this protocol (1-wire) in the Arduino Due by software.  This protocol too has a errors control (CRC8) that I need implement.  I ask for examples about it and information links. Thanksss for your response :)
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Markus_L811 on Mar 16, 2014, 01:45 pm
Did you try this?

http://www.pjrc.com/teensy/td_libs_OneWire.html (http://www.pjrc.com/teensy/td_libs_OneWire.html)

Works with the Due
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 16, 2014, 03:50 pm
This library is only for the sensor DS18S20 . I just read in other forum that MAXIM left make the 1-wire ADC.  :( :( In this case, I won't be able use this protocol in the ADC-Arduino's comunication.  I think that I will be able work with SPI protocol. If you know any library that implement SPI protocol tell me please.

And I have other question: Is possible program the Arduino Due with other language (I would like program timer interruptions and able/disable this interruption).  Thanksss a lot!!! ;)
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Markus_L811 on Mar 16, 2014, 06:58 pm
Quote
This library is only for the sensor DS18S20


Not really the OneWireLib (http://www.pjrc.com/teensy/arduino_libraries/OneWire.zip) is for the OneWire Protokol, the Lib from Miles Burton is specialy for the DS18S20. You need only the Onewirelib for your use. If you tell us the name of you ADC may we can give you an hint to comunicate with it.

Btw. take a look at this http://code.google.com/p/gfb/source/browse/arduino/DS2450/?r=22 (http://code.google.com/p/gfb/source/browse/arduino/DS2450/?r=22)
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 16, 2014, 08:11 pm
The ADC that I would like use is DS2450 but I just read in other forum that MAXIM left make the 1-wire ADC.  Is truth that the MAXIM (Dallas Semiconductor) is the only property of 1-Wire protocol? Can I use other maker for use ADC with 1-wire protocol? Thankss
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 17, 2014, 12:02 am
Now that you mention it I can only remember ever seeing MAXIM/DS chips with 1-wire, but that's not to say there aren't other manufacturers.

Quote
Can I use other maker for use ADC with 1-wire protocol?

Sure, if you can find one.

Why are you so fixed on 1-wire? There are a lot more options with I2C and it's only one more wire.

______
Rob
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Markus_L811 on Mar 17, 2014, 09:20 am

Now that you mention it I can only remember ever seeing MAXIM/DS chips with 1-wire, but that's not to say there aren't other manufacturers.

Quote
Can I use other maker for use ADC with 1-wire protocol?

Sure, if you can find one.

Why are you so fixed on 1-wire? There are a lot more options with I2C and it's only one more wire.

______
Rob


Yes Graynomad is right there are so many options, I2C, SPI, Serial and Parallel and I'm sure Graynomad knows some more. Btw. and faster as OneWire are they too.

Start at the beginning what do you want with an external ADC? The DUE has some inside itself 12bit if I'm right, goes from 0 to 3.3Volt.
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 17, 2014, 04:41 pm
The project that I need design is create 10 temperature sensors that will measure the temperature in 10 diferents positions . The distance from SENSORS+ADCS to Arduino Due is approximately 30m. (This distance is too big for use I2C or SPI).

I need design 10 temperature sensors.  These sensors will be connect with one or more ADC (depend of the number of channels). These ADC will send the data to Arduino Due. Now, I need to think the protocol that will comunicate the ADC and the Arduino.  I read yesterday that the MAXIM was the only manufacturer that would produced  the ADC 1wire but now doesn't (Is possible that I'm confuse).

If I decide comunicate the SENSORS+ADC with the Arduino by SERIAL protocol (RS232) I think that I need use a PIC for manage this Serial protocol in the connection SENSORS+ADC - ARDUINO yes? 

The mesure of the temperatures must be sufficient precise and If I decide use a PIC that incorpores ADCS I could use them for the temperature sensors but I don't know if this mesure will be precise.... 

I wait for your responses (Thanks and sorry if I don't express correctly)  :)
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Markus_L811 on Mar 17, 2014, 06:10 pm
Hmm, ok.

it would be make with DS18B20 the OneWireProtocol would work over this distance
http://www.maximintegrated.com/app-notes/index.mvp/id/148 (http://www.maximintegrated.com/app-notes/index.mvp/id/148)

Range is -55 to +125 Degree.

But if you want realy big distances and high precision so do something like this.

Temp-Sensor->ADC->uC->live-zero-Signal(DIN IEC 60381-1) [4..20mA]->ADC(near DUE)->Some Protocol->DUE

The current Signal is really unaffected by distance and EM-fields in the near.

So you can use any Sensor you want and go to long distances as well but you need to set up an DAC and an OP-circuit, or an IC for the Signal.
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 18, 2014, 04:56 am
Both I2C and SPI can do 30M but not in their standard form, you need drivers and slow(ish) speeds. Heck SPI could do 1.2k if you use RS-485 transceivers and still run at 1MHz.

Quote
I think that I need use a PIC for manage this Serial protocol

Yes a PIC would do, but so would an AVR and you'll get a lot more help here if you use an AVR.

Any CPU with a serial port, a line driver, and an external temp sensor could do this.

Are all 10 sensors at the same place that's 30M from the Due? Or are they all 30M away in different directions?

What is the rate you need to read them?

______
Rob
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: pjrc on Mar 18, 2014, 09:15 pm
30 meters is a very long distance for 1-wire communication.  If you get this to work, which is unlikely, it may not be very reliable.

(I am the current maintainer of the OneWire library, by the way...)

Usually such long distances are done with 4-20 mA analog current or RS-485 serial.

Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 19, 2014, 05:16 pm
Hi everyone! sorry for my later reply.

Markus thanks for your response. I decided use a simple sensor temperature. If I can't use 1wire because the manufacturer don't make 1wire ADC I won't use it. I thought to use 1wire protocol because the quantity of wire is small and with one pin of the Microcontroller I can manage all. But I won't use it because I see that there are other most common protocols.

Graynomad, the 10 sensor will stay in differents positions. The distance between Arduino-10 sensors will be approximately 30m. The distance between sensors will be short (2m).

Paul, I thought yesterday that I can use RS485 because is differential and I can connect others PIC in the bus. This is the best and easy protocol that I could use.

I think that I can do the following idea:  10 sensors temperature (with its voltage-intensity converters) and connect them with a PIC for use its internal ADC. The pic should  have 10 channels ADC for connect 10 sensors. The PIC will process the analogs signals. The pic will connect with the Arduino Due with a RS485 bus.
I will need to adapt the pic's out RS232 for RS485. I think that I can use a MAX485 for adapt it. I think that I must use two MAX485 for adapt the signals between protocols. One of them in the out of the PIC and the other one in the entrance of the Arduino Due's RS232. And I read that Arduino doesn't use TTL voltages in the RS232 (0-3.3V in Arduino?)
if i use RS485 I will be able to connect more PICs in the future if I need use more Sensors (using MAX485). I don't know if MAX485 adapts the TTL signals of the PIC (because the PICs use RS232 but with TTL signals).

New diagram:
[Sensors with I-V Converters} --> PIC's ADC --> MAX485 --> (BUS RS485) <--- MAX485 <--- Arduino Due ----------> DATAS


What do you opinion? Can I use MAX485 easily for adapt the RS232-RS485 and RS485-RS232 conversion?


Thanks a lot for yor responses!! :) :)
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 20, 2014, 12:50 am
Your "diagram" looks correct but your terminology is not. A PIC (or any other CPU for that matter) does not have RS-232, it has a UART that talks async serial. RS-232 is a voltage level spec (as is RS-485) that has nothing to do with the format of the data or anything like that.

Quote
I think that I must use two MAX485 for adapt the signals between protocols. One of them in the out of the PIC and the other one in the entrance of the Arduino Due's RS232.
Yes for two devices you need two RS-485 transceivers, one at each end. Every extra device added needs another transceiver.

The MAX485 is a common choice and of course it works OK, but I don't think it's available in a 3v3 version which you need for the Due end. Check that out, if not try a LTC1480 or similar that does run at 3v3.

Quote
This is the best and easy protocol that I could use.
RS-485 is not a protocol, a protocol is code that implements a set of rules that determine the format of the data being transferred and optionally how to handle errors etc. You will have to write the protocol. That said yes I think RS-485 is the best method.

Quote
I can connect others PIC in the bus

Again, why a PIC? Not that there's anything wrong with PICs but you won't get much (or any) help here with them.

______
Rob


Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 21, 2014, 09:26 pm
Thanks Graynomad! I am learning more in this forum  :)

The part of the pics is solved (that part is not a big problem now). I will send from Pics to Arduino a value type Float. For example, the smaller value that I can obtain with the measure of the Pic's ADC(10bits) is 5V/1024 =0,00488V. The smaller value that Arduino will receive by serial port is that.   Will the arduino's serial port receive packet of the 8bits? I will send to Arduino the value in string form by pic's serial port. If later I need send by arduino's serial port (to other platform, for example my laptop)  that smaller value I can use a simple "print()" ?

I wish that you understand that explanation. Thanks for your responses.
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 23, 2014, 01:22 pm
Quote
Will the arduino's serial port receive packet of the 8bits?

It will receive whatever you send to it.

Quote
I will send to Arduino the value in string form by pic's serial port.

Then that's what it will receive (subject to faults in the line etc).

Quote
If later I need send by arduino's serial port (to other platform, for example my laptop)  that smaller value I can use a simple "print()" ?

Yes, you can just echo the same data or change it as you see fit.

I won't ask again why you are using a PIC, I'll just assume there is a good reason.

______
Rob
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 25, 2014, 10:53 pm
Thanks a lot  Grainomad and the other users with your help. I am continuing with this project and developing it.  :) :)

I am using pics because the idea is comunicate the Arduino and the sensors with a only bus. I will use the pics' ADC to make the conversion (Analog to digital) and I will save problems (probably this isn't the best  metod).
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 26, 2014, 05:58 am
Quote
I am using pics because the idea is comunicate the Arduino and the sensors with a only bus.
That's a reason to use a processor of any kind and a reasonable decision. I'm just curious as to the choice of a PIC because you won't get much (any) help here with it. So if you are already proficient with PICs fair enough, but if you have to learn a processor anyway it might as well be an AVR.

______
Rob
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 29, 2014, 11:07 pm
Yes, I will use AVR. I think that is a good idea to start with microcontrollers. Now, I am programing the Arduino Due. I am trying to do a program with this algorithm:

The Arduino will receive instructions from my laptop by serial port. The laptop will send two thinks. For example, if I want that the sensors send me its information (temperature information) I will send to Arduino the following string: "$ADQ,Pxx,CHx" where the variable [ x ] is a number 0 to 9.  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. The other think that laptop can send to arduino is the option of  automatic mode.

The laptop too will send to Arduino if I want automatic mode. If I want automatic mode Arduino will send information request by serial port to microcontrollers. Example: if want that Arduino send automatically the strings "$ADQ,Pxx,CHx" by Serial port I need send to Arduino --> Automatic mode = 1. If Automatic mode is 0 Arduino will receive the string  from laptop and will retransmit this information to microcontrollers.

Arduino will receive sensors' information from microcontrollers by serial port and only will retransmit the received strings to laptop by serial port. Example: If Arduino send by bus the following string: "$ADQ,P01,CH0" the microcontroller 1 will respond with the following string :"$ADQ,P01,CH0,n" where  [ n ] is the result of the ADC's conversion in the microcontroller (ADC 10 bits).

I need use two serial ports from Arduino: the first SERIAL0 to connect laptop with arduino and the second SERIAL1 to connect the bus (with microcontrollers) and Arduino. Fisrt, I will send  always the string of automatic mode (AutomaticMode = 0/1) and later if I want manual mode (AutomaticMode=0) I will send the string that I want send (for example "$ADQ,P01,CH0").

I have done some think but I don't know if I am going by good way.


void setup() {

 int AutomaticMode=0;
 int CALL=0;
 
 boolean FlagUART= false;
 
 char DataReceivedMODE[2]={0};
 char DataReceivedSERIAL0[13]={0};
 char DataReceivedSERIAL1[19]={0};

 Serial.begin(9600);
 Serial1.begin(9600);
 
}


void loop() {
 
 CALL= UART0();
 CALL= AnalyzeSensors();
 CALL= UART1();
}



void UART0(){

while(Serial.available()){

if(FlagUART==false){
 
 FlagUART=true;
 
  DataReceivedMODE= Serial.read();
   
   Switch (DataReceivedMODE){
     
     case '1':
     
     AutimaticMode= 0;
     
     break;
     
     case default:
     
     AutomaticMode= 1;
     
     break;
     
     }
   }

else if {FlagUART=true||AutimaticMode==1){
 
 FlagUART=false;
 
 DataReceivedSERIAL0=Serial.read();

  }

else{

 FlagUART=false;

}

 }


}

 return(0);

}


void AnalyzeSensors(){
 
  if (AutomaticMode==1){
     
    Serial1.print("$ADQ,P00,CH0");
    delay(1);
    Serial1.print("$ADQ,P01,CH0");
    delay(1);
    Serial1.print("$ADQ,P02,CH0");
    delay(1);
    Serial1.print("$ADQ,P03,CH0");
    delay(1);
    Serial1.print("$ADQ,P04,CH0");
    delay(1);
    Serial1.print("$ADQ,P05,CH0");
    delay(1);
    Serial1.print("$ADQ,P06,CH0");
    delay(1);
    Serial1.print("$ADQ,P07,CH0");
    delay(1);
    Serial1.print("$ADQ,P08,CH0");
    delay(1);
    Serial1.print("$ADQ,P09,CH0");
    delay(1);
    Serial1.print("$ADQ,P10,CH0");
    delay(1);
   
  }
   
   else{
   
   
   Serial1.print(DataReceivedSERIAL0);
   delay(1);
   
    }

return(0);

}

void UART1() {

while(Serial1.available()){

DataReceivedSERIAL1=Serial1.read();
 
}
 return(0);
 
}


Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 29, 2014, 11:42 pm
Please use CODE tags and provide code that at least compiles, have you tried that code or is it just a collection of semi-random instructions?

For example all the variable declarations in setup() are local to setup(), they are not global, so all references to them from the rest of the code causes errors.

Code: [Select]
CALL= UART0();
  CALL= AnalyzeSensors();
  CALL= UART1();


These functions are void functions, they do not return a value. And even if they did you do not use CALL anyway. Then there's

Code: [Select]
     AutimaticMode= 0;
            break;
            case default:
            AutomaticMode= 1;


AutimaticMode or AutomaticMode?

You should at least try to provide working code, or at least code that compiles.

______
Rob
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 29, 2014, 11:58 pm
Sorry. I am working it and I'm thinking, I have a doubt now... If I want use a Switch with the data received by serial port I can use this data directly? For example,   Arduino will receive by serial port "1" or "0" and will select one case. The following code is correct?

DataReceivedMODE= Serial.read();
   
   Switch (DataReceivedMODE){
     
     case '1':
      AutomaticMode= 0;
      break;
     
     case default:
     AutomaticMode= 1;
     break;
 }
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 30, 2014, 03:22 am
If you only have those two possibilities like that then an if() is more appropriate

Code: [Select]
if (DataReceivedMODE == '1')
   AutomaticMode= 0;
else
   AutomaticMode= 1;


or even better (but more cryptic)

Code: [Select]
AutomaticMode = DataReceivedMODE == '1' ? 0 : 1

______
Rob
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 30, 2014, 12:05 pm
Thanks!! I am learning a lot. Other problem solved  :). But now I am trying receive correctly the datas from serial port. For example, If I need receive from serial port 0 the string "$ADQ,P00,CH0" I was reading that the function Serial.read() only returns the first byte available in the buffer. My string have 12 bytes (without count the null character). If I work with the variable [char DataReceivedUART0[13];]   and I do DataReceivedUART0=Serial.read();  I only will receive the first byte available in serial port? or willl I need use a bucle for if I need save 12bytes ("$ADQ,P00,CH0")? -->  

for(i=0; i<13; i++){
DataReceivedUART0=Serial.read();
}


When one byte is read with serial.read() in serial port this byte, later, is removed?

Thanks a lot!!!
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 30, 2014, 12:32 pm
Code: [Select]
for(i=0; i<13; i++){
DataReceivedUART0=Serial.read();
}


Notice anything missing? I bet that's not your actual code. That's why we insist on people using CODE TAGS. (the # button in the tool bar when editing your post)

I suspect your problem is simple but we need to see the code properly presented without missing parts.

______
Rob
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 30, 2014, 12:58 pm
This is the code. Sorry.  :) This code have errors that I don't know what is. (Errors  like  dd:36: error: ISO C++ forbids comparison between pointer and integer).

Code: [Select]
char DataReceivedMODE[2]={0};
char DataReceivedSERIAL0[13]={0};
char DataReceivedSERIAL1[18]={0};
int AutomaticMode=0;
int i=0;
boolean FlagUART= false;


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


void loop() {
 
 UART0();
 AnalyzeSensors();
 UART1();
 
}


void UART0(){  //This function receve the datas from my laptop (Mode and Resquest sensor's infromation)

while(Serial.available()){

if(FlagUART==false){
 
 FlagUART=true;
 
 
    if(DataReceivedMODE == '1'){
     
      AutomaticMode= 1;
     
      }
     
     else{
       
       AutomaticMode= 0;
     
      }
 
 }

else if (FlagUART=true||AutomaticMode==1){
 
 FlagUART=false;
 
 for (i=0;i<13;i++){
 
 DataReceivedSERIAL0[i]=Serial.read();
  }
}

else{

 FlagUART=false;

}

 }

 

}



void AnalyzeSensors(){
 
  if (AutomaticMode==1){
     
    Serial1.print("$ADQ,P00,CH0");
    delay(1);
    Serial1.print("$ADQ,P01,CH0");
    delay(1);
    Serial1.print("$ADQ,P02,CH0");
    delay(1);
    Serial1.print("$ADQ,P03,CH0");
    delay(1);
    Serial1.print("$ADQ,P04,CH0");
    delay(1);
    Serial1.print("$ADQ,P05,CH0");
    delay(1);
    Serial1.print("$ADQ,P06,CH0");
    delay(1);
    Serial1.print("$ADQ,P07,CH0");
    delay(1);
    Serial1.print("$ADQ,P08,CH0");
    delay(1);
    Serial1.print("$ADQ,P09,CH0");
    delay(1);
    Serial1.print("$ADQ,P10,CH0");
    delay(1);
   
  }
   
   else{
   
   
   Serial1.print(DataReceivedSERIAL0);
   delay(1);
   
    }



}


void UART1() { //This function receive the datas from microcontrollers

while(Serial1.available()){

for(i=0;i<18;i++){  
 
DataReceivedSERIAL1=Serial1.read();

}

Serial.print(DataReceivedSERIAL1);
 
}

 
}
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 30, 2014, 01:14 pm
Code: [Select]
if(DataReceivedMODE == '1')

You are comparing an array with a char

Code: [Select]
if(DataReceivedMODE[0] == '1')

Will compile, as to the logic of the program I'll look at that.

______
Rob
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 30, 2014, 01:18 pm
OK yes. Now it will compile! Thankss. But I have a question is possible simplify when I send by serial port the strings "$ADQ,P00,CH0", "$ADQ,P01,CH0" etc? And I don't know if I do correctly the assignation of  the received datas from serial port.


Code: [Select]
char DataReceivedMODE[2]={0};
char DataReceivedSERIAL0[13]={0};
char DataReceivedSERIAL1[18]={0};
int AutomaticMode=0;
int i=0;
boolean FlagUART= false;


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


void loop() {
 
 UART0();
 AnalyzeSensors();
 UART1();
 
}


void UART0(){  //This function receve the datas from my laptop (Mode and Resquest sensor's infromation)

while(Serial.available()){

if(FlagUART==false){
 
 FlagUART=true;
 
 
    if(DataReceivedMODE[0] == '1'){
     
      AutomaticMode= 1;
     
      }
     
     else{
       
       AutomaticMode= 0;
     
      }
 
 }

else if (FlagUART=true||AutomaticMode==1){
 
 FlagUART=false;
 
 for (i=0;i<13;i++){
 
 DataReceivedSERIAL0[i]=Serial.read();
  }
}

else{

 FlagUART=false;

}

 }

 

}



void AnalyzeSensors(){
 
  if (AutomaticMode==1){
     
    Serial1.print("$ADQ,P00,CH0");
    delay(1);
    Serial1.print("$ADQ,P01,CH0");
    delay(1);
    Serial1.print("$ADQ,P02,CH0");
    delay(1);
    Serial1.print("$ADQ,P03,CH0");
    delay(1);
    Serial1.print("$ADQ,P04,CH0");
    delay(1);
    Serial1.print("$ADQ,P05,CH0");
    delay(1);
    Serial1.print("$ADQ,P06,CH0");
    delay(1);
    Serial1.print("$ADQ,P07,CH0");
    delay(1);
    Serial1.print("$ADQ,P08,CH0");
    delay(1);
    Serial1.print("$ADQ,P09,CH0");
    delay(1);
    Serial1.print("$ADQ,P10,CH0");
    delay(1);
   
  }
   
   else{
   
   
   Serial1.print(DataReceivedSERIAL0);
   delay(1);
   
    }



}


void UART1() { //This function receive the datas from microcontrollers

while(Serial1.available()){

for(i=0;i<18;i++){  
 
DataReceivedSERIAL1[i]=Serial1.read();

}

Serial.print(DataReceivedSERIAL1);
 
}
 
 
}
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 30, 2014, 01:28 pm
Another problem

Code: [Select]
while(Serial1.available()) {
for(i=0;i<18;i++){  
DataReceivedSERIAL1[i]=Serial1.read();
}


Let's assume there was a single byte available so this code it executed. What makes you think there are 18 bytes? and anyway aren't there just 12 bytes in the received string?

Code: [Select]
if (Serial1.available() >= 12) {
for(int i=0; i<12; i++){  
DataReceivedSERIAL1[i]=Serial1.read();
}


Same in UART0().

Sorry, I still haven't thought about the logic of the program as I keep finding errors like these.

______
Rob
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 30, 2014, 01:37 pm
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
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 30, 2014, 02:06 pm
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?  :~
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 30, 2014, 02:11 pm
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
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 30, 2014, 02:13 pm
Quote
The laptop send me  by the same serial port differents strings.
But don't you only handle one at a time?

______
Rob
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 30, 2014, 02:16 pm
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).
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 30, 2014, 02:18 pm

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 .
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 30, 2014, 02:20 pm
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
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 30, 2014, 02:21 pm

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
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 30, 2014, 02:22 pm
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

Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 30, 2014, 02:27 pm

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.
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 30, 2014, 02:28 pm
That's OK, so can you try my example code? Or don't you have the sensors working yet?

______
Rob
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 30, 2014, 02:37 pm
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 :)
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 30, 2014, 02:40 pm
I don't have now the sensors working sorry.
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: graynomad on Mar 30, 2014, 03:08 pm
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
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 30, 2014, 03:26 pm
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)

Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Mar 30, 2014, 04:22 pm
I will work more with this code and when I have the new version I will post it.  Thanks for your help Graynomad.
Title: Re: Comunicating ADC+ Arduino DUE with the protocol 1-wire
Post by: Due88 on Apr 10, 2014, 05:32 pm
Hi again! I have been very busy but now I am improving my arduino code. I have very trouble because the specifications on internet says that Arduino Due has 103 I/0 interrupts.   All pins in this board can be able like interruptions?
For example, if I need use a serial interrupt (Port0-->RX0) must I define this function? --> attachInterrupt(0, Serial0Reception, mode)  where mode (that can be 0, 1, 2 or 3)  in this case is irrelevant?  (Serial0Reception is the name of my serial interrupt).
The first "0" is the Ardino's Pin 0 (Rx0)?
If I need specify other interrupt (for example, Pin RX1 or the interrupt of the pin 51) I need specify in this function the number of this pin?

Thanks  :) :)