from machine import Pin, I2C, ADC import SSD1306 as SSD1306 import utime, gc # 50.3k & 48.3k def remap(value, leftMin, leftMax, rightMin, rightMax): leftSpan = leftMax - leftMin rightSpan = rightMax - rightMin valueScaled = float(value - leftMin) / float(leftSpan) return rightMin + (valueScaled * rightSpan) _MEAS_COUNT = 3 adc = ADC(Pin(32)) # create ADC object on ADC pin adc.atten(ADC.ATTN_11DB) # set 11dB input attenuation (voltage range roughly 0.0v - 3.6v) print("ADC set") i2c1 = I2C(-1, scl=Pin(22), sda=Pin(21)) oled = SSD1306.SSD1306_I2C(128, 64, i2c1, 0x3c) # 0x3C = 60 print("OLED set") oled.fill(1) oled.show() utime.sleep(1) oled.fill(0) oled.show() oled.text("Hello", 0, 0) oled.show() utime.sleep(1) print("Goin into loop...") while True: # make 3 measurements # show average on screen # sleep for one second total = 0 for i in range(_MEAS_COUNT): total = total + int(adc.read()) utime.sleep_ms(100) raw = int(total / _MEAS_COUNT) oled.fill(0) oled.text("{} {}v".format(raw, remap(raw, 1350, 1680, 2.69, 3.214)) , 10, 0) oled.show() print(str(int(total / _MEAS_COUNT))) utime.sleep_ms(1000)