วันอังคารที่ 30 มิถุนายน พ.ศ. 2558

วันที่31 ที่Fibo

-สามารถส่งserial ไปcalibrateได้เรียบร้อยพร้อมทั่งส่งPWMได้
   การส่งserialไปควบคุมมีดั่งนี้
   -M...EF จะสามมารถควบคุม PWM
   -Pcal,...,...EF ส่งไปcalibrate ค่าPH
        -cal,low,4
        -cal,mid,7
        -cal,high,10
   -E..cal,...,...EF ส่งไปcalibrate ค่าEC
         -cal,low,12000
         -cal,high,80000
-แต่มันจะมีปัญหาคือ จะติดตัวE มาทุกครั้งทำให้error แต่บ้างครั้งก็ได้เมื่อกด reset ใหม่อาจยังคงไม่ได้100%แต่การทำงานทำงานได้เต็มรูปแบบ
-ส่วนผลการทดลองนั้นยังไม่ได้ทำเป็นคริปวีดีโอส่วนการทดลองรอดูในวันพรุ่งนี้
-ส่วนของโค้ดโปรแกรม

String inputstring = "";                                                       //a string to hold incoming data from the PC
int inputstringLength=0;
boolean input_stringcomplete = false;                                          //have we received all the data from the PC

String sensorstringPH = "";                                                      //a string to hold the data from the Atlas Scientific product
boolean sensor_stringcompletePH = false;                                         //have we received all the data from the Atlas Scientific product

String sensorstringEC = "";                                                      //a string to hold the data from the Atlas Scientific product
boolean sensor_stringcompleteEC = false;                                         //have we received all the data from the Atlas Scientific product

String latter =""; 

float time1 = 0.0;
float time2 = 0.0;
float s=0.0;
float counter = 0.0;
float j = 0.0;
float k=0.0;
float rpm=0.0;
float rpm_set = 0.0;
float err = 0;
float sum_err = 0;
float old_err = 0;
float Kp = 1;           //ค่าคงที่ kp
float Ki = 0.5;         //ค่าคงที่ki
float Kd = 1;           //ค่าคงที่kd
float u = 0;
float pwm_set = 0;

unsigned long Cur_time=0;
unsigned long Prev_time=0;

int latter1 = 1;                                                                //set pwm out 0-50 
int pwm = 9;                                                                    // PWM connected to digital pin 9
int inputstring1 = 0;

  void setup()
  {                                                                             //set up the hardware
     Serial.begin(38400);                                                       //set baud rate for the hardware serial port_0 to 38400
     Serial2.begin(38400);                                                      //set baud rate for software serial port_2 to 38400
     Serial3.begin(38400);                                                      //set baud rate for software serial port_3 to 38400
     
     inputstring.reserve(5);                                                    //set aside some bytes for receiving data from the PC
     sensorstringPH.reserve(30);                                                 //set aside some bytes for receiving data from Atlas Scientific product                                              
     sensorstringEC.reserve(30);                                                 //set aside some bytes for receiving data from Atlas Scientific product
     
     attachInterrupt(0,Millis,RISING);
      //LOW to trigger the interrupt whenever the pin is low,
      //CHANGE to trigger the interrupt whenever the pin changes value
      //RISING to trigger when the pin goes from low to high,
      //FALLING for when the pin goes from high to low.
      pinMode(pwm,OUTPUT);                                                          //PWM
      digitalWrite(7,HIGH);
      digitalWrite(8,LOW);
  }
 
 
 
   void serialEvent() 
   {                                                                              //if the hardware serial port_0 receives a char              
    char inchar = (char)Serial.read();                               //get the char we just received
    inputstring += inchar;                                           //add it to the inputString
    if(inchar == '\r') {input_stringcomplete = true;}                //if the incoming character is a <CR>, set the flag
   }  


  void serialEvent2()
  {                                                                              //if the hardware serial port_2 receives a char 
    char incharEC = (char)Serial2.read();                              //get the char we just received
    sensorstringEC += incharEC;                                        //add it to the inputString
    if(incharEC == '\r') {sensor_stringcompleteEC = true;}               //if the incoming character is a <CR>, set the flag 
  }
  
  void serialEvent3()
  {                                                                              //if the hardware serial port_3 receives a char 
   char incharPH = (char)Serial3.read();                              //get the char we just received
   sensorstringPH += incharPH;                                        //add it to the inputString
   if(incharPH == '\r') {sensor_stringcompletePH = true;}               //if the incoming character is a <CR>, set the flag 
  }

  void Millis()
  {
  counter++;
  }


 void loop()
 {  
  if(Serial.available()>0)
  {
    while(Serial.available()>0)
    {
      
      inputstring += char(Serial.read());
      inputstringLength += 1;
      delay(1);
    }
  }
  for(int i=1;i<=inputstringLength;i++)
   {     
    if((inputstring[i]=='F')&&(inputstring[i-1]=='E'))
    {  
      Serial.println(inputstring);
      if(inputstring[0]=='M')
      {
        String temp="";
        temp.reserve(30);   
        for(int i=1;i<(inputstringLength-2);i++)
        {
          temp += inputstring[i];
        }
        Serial.println(temp);
        
  inputstring1=temp.toInt();
  if(inputstring1 <=50 )                                                    //send to serial over 50
  {
   Cur_time = millis();                                                   //set Cur_time is millis
   s = Cur_time-Prev_time;
   if(s >= 10)
      {
        j = (counter*10.0)/360.0;
        k = j/(s*0.001);
        rpm = k*60.0;    //rpm
        Serial.print(rpm);
        err = inputstring1 - rpm/100;
        sum_err += err;
        u = Kp*err + Ki*sum_err + Kd*(err-old_err);
        old_err = err;
        pwm_set = u*1.2;             
        analogWrite(pwm,pwm_set);
         
        pwm_set+=0;    
        counter=0;
        Prev_time = Cur_time;
        pwm_set=0;   
      }
   }
     }
      
      if(inputstring[0]=='P')
      {
         String temp="";
        temp.reserve(30);   
        for(int i=1;i<(inputstringLength-2);i++)
        {
          temp += inputstring[i];
        }
        Serial.println(temp);
        input_stringcomplete=temp;
      if (input_stringcomplete)
      {                                                                          //if a string from the PC has been received in its entirety 
        Serial3.print(inputstring);                                              //send that string to the Atlas Scientific product
        inputstring = "";                                                        //clear the string:
        input_stringcomplete = false;                                            //reset the flag used to tell if we have received a completed string from the PC
      }
      if (input_stringcomplete)
      {                                                                          //if a string from the PC has been received in its entirety 
        Serial2.print(inputstring);                                              //send that string to the Atlas Scientific product
        Serial3.print(inputstring);                                              //send that string to the Atlas Scientific product
        inputstring = "";                                                        //clear the string:
        input_stringcomplete = false;                                            //reset the flag used to tell if we have received a completed string from the PC
      }
      }
      
      if(inputstring[0]=='E')
      {
         String temp="";
        temp.reserve(30);   
        for(int i=1;i<(inputstringLength-2);i++)
        {
          temp += inputstring[i];
        }
        Serial.println(temp);
        
      input_stringcomplete=temp;
      if (input_stringcomplete)
      {                                                                          //if a string from the PC has been received in its entirety 
        Serial2.print(inputstring);                                              //send that string to the Atlas Scientific product
        inputstring = "";                                                        //clear the string:
        input_stringcomplete = false;                                            //reset the flag used to tell if we have received a completed string from the PC
      }  
     if (sensor_stringcompleteEC)
      {                                                                         //if a string from the Atlas Scientific product has been received in its entierty 
        Serial.print( "EC:");
        Serial.print(sensorstringEC);                                            //send that string to to the PC's serial monitor
        sensorstringEC = "";                                                       //clear the string:
        Serial.println("\t");  
        sensor_stringcompleteEC = false;                                           //reset the flag used to tell if we have received a completed string from the Atlas Scientific product   
      }
      }
      inputstringLength=0;
      inputstring="";
    }
   } 

   
    if (sensor_stringcompletePH)
      {                                                                         //if a string from the Atlas Scientific product has been received in its entierty 
        Serial.print( "PH:");
        Serial.print(sensorstringPH);                                            //send that string to to the PC's serial monitor
        sensorstringPH = "";                                                       //clear the string:
        Serial.print("\t");  
        sensor_stringcompletePH = false;                                           //reset the flag used to tell if we have received a completed string from the Atlas Scientific product  
      } 

    if (sensor_stringcompleteEC)
      {                                                                         //if a string from the Atlas Scientific product has been received in its entierty 
        Serial.print( "EC:");
        Serial.print(sensorstringEC);                                            //send that string to to the PC's serial monitor
        sensorstringEC = "";                                                       //clear the string:
        Serial.println("\t");  
        sensor_stringcompleteEC = false;                                           //reset the flag used to tell if we have received a completed string from the Atlas Scientific product   
      }  
 }


PIC18F4550 Ultrasonic Sensor สายแพร ขาย่ำ

-ไปบ้านหม้อได้ของดั้งรูป แต่ของที่จะไปหาให้พี่ไนท์ไม่มีเจอแต่ sensor วัดอุณหภูมิ Temperature control for 3d printer 

Temperature control for 3d printer 

-และได้ไปดูหลายๆร้านโดยเทียบราคาของที่ซื้อมาแล้วบ้างร้านราคาก็สูงผิดปกติ แต่บ้างร้านก็ราคาปกติตามเว็ป


ไม่มีความคิดเห็น:

แสดงความคิดเห็น