redoing things

This commit is contained in:
Maff 2018-08-27 00:08:16 +01:00
parent 0983d2c010
commit 6bdeb122d7
1 changed files with 113 additions and 38 deletions

151
main.py
View File

@ -1,48 +1,123 @@
import uPyConfig
hw = uPyConfig.esp32()
#hw = uPyConfig.esp32()
hw = uPyConfig.esp8266(variant='d1-r2')
import webrepl
webrepl.start()
#print family, variant and IP address (using oled, if available on-board)
import init_sample
init_sample.PrintHWInfo(hw)
#import init_sample
#init_sample.PrintHWInfo(hw)
# 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 ST7735 import TFT
from time import sleep_ms
#from ST7735 import TFT
#from time import sleep_ms
tft_spibus=2
tft_mosi=Pin(23)
tft_sck=Pin(5)
tft_dc=17
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)
tft.on()
tft.initg()
tft.initb()
tft.rgb(True)
tft.initr()
sleep_ms(200)
tft.fill(tft.RED)
sleep_ms(40)
tft.fill(tft.BLUE)
sleep_ms(40)
tft.fill(tft.GREEN)
sleep_ms(40)
tft.fill(tft.PURPLE)
sleep_ms(40)
tft.fill(tft.WHITE)
sleep_ms(800)
from fonts import terminal
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)
#display initialise
#tft_spibus=2
#tft_mosi=Pin(23)
#tft_sck=Pin(5)
#tft_dc=17
#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)
##turn display on, init green, blue, enable RGB, then init red.
##i don't get it either, but this is the only way i've found to get the screen fully working
##anything else either doesn't display correct colours, or it does but there's a bar on the side of the screen
#tft.on()
#tft.initg()
#tft.initb()
#tft.rgb(True)
#tft.initr()
#sleep_ms(200)
#tft.fill(tft.RED)
#sleep_ms(40)
#tft.fill(tft.BLUE)
#sleep_ms(40)
#tft.fill(tft.GREEN)
#sleep_ms(40)
#tft.fill(tft.PURPLE)
#sleep_ms(40)
#tft.fill(tft.WHITE)
#sleep_ms(800)
#
#from fonts import terminal
#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)
#