[[FrontPage]]
 objectPage http://www.yama-lab.org/fwb4pi/index.php?Sensors3 or http://www.yama-lab.org/fwb4pi/index.php?Sensors3
 device yamaRasPiDp9_1 or yamaRasPiDp9_2 start after no write for 10 min.
 command: set readInterval=30000
 command: set execInterval=0
 command: program Sensors
 program: '
 program: ' init i2c
 program: ex("pi4j", "i2c use 1")
 program: '
 program: ' init lux sensor 
 program: ex("pi4j", "i2c write1 0x29,0x80,0x03") 'power up the tsl2561 lux sensor
 program: ex("pi4j", "i2c write1 0x29,0x81,0x00")
 program: ex("pi4j", "i2c write1 0x29,0x86,0x00") 'scale
 program: ex("pi4j", "i2c write1 0x29,0x80,0x00") 'power down
 program: ex("pi4j", "i2c write1 0x29,0x80,0x03") ' power up again
 program: delay(50)
 program: '
 program: 'get the lux value
 program: v1=ex("pi4j", "i2c read1 0x29,0x8c")
 program: v2=ex("pi4j", "i2c read1 0x29,0x8d")
 program: lux=s2i(v2)*256+s2i(v1)
 program: '
 program: 'get the Aanalog value from the ADS1115 ch0
 #  // Start with default values
 #  uint16_t config = ADS1015_REG_CONFIG_CQUE_NONE    | // Disable the comparator (default val)
 #                    ADS1015_REG_CONFIG_CLAT_NONLAT  | // Non-latching (default val)
 #                    ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low   (default val)
 #                    ADS1015_REG_CONFIG_CMODE_TRAD   | // Traditional comparator (default val)
 #                    ADS1015_REG_CONFIG_DR_1600SPS   | // 1600 samples per second (default)
 #                    ADS1015_REG_CONFIG_MODE_SINGLE;   // Single-shot mode (default)
 #
 program: config=0x0003|0x0000|0x0000|0x0000|0x0080|0x0100
 #
 #  // Set PGA/voltage range
 #  config |= m_gain;
 program: config=config|0x0000
 #
 #  // Set single-ended input channel
 #  switch (channel)
 #  {
 #    case (0):
 #      config |= ADS1015_REG_CONFIG_MUX_SINGLE_0; //SINGLE_1, SINGLE_2, SINGLE_3
 #      break;
 #program: config=config|0x4000
 program: config= config|0x5000
 #
 #  // Set 'start single-conversion' bit
 #  config |= ADS1015_REG_CONFIG_OS_SINGLE;
 program: config=config|0x8000
 #
 #  writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);
 #
 program: ex("pi4j", "i2c write2 0x49,0x01,"+config)
 #
 #  // Wait for the conversion to complete
 #  delay(m_conversionDelay);
 #
 program: delay(10)
 #
 #  // Read the conversion results
 #  // Shift 12-bit results right 4 bits for the ADS1015
 #  return readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;  
 #
 program: v2=ex("pi4j","i2c read2 0x49,0x00")
 program: airpol=s2i(v2)
 program: airpol=(airpol+32768)/16
 #
 program: '
 program: ' get temperature
 program: v1=ex("pi4j", "i2c read1 0x48,0x00")
 program: tmp=s2i(v1)
 program: '
 program: ' get motion
 program: v1=ex("pi4j","get-a-0")
 program: motion=s2i(v1)
 program: '
 program: ex("pi4j", "i2c close")
 program: '
 program: date=ex("service","getCurrentDate.")
 program: ex("service","clear sendBuffer")
 program: ex("service","putSendBuffer device=light, Date="+date+", v="+lux)
 program: ex("service","putSendBuffer device=airPol, Date="+date+", v="+airpol)
 program: ex("service","putSendBuffer device=temp, Date="+date+", v="+tmp)
 program: ex("service","putSendBuffer device=motion, Date="+date+", v="+motion)
 program: ex("service","sendResults.")
 command: end Sensors
 command: run Sensors
 result:
 device=light, Date=2018/9/16/ 11:23:45, v=13
 device=airPol, Date=2018/9/16/ 11:23:45, v=2011
 device=temp, Date=2018/9/16/ 11:23:45, v=29
 device=motion, Date=2018/9/16/ 11:23:45, v=15
 currentDevice="yamaRasPiDp9_1",Date=2018/9/16/ 11:23:45

 device=light, Date=2018/9/16/ 11:24:15, v=14
 device=airPol, Date=2018/9/16/ 11:24:15, v=2011
 device=temp, Date=2018/9/16/ 11:24:15, v=29
 device=motion, Date=2018/9/16/ 11:24:15, v=15
 currentDevice="yamaRasPiDp9_1",Date=2018/9/16/ 11:24:15


トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS