Esempio n. 1
0
        # Send the string to the PIC for display.
        self.pi.i2c_write_i2c_block_data(self._h, 0, value)


if __name__ == "__main__":
    import time
    import pigpio
    import Si7021

    pi = pigpio.pi()

    if not pi.connected:
        exit(0)

    # Sensor initialization
    s = Si7021.sensor(pi)

    s.set_resolution(0)
    print("Sensor resolution set to {:x}".format(s.get_resolution()))

    print(
        "Sensor hardware revision={:x} with ID1={:08x} and ID2={:08x}".format(
            s.firmware_revision(), s.electronic_id_1(), s.electronic_id_2()))

    # LCD initialization
    led = PIC_LTC4627JR(pi)

    try:
        print("Press Control-C to exit program.")
        while True:
            celsius = s.temperature()
Esempio n. 2
0
def initialise():
    global dir_path,Ts1, Ms1, Ts2, Ms2, speedM, Ti, HuAir, \
            TAir, offset, facta, factb, maxspeed, minspeed,\
            Sm, db,cursor, interval, limitmin, limitmax, bus,\
            adc, adc2, GAIN, configfile, config, max31,\
            s, instrument, Tm, range_error

    
    #default values
    Ts1=0       #temperature sensor1
    Ms1=0       #moisture sensor1
    Ts2=0       #temperature sensor2
    Ms2=0       #moisture sensor2
    speedM=25   #speedmotor
    Ti=datetime.now()       #time
    Sm=15        #Set moisture
    HuAir=0     #Humidity air
    TAir=0      #temperature air
    interval=2
    limitmin = 17
    limitmax=13
    Tm=datetime.now() #time for emails
    range_error=False

    #Parameters:
    offset=0    #offset
    facta=0     #facteur of the formula a
    factb=0     #facteur of the formula b
    maxspeed=50
    minspeed=0

    #initialise db
    inidb()

    #intialise bus for temperature and humidity reading
    #bus = smbus2.SMBus(1)

    #intialise ADC
    adc = Adafruit_ADS1x15.ADS1115()
    adc = Adafruit_ADS1x15.ADS1115(address=0x4A, busnum=1)
    adc2 = Adafruit_ADS1x15.ADS1115()
    adc2 = Adafruit_ADS1x15.ADS1115(address=0x48, busnum=1)
    GAIN = 2/3
    
    #config file
    configfile="/var/www/html/configfolder/config.ini"
    config = configparser.ConfigParser()
    
    #Si7021:
    pi = pigpio.pi()
    s = Si7021.sensor(pi)  
    
    #minimalbus
    instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 1) # port name, slave address (in decimal)
    instrument.serial.port          # this is the serial port name
    instrument.serial.baudrate = 19200   # Baud
    instrument.serial.bytesize = 8
    instrument.serial.parity   = minimalmodbus.serial.PARITY_NONE
    instrument.serial.stopbits = 1
    instrument.serial.timeout  = 10   # seconds
    instrument.address=1     # this is the slave address number
    instrument.mode = minimalmodbus.MODE_RTU   # rtu or ascii mode
    #Set Registers
    instrument.write_register(8501, 0x0080, 0) #reset fault
    if record_only==True:
        print("Setting to Manual")
        instrument.write_register(8413, 0x0001, 0) #Manual set Fr1 to AI1
    elif record_only==False:
        print("Setting to Controlled")
        instrument.write_register(8413, 0x00A4, 0) #Automatic. set Fr1 to ModBus 
        instrument.write_register(8501, 0x0006, 0) # set it read to switch on
        instrument.write_register(8501, 0x0007, 0) # set it switch on
        instrument.write_register(8501, 0x000f, 0) # start
        instrument.write_register(8502, 0, 0) # put speed at 0Hz