ESP32通过RS485使用土壤氮磷钾传感器


//TX 16
//RX 17
#include 
#include 
unsigned char item[8] = {0x01, 0x03, 0x00, 0x1E, 0x00, 0x03, 0x65, 0xCD};
void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);

  Serial2.begin(9600);
  while (!Serial)
    ; // wait for serial port to connect. Needed for Leonardo only
}

void loop()
{

  String data = "";
  char buff[128]; // 定义存储传感器数据的数组
  String info[11];
  for (int i = 0; i < 8; i++)
  {                         // 发送测温命令
    Serial2.write(item[i]); // write输出
  }
  delay(100); // 等待测温数据返回
  data = "";
  while (Serial2.available())
  {                                                   //从串口中读取数据
    unsigned char in = (unsigned char)Serial2.read(); // read读取
    // Serial.print(in, HEX);
    // Serial.print(',');
    data += in;
    data += ',';
  }
  if (data.length() > 0)
  { //先输出一下接收到的数据
    // S

你可能感兴趣的:(笔记,物联网)