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=15000
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
#
#/**************************************************************************/
#/*!
# @brief Gets a single-ended ADC reading from the specified channel
#*/
#/**************************************************************************/
#uint16_t Adafruit_ADS1015::readADC_SingleEnded(uint8_t channel) {
# ...
#
# // Write config register to the ADC
# writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);
#
# // Wait for the conversion to complete
# delay(m_conversionDelay);
#
# // Read the conversion results
# // Shift 12-bit results right 4 bits for the ADS1015
# return readRegister(m_i2cAddress, ADS1015_REG_POINTER_CONVERT) >> m_bitShift;
#}
#
# // 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;
# break;
program: config=config|0x4000
#
# // Set 'start single-conversion' bit
# config |= ADS1015_REG_CONFIG_OS_SINGLE;
program: config=config|0x8000
#
# writeRegister(m_i2cAddress, ADS1015_REG_POINTER_CONFIG, config);
#
#static void writeRegister(uint8_t i2cAddress, uint8_t reg, uint16_t value) {
# Wire.beginTransmission(i2cAddress);
# i2cwrite((uint8_t)reg);
# i2cwrite((uint8_t)(value>>8));
# i2cwrite((uint8_t)(value & 0xFF));
# Wire.endTransmission();
#}
program: ex("pi4j", "i2c write2 0x49,0x01,"+config)
#
# // Wait for the conversion to complete
# delay(m_conversionDelay);
#
program: delay(8)
#
# // 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: '
program: ' get temperature
program: v1=ex("pi4j", "i2c read1 0x48,0x00")
program: tmp=s2i(v1)
#program: '
#program: 'get the Mag value, LSM303DLHC
#program: ex("pi4j","i2c write1 0x1e 0x00 0x08")
#program: ex("pi4j","i2c write1 0x1e 0x01 0x20")'gain setting,+-1.3
#program: ex("pi4j","i2c write1 0x1e 0x02 0x00")
#program: delay(50)
#program: 'sth=ex("pi4j","i2c read1 0x1e 0x32")
#program: 'stl=ex("pi4j","i2c read1 0x1e 0x31")
#program: smxh=ex("pi4j", "i2c read1 0x1e,0x03")
#program: smxl=ex("pi4j", "i2c read1 0x1e,0x04")
#program: smzh=ex("pi4j", "i2c read1 0x1e,0x05")
#program: smzl=ex("pi4j", "i2c read1 0x1e,0x06")
#program: smyh=ex("pi4j", "i2c read1 0x1e,0x07")
#program: smyl=ex("pi4j", "i2c read1 0x1e,0x08")
#program: mxh=s2i(smxh) : mxl=s2i(smxl)
#program: if mxh>127 then mx=(mxh-255)*256+(mxl-256) else mx=mxh*256+mxl
#program: myh=s2i(smyh) : myl=s2i(smyl)
#program: if myh>127 then my=(myh-255)*256+(myl-256) else my=myh*256+myl
#program: mzh=s2i(smzh) : mzl=s2i(smzl)
#program: if mzh>127 then mz=(mzh-255)*256+(mzl-256) else mz=mzh*256+mzl
#program: 't2=s2i(sth)*2+s2i(stl)/256
#program: '
#program: 'get the acceleration value, LSM303DLHC
#program: ex("pi4j","i2c write1 0x18 0x20,0x27")
#program: delay(50)
#program: saxl=ex("pi4j", "i2c read1 0x18,0x28")
#program: saxh=ex("pi4j", "i2c read1 0x18,0x29")
#program: sayl=ex("pi4j", "i2c read1 0x18,0x2a")
#program: sayh=ex("pi4j", "i2c read1 0x18,0x2b")
#program: sazl=ex("pi4j", "i2c read1 0x18,0x2c")
#program: sazh=ex("pi4j", "i2c read1 0x18,0x2d")
#program: axh=s2i(saxh) : axl=s2i(saxl)
#program: if axh>127 then ax=(axh-255)*256+(axl-256) else ax=axh*256+axl
#program: ayh=s2i(sayh) : ayl=s2i(sayl)
#program: if ayh>127 then ay=(ayh-255)*256+(ayl-256) else ay=ayh*256+ayl
#program: azh=s2i(sazh) : azl=s2i(sazl)
#program: if azh>127 then az=(azh-255)*256+(azl-256) else az=azh*256+azl
#program: '
program: ex("pi4j", "i2c close.")
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=temp2, Date="+date+", v="+t2)
#program: ex("service","putSendBuffer device=mag-x, Date="+date+", v="+mx)
#program: ex("service","putSendBuffer device=mag-y, Date="+date+", v="+my)
#program: ex("service","putSendBuffer device=mag-z, Date="+date+", v="+mz)
#program: ex("service","putSendBuffer device=a-x, Date="+date+", v="+ax)
#program: ex("service","putSendBuffer device=a-y, Date="+date+", v="+ay)
#program: ex("service","putSendBuffer device=a-z, Date="+date+", v="+az)
program: ex("service","sendResults.")
command: end Sensors
command: run Sensors
result:
device=airPol, Date=2018/9/15/ 0:57:51, v=64959
device=temp, Date=2018/9/15/ 0:57:51, v=26
currentDevice="yamaRasPiDp9_1",Date=2018/9/15/ 0:57:51