| 
 | 
 
 本帖最後由 lucy522285 於 2020-8-31 11:36 編輯  
 
大家好  目前在進行乙烯空氣sensor 的通訊連接   使用的是arduino nano 進行通訊 
當中所使用的是UART 目前正以廠商方面提供的datasheet 進行程式編寫,也有參閱相關類似的資料 
以下為參閱網站寫法 
網址:https://wiki.dfrobot.com/Infrare ... 000ppm_SKU__SEN0220 
datasheet:在附件中(co2) 
基本上我以這種架構去編寫我的乙烯感測器,但通訊後只出現0跟1兩種的數字 不知道應該如何編寫 
以下為我的程式碼和乙烯(ze11-c2h4)的datasheet 
(ps 乙烯感測器的範圍為0-100ppm) 
 
#include <SoftwareSerial.h> 
SoftwareSerial mySerial(9, 10); // RX, TX 
unsigned char hexdata[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79}; //Read the gas density command  
void setup() { 
 
  Serial.begin(9600); 
  while (!Serial) { 
 
  } 
  mySerial.begin(9600); 
 
} 
 
void loop() { 
   mySerial.write(hexdata,9); 
   delay(500); 
 
 for(int i=0,j=0;i<9;i++) 
 { 
  if (mySerial.available()>0) 
  { 
     long hi,lo,C2H4; 
     int ch=mySerial.read(); 
 
    if(i==4){     hi=ch;   }   //High concentration 
    if(i==5){     lo=ch;   }   //Low concentration 
    if(i==8) { 
               C2H4=hi*256+lo;  //C2H4 concentration} 
      Serial.print("C2H4 concentration: "); 
      Serial.print(C2H4); 
      Serial.println("ppm"); 
             
} 
  } 
 
 } 
 
 } 
 
這是在datasheet 中 關於通訊寫法 
但實在不懂什麼意思 再請各位可以給個幫忙  謝謝大家 
 
 
 
 |   
 
 
 
 |