def __init__(self):
     self.i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)  #i2c settings
     self.display = sh1106.SH1106_I2C(
         128, 64, self.i2c, Pin(16),
         0x3c)  #Load the driver and set it to "display"
     self.bme = BME280(i2c=self.i2c)  #sensor function
     self.pump = PWM(Pin(14), freq=0,
                     duty=0)  #create PWM objekt and configure pump forward
     #self.pump_reverse = PWM(Pin(12), freq=0, duty=0) #create PWM objekt and configure pump backwards
     #self.button = Pin(0, Pin.IN, Pin.PULL_UP) #initialize button
     self.adc = ADS1115(
         self.i2c, self.addr, self.gain
     )  #create analog-digtial converter object to read analog humidity sensor
     self.time_start = ticks_ms() / 1000  #Sekunden
     self.autosetinterval = ticks_ms() / 1000 + 25200  #counter
     self.time_current = 0
     self.time_start = 0
     self.reset = 0
     self.epoche = 0
     self.water_storage = 1.2
     #self.water_use = 0
     #self.water_status = True
     self.button = Pin(0, Pin.IN, Pin.PULL_UP)
     #self.button.irq(trigger=Pin.IRQ_FALLING, handler=self.handle_interrupt)
     self.soil_dry = 20000  #CSensor >20000 /Annahme Test offen
     self.soil_ok = 15000  #CSensor 15000 bis 10000 /Annahme Test offen
     self.soil_humid = 10000  #CSensor 250 - bis 10000 /Annahme Test offen
     self.soil_humidity = None
     self.activateAndClearDisplay()
Exemplo n.º 2
0
def read_soil_moisture_i2c(i2c):
    """The ADS1115 4-channel ADC converter is somewhere between 0x48-0x4B. Ours is
      on the default. We're assuming we're only hooking soil sensors to it."""
    addr = 72
    adc = ADS1115(i2c, addr, 0)
    ret = []
    for i in range(0, 3):
        val = adc.read(0, i)
        if val < 3130 or val > 3150:
            ret.append({
                "id": "adc_{}_{}".format(addr, i),
                "type": "soil moisture",
                "value": val
            })

    return ret
Exemplo n.º 3
0
    def __init__(self, address, channels, settings={}):
        global i2c
        if i2c is None:
            print("Initializing I2C")
            i2c_settings = settings["i2c"]
            i2c = machine.I2C(
                settings["i2c"].get("id", -1),
                scl=machine.Pin(i2c_settings["scl"]),
                sda=machine.Pin(i2c_settings["sda"]),
                freq=i2c_settings.get("freq", None),
                )

        # Voltage is max readable voltage (full-scale input voltage range: FSR).
        # Doesn't let you read above power supply voltage (VCC) of 3.3V or 5V.
        # So for maximum resolution, pick 1x for 5V and 2x for 3.3V and make sure
        # input voltages are less than 4.096V and 2.048V respectively

        # gain_index = 0 # 2/3x 6.144V
        # gain_index = 1 # 1x   4.096V
        gain_index = 2 # 2x   2.048V
        # gain_index = 3 # 4x   1.024V
        # gain_index = 4 # 8x   0.512V
        # gain_index = 5 # 16x  0.256V

        self.adc = ADS1115(i2c, address, gain_index)
        self.channels = channels

        # rate_index is an index into how many samples can be taken per second.
        # More samples per second means faster reads but noisier results.
        # self.rate_index = 0 # 8    samples per second
        # self.rate_index = 1 # 16   samples per second
        # self.rate_index = 2 # 32   samples per second
        # self.rate_index = 3 # 64   samples per second
        # self.rate_index = 4 # 128  samples per second
        # self.rate_index = 5 # 250  samples per second
        # self.rate_index = 6 # 475  samples per second
        self.rate_index = 7 # 860  samples per Second
Exemplo n.º 4
0
# M5Stack ESP32
# Mesure de température avec le capteur CTN PlugUino
# Ro = 10 kOhm reliée à la masse
# CAN 16 bits I2C AS1115

from machine import I2C, Pin, Onewire
from ads1x15 import ADS1115
from time import sleep_ms
from math import log
from m5stack import lcd, buttonA

i2c = I2C(freq=400000, sda=21, scl=22)
adc = ADS1115(i2c, 0x48, 0)  # Gain value - 0 : 6.144V # 2/3x

ow = Onewire(26)
ds = Onewire.ds18x20(ow, 0)

# Coefficients de Steinhart-Hart
A = 1.0832e-3
B = 2.1723e-4
C = 3.2770e-7

Nmax = 26860  # 5/6.144*32765 = 26664
Ro = 10e3


def mesure_resistance_up():
    return Ro * (Nmax / adc.read() - 1)


while not buttonA.wasPressed():
Exemplo n.º 5
0
from machine import I2C, Pin, DAC
from ads1x15 import ADS1115
import sys, time

if sys.platform == "esp8266":
    #    print("Running on ESP8266")
    pinScl = 5  #ESP8266 GPIO5 (D1
    pinSda = 4  #ESP8266 GPIO4 (D2)
else:
    #    print("Running on ESP32")
    pinScl = 22  # SCL on esp32
    pinSda = 21  # SDA ON ESP32

dac = DAC(Pin(26))
i2c = I2C(1, scl=Pin(pinScl), sda=Pin(pinSda))

file = open("linADS1115.dat", "w")
ads1115 = ADS1115(i2c)
for i in range(256):
    dac.write(i)
    value = ads1115.read(1)
    print("DAC value: {:d}, ADC value: {:d}".format(i, value))
    file.write("{:d}\n".format(value))
    time.sleep(0.1)
file.close()
Exemplo n.º 6
0
# Mesure de température à l'aide d'une CTN 10k
# dans un pont diviseur de tension Ro = 10 kOhm
# CAN 16 bits I2C AS1115 

from machine import I2C
from ads1x15 import ADS1115

import time
from math import log

from m5stack import lcd, buttonA



i2c = I2C(freq=400000,sda=21,scl=22)
adc = ADS1115(i2c,0x48,0)

# adc = ADS1115(i2c, address, gain)
# Gain value - 0 as default
# 0 : 6.144V # 2/3x
# 1 : 4.096V # 1x
# 2 : 2.048V # 2x
# 3 : 1.024V # 4x
# 4 : 0.512V # 8x
# 5 : 0.256V # 16x

lcd.font(lcd.FONT_DejaVu24)
lcd.clear()
lcd.text(lcd.CENTER, 0,'ADS1115 - CTN')
#lcd.text(lcd.CENTER,30,'I2C ADC 16 bits')
lcd.text(40,210,'Stop')
Exemplo n.º 7
0
# Pot qui pense - CREPP 2019
# GPL V3.0
# www.crepp.org - [email protected]

import machine
from ads1x15 import ADS1115

i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
can = ADS1115(i2c=i2c, address=72, gain=0)


def test():
    a0 = can.read(rate=0, channel1=0)
    print(a0)


def get_a0():
    try:
        a0 = can.read(rate=0, channel1=0)
        return a0
    except OSError:
        return -1


def get_a1():
    try:
        a1 = can.read(rate=0, channel1=1)
        return a1
    except OSError:
        return -1
Exemplo n.º 8
0
from machine import Pin, I2C
from ads1x15 import ADS1115

i2c = I2C(sda = Pin(21), scl = Pin(22))

ads = ADS1115(i2c, 72, 3)

size = 20

array = []
for _ in range(size):
    array.append(ads.read(0, 0))


while True:
    array.pop(0)
    array.append(ads.read(0, 0))

    print(sum(array)/size*1)
# Capteur Pluginguino pression manomètre 0-50 hPA / 0.5-4.5V

from machine import I2C
from ads1x15 import ADS1115
from time import sleep_ms

i2c = I2C(1)
adc = ADS1115(i2c, 0x48, 0)  # 0 : 6.144V # 2/3x
Vref = 6.100  # 6.144 V ajust to 6.10
Nmax = 32765  # 2^15 - 1

U = adc.read() * Vref / Nmax
P = 5000 / 4 * (U - 0.5)
print(U, P)
sleep_ms(1000)
Exemplo n.º 10
0
import time
import framebuf
import ili9341
from xglcd_font import XglcdFont

try:
    camera.init(0, format=camera.JPEG)
except OSError as e:
    print(e)

SCREEN_W = 320
SCREEN_H = 240

i2c = machine.I2C(0, scl=machine.Pin(0), sda=machine.Pin(2))
pca = PCA8574(i2c, addr=0x21)
adc = ADS1115(i2c, address=0x48)
text = 'Foo text'
spi = machine.SPI(1,
                  baudrate=80000000,
                  mosi=machine.Pin(13),
                  sck=machine.Pin(14))
display = ili9341.Display(spi,
                          cs=pca.pin(5),
                          dc=pca.pin(3),
                          rst=pca.pin(4),
                          width=SCREEN_W,
                          height=SCREEN_H,
                          rotation=270)
#display = ILI9341( spi, cs=pca.pin(5), dc=pca.pin(3), rst=pca.pin(4), w=SCREEN_W, h=SCREEN_H, r=1)
#display.set_font(tt14)
#display.erase()