import babel_out import time from machine import I2C #id, scl, sda, freq i2c = I2C(id=-1, scl=26, sda=27, freq=100000) # create I2C peripheral at frequency of 400kHz # depending on the port, extra parameters may be required # to select the peripheral and/or pins to use read_msb_addr = 0x73 >> 1 read_lsb_addr = 0x71 >> 1 write_addr = 0x70 >> 1 init_write = 0x06 i2c.writeto(write_addr, bytearray([init_write])) # initialize the dumb thing lsb = i2c.readfrom(read_lsb_addr, 1) # read 4 bytes from slave with 7-bit address 42 msb = i2c.readfrom(read_msb_addr, 1) # read 4 bytes from slave with 7-bit address 42 i2c.deinit() value = msb[0] << 1 | lsb[0] babel_out.babel_strstore(str(round(value, 3)) + "Lumens")
import babel_out import time from machine import Pin import time from machine import I2C i2c_addr = 0x40 #id, scl, sda, freq i2c = I2C(id=-1, scl=27, sda=26, freq=100000) # create I2C peripheral at frequency of 400kH i2c.writeto(i2c_addr, bytearray([0x00, 0x39, 0x9F])) # initialize the dumb thing i2c.writeto(i2c_addr, bytearray([0x05, 4096 >> 8, 4096 & 0xFF])) # initialize the dumb thing i2c.writeto(i2c_addr, bytearray([0x04])) # initialize the dumb thing time.sleep(.05) raw_current = i2c.readfrom(i2c_addr, 2) # read 4 bytes from slave with 7-bit address 42 ma_current = raw_current[0] << 8 | raw_current[1] babel_out.babel_strstore(str(round(ma_current / 10.0, 3)) + "mA") i2c.deinit()
import babel_out import time # create an output pin on pin #0 adc_val = babel_out.babel_get_adc() temp = (adc_val - 500) / 10. babel_out.babel_strstore(str(round(temp, 3)) + "C") time.sleep(.1)
import babel_out import time from machine import Pin def do_data(cycles): clk.value(0) prev_value = 0 while data.value() != 0 or prev_value != 1: prev_value = data.value() result = 0 for i in range(cycles): clk.value(1) clk.value(0) if i < 24: result = (result | (data.value() << (23 - i))) time.sleep(.01) return result data = Pin(26, Pin.IN) clk = Pin(27, Pin.OUT) r1 = do_data(26) r1 = 1.0 * r1 / (1 << 24 - 1) * 3.26 / 2 r2 = do_data(25) clk.value(1) babel_out.babel_strstore(str(round(r2, 5)) + " adc2")