I purchased an ozone sensor from Winsen for ozone measurement.
I'm using ESP32-PICO-KIT V4
On datasheet, to use the "Q&A mode", set up command
Send
Start Byte / Address / Demand / Communication Type / -- / -- / -- / -- / Checksum
0XFF 0X01 0x78 0x04 0x00 0x00 0x00 0x00 x83
Receive
Start Byte / Command / Return calibration / -- / -- / -- / -- / -- / Checksum
0XFF 0X78 (Success: 1 Failure: 0) 0x0 0x0 0x0 0x0 0x0 (0x87 0x88)
If use the serial communication terminal program, commands are transmitted, but It is not transferred when using Arduino IDE.
Is my code wrong?
#include<HardwareSerial.h>
HardwareSerial mySerial(2);
byte command[9] = {0xFF, 0x01, 0x78, 0x04, 0x00, 0x00, 0x00, 0x00, 0x83};
void setup() {
Serial.begin(115200);
mySerial.begin(9600, SERIAL_8N1, 15, 13);
}
void loop() {
byte readBuffer[9] = {};
mySerial.write(command, 9);
mySerial.readBytes(readBuffer, 9);
for (int i = 0; i < 8; i++) {
Serial.print(readBuffer[i], HEX); Serial.print(" ");
}
Serial.println(readBuffer[8], HEX);
delay(1000);
}
esp32UART.ino (499 Bytes)