Created
January 20, 2020 06:52
-
-
Save neosarchizo/ed5fc7ff4a6d80da48e578259dbf272b to your computer and use it in GitHub Desktop.
[PM2008] 보정
This file contains 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
#include <Wire.h> | |
#define PM2008_I2C_ADDRESS 0x28 | |
// Control modes | |
#define PM2008_I2C_CTRL_CLOSE_MEASUREMENT 0x1 | |
#define PM2008_I2C_CTRL_OPEN_SINGLE_MEASUREMENT 0x2 | |
#define PM2008_I2C_CTRL_SET_UP_CONTINUOUSLY_MEASUREMENT 0x3 | |
#define PM2008_I2C_CTRL_SET_UP_TIMING_MEASUREMENT 0x4 | |
#define PM2008_I2C_CTRL_SET_UP_DYNAMIC_MEASUREMENT 0x5 | |
#define PM2008_I2C_CTRL_SET_UP_CALIBRATION_COEFFICIENT 0x6 | |
#define PM2008_I2C_CTRL_SET_UP_WARM_MODE 0x7 | |
#define PM2008_I2C_CONTROL_MODE PM2008_I2C_CTRL_SET_UP_CALIBRATION_COEFFICIENT | |
#define PM2008_I2C_FRAME_HEADER 0x16 | |
void setup() { | |
Wire.begin(); | |
uint8_t buffer[7]; | |
buffer[0] = PM2008_I2C_FRAME_HEADER; | |
buffer[1] = 0x7; // frame length | |
buffer[2] = PM2008_I2C_CONTROL_MODE; | |
uint16_t data = 70; // 70 ~ 150 | |
buffer[3] = data >> 8; | |
buffer[4] = data & 0xFF; | |
buffer[5] = 0; // Reserved | |
// Calculate checksum | |
buffer[6] = buffer[0]; | |
for (uint8_t i = 1; i < 6; i++) { | |
buffer[6] ^= buffer[i]; | |
} | |
Wire.beginTransmission(PM2008_I2C_ADDRESS); | |
Wire.write(buffer, 7); | |
Wire.endTransmission(); | |
} | |
void loop() {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment