redoing things
This commit is contained in:
parent
0983d2c010
commit
6bdeb122d7
151
main.py
151
main.py
|
@ -1,48 +1,123 @@
|
||||||
import uPyConfig
|
import uPyConfig
|
||||||
|
|
||||||
hw = uPyConfig.esp32()
|
#hw = uPyConfig.esp32()
|
||||||
|
hw = uPyConfig.esp8266(variant='d1-r2')
|
||||||
import webrepl
|
import webrepl
|
||||||
webrepl.start()
|
webrepl.start()
|
||||||
#print family, variant and IP address (using oled, if available on-board)
|
#print family, variant and IP address (using oled, if available on-board)
|
||||||
import init_sample
|
#import init_sample
|
||||||
init_sample.PrintHWInfo(hw)
|
#init_sample.PrintHWInfo(hw)
|
||||||
|
|
||||||
# Main app
|
# Main app
|
||||||
from machine import Pin, TouchPad, SPI
|
from uPySensor import *
|
||||||
|
hw.owc.__init__(hw.owc, 12)
|
||||||
|
bme280 = BME280 (hw.i2c.bus)
|
||||||
|
lm75a = LM75A (hw.i2c.bus)
|
||||||
|
sht21 = SHT21 (hw.i2c.bus)
|
||||||
|
ds18b20= DS18B20(hw.owc.bus)
|
||||||
|
from machine import unique_id
|
||||||
|
import ubinascii
|
||||||
|
from umqtt.simple import MQTTClient
|
||||||
|
server="10.13.37.18"
|
||||||
|
client_id=ubinascii.hexlify(unique_id())
|
||||||
|
mqttc=MQTTClient(client_id,server)
|
||||||
|
mqttc.connect()
|
||||||
|
|
||||||
|
def _bme280():
|
||||||
|
bme280.update_sensor()
|
||||||
|
mqttc.publish(b'home/temp/indoor/bme280/1', "%0.2f" % bme280.temperature)
|
||||||
|
mqttc.publish(b'home/humidity/indoor/bme280/1', "%0.2f" % bme280.humidity)
|
||||||
|
mqttc.publish(b'home/pressure/indoor/bme280/1', "%0.2f" % bme280.pressure)
|
||||||
|
def _sht21():
|
||||||
|
mqttc.publish(b'home/temp/indoor/sht21/1', "%0.3f" % sht21.read_tempC())
|
||||||
|
mqttc.publish(b'home/humidity/indoor/sht21/1', "%0.3f" % sht21.read_hum())
|
||||||
|
def _lm75a(): mqttc.publish(b'home/temp/indoor/lm75a/1', "%0.1f" % lm75a.read_tempC())
|
||||||
|
|
||||||
|
#from machine import Pin, TouchPad, SPI
|
||||||
|
|
||||||
#from uPaper import epaper, fbuf
|
#from uPaper import epaper, fbuf
|
||||||
from ST7735 import TFT
|
#from ST7735 import TFT
|
||||||
from time import sleep_ms
|
#from time import sleep_ms
|
||||||
|
|
||||||
tft_spibus=2
|
#display initialise
|
||||||
tft_mosi=Pin(23)
|
#tft_spibus=2
|
||||||
tft_sck=Pin(5)
|
#tft_mosi=Pin(23)
|
||||||
tft_dc=17
|
#tft_sck=Pin(5)
|
||||||
tft_rst=12
|
#tft_dc=17
|
||||||
tft_cs=16
|
#tft_rst=12
|
||||||
|
#tft_cs=16
|
||||||
spi=SPI(tft_spibus,baudrate=20000000,polarity=0,phase=0,mosi=tft_mosi,sck=tft_sck)
|
#
|
||||||
tft=TFT(spi,tft_dc,tft_rst,tft_cs)
|
#spi=SPI(tft_spibus,baudrate=20000000,polarity=0,phase=0,mosi=tft_mosi,sck=tft_sck)
|
||||||
tft.on()
|
#tft=TFT(spi,tft_dc,tft_rst,tft_cs)
|
||||||
tft.initg()
|
##turn display on, init green, blue, enable RGB, then init red.
|
||||||
tft.initb()
|
##i don't get it either, but this is the only way i've found to get the screen fully working
|
||||||
tft.rgb(True)
|
##anything else either doesn't display correct colours, or it does but there's a bar on the side of the screen
|
||||||
tft.initr()
|
#tft.on()
|
||||||
sleep_ms(200)
|
#tft.initg()
|
||||||
tft.fill(tft.RED)
|
#tft.initb()
|
||||||
sleep_ms(40)
|
#tft.rgb(True)
|
||||||
tft.fill(tft.BLUE)
|
#tft.initr()
|
||||||
sleep_ms(40)
|
#sleep_ms(200)
|
||||||
tft.fill(tft.GREEN)
|
#tft.fill(tft.RED)
|
||||||
sleep_ms(40)
|
#sleep_ms(40)
|
||||||
tft.fill(tft.PURPLE)
|
#tft.fill(tft.BLUE)
|
||||||
sleep_ms(40)
|
#sleep_ms(40)
|
||||||
tft.fill(tft.WHITE)
|
#tft.fill(tft.GREEN)
|
||||||
sleep_ms(800)
|
#sleep_ms(40)
|
||||||
|
#tft.fill(tft.PURPLE)
|
||||||
from fonts import terminal
|
#sleep_ms(40)
|
||||||
from network import WLAN as wlan, STA_IF as staif
|
#tft.fill(tft.WHITE)
|
||||||
|
#sleep_ms(800)
|
||||||
tft.text((4,6),hw.family,tft.BLACK,terminal.data)
|
#
|
||||||
tft.text((4,16),hw.variant,tft.BLACK,terminal.data)
|
#from fonts import terminal
|
||||||
tft.text((4,26),wlan(staif).ifconfig()[0],tft.BLACK,terminal.data)
|
#from network import WLAN as wlan, STA_IF as staif
|
||||||
|
#
|
||||||
|
#tft.text((4,6),hw.family,tft.BLACK,terminal.data)
|
||||||
|
#tft.text((4,16),hw.variant,tft.BLACK,terminal.data)
|
||||||
|
#tft.text((4,26),wlan(staif).ifconfig()[0],tft.BLACK,terminal.data)
|
||||||
|
#
|
||||||
|
#w=32
|
||||||
|
#h=25
|
||||||
|
#
|
||||||
|
#buttonA=Pin(35,Pin.IN)
|
||||||
|
#buttonB=Pin(34,Pin.IN)
|
||||||
|
#buttonC=Pin(39,Pin.IN)
|
||||||
|
#stateA=1
|
||||||
|
#stateB=1
|
||||||
|
#stateC=1
|
||||||
|
#
|
||||||
|
#import machine
|
||||||
|
#
|
||||||
|
#def buttonInterrupt(p):
|
||||||
|
# print(p)
|
||||||
|
# if p==buttonA:
|
||||||
|
# stateA=p.value()
|
||||||
|
# buttonChange(0)
|
||||||
|
# elif p==buttonB:
|
||||||
|
# stateB=p.value()
|
||||||
|
# buttonChange(1)
|
||||||
|
# elif p==buttonC:
|
||||||
|
# stateC=p.value()
|
||||||
|
# buttonChange(2)
|
||||||
|
# else:
|
||||||
|
# print("unrecognised button")
|
||||||
|
#
|
||||||
|
#def buttonChange(i):
|
||||||
|
# left=2+(w*i)+i
|
||||||
|
# c=tft.RED
|
||||||
|
# if i==0: c=(tft.GREEN if stateA==0 else tft.RED)
|
||||||
|
# elif i==1: c=(tft.GREEN if stateB==0 else tft.RED)
|
||||||
|
# elif i==2: c=(tft.GREEN if stateC==0 else tft.RED)
|
||||||
|
# else: return
|
||||||
|
# tft.rect((left,128-h),(w,h),c)
|
||||||
|
#
|
||||||
|
#buttonChange(0)
|
||||||
|
#buttonChange(1)
|
||||||
|
#buttonChange(2)
|
||||||
|
#buttonA.irq(trigger=Pin.IRQ_FALLING, handler=buttonInterrupt)
|
||||||
|
#buttonA.irq(trigger=Pin.IRQ_RISING, handler=buttonInterrupt)
|
||||||
|
#buttonB.irq(trigger=Pin.IRQ_FALLING, handler=buttonInterrupt)
|
||||||
|
#buttonB.irq(trigger=Pin.IRQ_RISING, handler=buttonInterrupt)
|
||||||
|
#buttonC.irq(trigger=Pin.IRQ_FALLING, handler=buttonInterrupt)
|
||||||
|
#buttonC.irq(trigger=Pin.IRQ_RISING, handler=buttonInterrupt)
|
||||||
|
#
|
Loading…
Reference in New Issue