from machine import I2C, Pin, Timer, RTC from network import STA_IF, WLAN import ssd1306 import time import utime from mpu6050 import accel screen = {} screen['rst'] = Pin(16, Pin.OUT) screen['rst'].value(1) screen['scl'] = Pin(15, Pin.OUT, Pin.PULL_UP) screen['sda'] = Pin(4, Pin.OUT, Pin.PULL_UP) screen['i2c'] = I2C(scl=screen['scl'], sda=screen['sda'], freq=450000) oled = ssd1306.SSD1306_I2C(128, 64, screen['i2c'], addr=0x3c) oled.fill(0) oled.text('Initializing',5,5) oled.show() mpu = {} mpu['scl'] = Pin(19, Pin.OUT, Pin.PULL_UP) mpu['sda'] = Pin(23, Pin.OUT, Pin.PULL_UP) mpu['i2c'] = I2C(scl=mpu['scl'], sda=mpu['sda']) accelerometer = accel(mpu['i2c']) def date_time(): (y,mo,d,wd,h,mi,s,*v) = RTC().datetime() (y,mo,d,h,mi,s,wd,yd) = utime.localtime(utime.mktime((y,mo,d,h,mi,s,wd,0))-4*3600) return ('%02d/%02d/%02d' % (mo,d,y-2000), '%02d:%02d:%02d' % (h,mi,s)) def ip(): return WLAN(STA_IF).ifconfig()[0] def output_positions(arg): oled.fill(0) oled.text('X: %(AcX)+05d' % arg, 5, 5) oled.text('Y: %(AcY)+05d' % arg, 5, 15) oled.text('Z: %(AcZ)+05d' % arg, 5, 25) (d,t) = date_time() oled.text(d,5,35) oled.text(t,5,45) oled.text(ip(),5,55) oled.show() def run_cycle(): output_positions(accelerometer.get_values()) timer = Timer(0) timer.init(period=1000, mode=Timer.PERIODIC, callback=lambda t:run_cycle())