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);**
}