def test_timeout(): sys.modules['smbus'] = mock.Mock() sys.modules['smbus'].SMBus = MockSMBus import ads1015 device = ads1015.ADS1015() with pytest.raises(ads1015.ADS1015TimeoutError): device.wait_for_conversion(timeout=0.01)
def setup(): global adc, _is_setup if _is_setup: return _is_setup = True adc = ads1015.ADS1015(i2c_addr=0x49) adc.set_mode('single') adc.set_programmable_gain(MICS6814_GAIN) adc.set_sample_rate(1600) GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(MICS6814_HEATER_PIN, GPIO.OUT) GPIO.output(MICS6814_HEATER_PIN, 1) atexit.register(cleanup)
found = i2c.scan() for i in range(32, 40): if i in found: print('Found MCP23017 at I2C address {} {}'.format(i, hex(i))) mcp_address = i break for i in range(72, 74): if i in found: print('Found ADS1015 at I2C address {} {}'.format(i, hex(i))) ads_address = i break del found # adc import ads1015 ads = ads1015.ADS1015(i2c, ads_address, gain=1) # mcp23017 import mcp23017 mcp = mcp23017.MCP23017(i2c, mcp_address) # sd card import uos as os from machine import SDCard sd = SDCard(slot=2) sd_cd = Pin(33, Pin.IN) # if sd card detect pin is LOW, a card is inserted if sd_cd.value() == 0: try: print('Found SD card {}'.format(sd.info()))
def test_convert(): sys.modules['smbus'] = mock.Mock() sys.modules['smbus'].SMBus = MySMBus import ads1015 device = ads1015.ADS1015() device.wait_for_conversion(timeout=0.01)
def test_setup_invalid_i2c_address(): sys.modules['smbus'] = mock.Mock() import ads1015 with pytest.raises(ValueError): device = ads1015.ADS1015(i2c_addr=0xfff) del device
def test_setup(): sys.modules['smbus'] = mock.Mock() import ads1015 device = ads1015.ADS1015() del device
import RPi.GPIO as GPIO import ads1015 from time import sleep, time, localtime,strftime,perf_counter from BME280_new import BME280_new from pms5003 import PMS5003, ReadTimeoutError try: from smbus2 import SMBus except ImportError: from smbus import SMBus MICS6814_HEATER_PIN = 24 ads1015.I2C_ADDRESS_DEFAULT = ads1015.I2C_ADDRESS_ALTERNATE adc = ads1015.ADS1015(i2c_addr=0x49) adc.set_mode('single') adc.set_programmable_gain(4.096) adc.set_sample_rate(128) bus = SMBus(1) bme280 = BME280_new(i2c_dev=bus) bme280.setup(mode='forced', temperature_oversampling=1, pressure_oversampling=1, humidity_oversampling=1) GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(MICS6814_HEATER_PIN, GPIO.OUT)