Created
March 17, 2018 08:57
-
-
Save yoggy/c0e1bb116124039cf04cd817b89ae6c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// mh-z14-calibration-test.pde | |
// | |
// see also... https://www.openhacks.com/uploadsproductos/mh-z14_co2.pdf | |
// | |
import processing.serial.*; | |
byte [] buf = new byte[9]; | |
Serial s = new Serial(this, "COM9", 9600); | |
// calibrate zero point | |
s.write(0xff); // header | |
s.write(0x01); // sensor no | |
s.write(0x87); // command | |
s.write(0x00); | |
s.write(0x00); | |
s.write(0x00); | |
s.write(0x00); | |
s.write(0x00); | |
s.write(0x78); // check value | |
delay(500); | |
// read return value (9byte) | |
print("read value : "); | |
for (int i = 0; i < 9; ++i) { | |
buf[i] = (byte)s.read(); | |
print(hex(buf[i])); | |
print(", "); | |
} | |
println(); | |
// read gas soncentration | |
s.write(0xff); // header | |
s.write(0x01); // sensor no | |
s.write(0x86); // command | |
s.write(0x00); | |
s.write(0x00); | |
s.write(0x00); | |
s.write(0x00); | |
s.write(0x00); | |
s.write(0x79); // check value | |
delay(500); | |
// read return value (9byte) | |
print("read value : "); | |
for (int i = 0; i < 9; ++i) { | |
buf[i] = (byte)s.read(); | |
print(hex(buf[i])); | |
print(", "); | |
} | |
println(); | |
int val = Byte.toUnsignedInt(buf[2]) * 256 + Byte.toUnsignedInt(buf[3]); | |
println("co2=" + val); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment