1. 참조
    1. PMS7003 활용 예 : http://blog.naver.com/elepartsblog/221347040698
  2. 필요 장비
    1. PMS7003 먼지 센서
    2. 먼지센서 인터페이스 보드
    3. USB  to UART 변환 케이블
  3. 시리얼 통신을 위한 설정 : 참조
  4. 데이터 시트 : http://eleparts.co.kr/data/_gextends/good-pdf/201803/good-pdf-4208690-1.pdf
  5. 출력 모드 2가지 존재
    1. Active Mode : 기본 설정, 자동으로 측정값 전송, 예제 프로그램은 Activie Mode용
      1. stable mode : 2.3s 간격
      2. fast mode : 200~800ms 간격
    2. Passive Mode : 요청이 있을 때만 측정값 전송, 재작동시 30초 이후에 값 측정해야 정확
  6. 샘플코드 : https://github.com/eleparts/PMS7003
  7. PMS7003 센서에서 전송되는 값
    1. 32바이트로 구성된 18개의 값
      1. 1바이트 : 0x42
      2. 1바이트 : 0x4d
      3. 2바이트 : 28
      4. 2바이트 : PM1.0 concentration unit μ g/m3(CF=1,standard particle)
      5. 2바이트 : PM2.5 concentration unit μ g/m3(CF=1,standard particle)
      6. 2바이트 : PM10 concentration unit μ g/m3(CF=1,standard particle)
      7. 2바이트 : PM1.0 concentration unit μ g/m3(under atmospheric environment)
      8. 2바이트 : PM2.5 concentration unit μ g/m3(under atmospheric environment)
      9. 2바이트 : PM10 concentration unit μ g/m3 (under atmospheric environment)
      10. 2바이트 : indicates the number of particles with diameter beyond 0.3 um in 0.1 L of air.
      11. 2바이트 : indicates the number of particles with diameter beyond 0.5 um in 0.1 L of air.
      12. 2바이트 : indicates the number of particles with diameter beyond 1.0 um in 0.1 L of air.
      13. 2바이트 : indicates the number of particles with diameter beyond 2.5 um in 0.1 L of air.
      14. 2바이트 : indicates the number of particles with diameter beyond 5.0 um in 0.1 L of air.
      15. 2바이트 : indicates the number of particles with diameter beyond 10 um in 0.1 L of air.
      16. 1바이트 : Data13 Reserved high 8 bits
      17. 1바이트 : Data13 Reserved low 8 bits
      18. 2바이트 : Checksum code
  8. struct 모듈 : C의 union과 유사하게 bytes를 struct로 또는 그 반대로 상호 변환해 줌
    1. 참조 : https://m.blog.naver.com/s2kiess/220243476924
    2. struct.unpack(format, buffer) : byte로 구성된 buffer의 내용을 format 형태로 변환한 후 파이썬의 투플(tuple)로 표현됨
    3. chksum_data = struct.unpack(‘!30BH’, buffer)
      1. bytes로 구성된 buffer를 30개의 B와 1개의 H로 변환
      2. !  : 정렬 제어문자 중 하나로  네트워크 바이트 순서(빅 엔디안)로 전송
        1. 리틀 엔디안 : 역순으로 저장되고 역순으로 읽어옴
        2. 빅 엔디안 : 순서대로 저장하고 순서대로 읽어옴
      3. B : unsigned char(1byte) -> 1바이트 정수
      4. H : unsigned short(2bytes) -> 2바이트 정수
      5. chksum_data = (B, B, B, … , B, H)
    4. data = struct.unpack(‘!2B13H2BH’, buffer)
      1. bytes로 구성된 buffer를 2개의 B와 13개의 H, 2개의 B, 1개의 H로 변환
      2. data = (B, B, H, H, …, H, B, B, H)
    5. struct.pack(format, v1, v2, …) : 여려개의 변수의 값들을  byte형태로 변환
    6. struct.pack(‘hhl’, 1, 2, 3)                 =>  b’\x00\x01\x00\x02\x00\x00\x00\x03′
    7. struct.pack(‘ci’, b’*’, 0x12131415)  => b’*\x00\x00\x00\x12\x13\x14\x15
      1. 4바이트 단위로 저장되기 위해 문자(*) 뒤에 3바이트를 비운 듯 ?
    8. struct.pack(‘ic’, 0x12131415, b’*’)  => b’\x12\x13\x14\x15*
    9. struct.calcsize(‘ci’)                  => 8
    10. struct.calcsize(‘ic’)                  => 5
    11. pack(‘llh0l’, 1, 2, 3)   => b’\x00\x00\x00\x01\x00\x00\x00\x02\x00\x03\x00\x00
error: Content is protected !!