Beispiel #1
0
    def __init__(self, wlan, SSID, PASSWD):
        #init wlan
        self.wlan = wlan
        self.SSID = SSID
        self.PASSWD = PASSWD

        #init time
        print('ntp_url:', self.ntp_url)
        ntptime.host = self.ntp_url
        print('ntp_host:', ntptime.host)
        ntptime.time()
        ntptime.settime()
        self.last_time_update = time.time()
        print('init_time:', time.localtime(self.last_time_update + 3600 * 8))

        #init data
        print('dat_url:', self.dat_url)

        #init display mod
        '''
        mode:
            0:cycle
            1:temp only
            2:pres only
            3:water only
            4:humi only
        '''
        self.mode = 0
        '''
        last:
            0:temp
            1:pres
            2:water
            3:humi
        '''
        self.last = 0

        #init tft
        print('init TFT...')
        spi = SPI(1, baudrate=32000000, polarity=0, phase=0)
        self.tft = TFT(spi, 2, 16, 0)
        self.tft.init_7735(self.tft.GREENTAB128x128)
        self.tft.fill(TFT.WHITE)
        self.tft.text((5, 10), "initlizing", TFT.YELLOW, 2, nowrap=True)
        self.tft.text((5, 50), "please wait", TFT.YELLOW, 2, nowrap=True)

        self.run()
Beispiel #2
0
 def __init__(self, screensize):
     spi = SPI(1, baudrate=20000000, polarity=0, phase=0,
               sck=Pin(SPI_SCK), mosi=Pin(SPI_SDO), miso=None)
     # def __init__( self, spi, aDC, aReset, aCS) :
     # Pin details for SPI interface for screen
     self.tft = TFT(spi, SPI_DC, SPI_RS, SPI_CS)
     self.tft.initg()   # Change this to make screen dimensions match board i.e if you get a line around the edge driver needs rewwwok for this
     self.tft.rgb(True)
     self.tft.set_size(screensize)
     self.set_caption("Tetris")
     self.level = 2
     self.screenSize = screensize
     # Board offsets
     self.x = 4
     self.y = 10
     
     # Pin details for buttons.
     self.right_button = button(19)
     self.left_button = button(14)
Beispiel #3
0
## ADC.WIDTH_11BIT: range 0 to 2047
## ADC.WIDTH_12BIT: range 0 to 4095

# from https://forum.micropython.org/viewtopic.php?t=5677
# is it any better?
# spi = SPI(2, baudrate=20000000, sck=Pin(18), mosi=Pin(23), miso=Pin(19))

spi = SPI(2,
          baudrate=24000000,
          polarity=0,
          phase=0,
          sck=Pin(14),
          mosi=Pin(13),
          miso=Pin(12))

tft1 = TFT(spi, aDC=16, aReset=17, aCS=23)
tft2 = TFT(spi, aDC=16, aReset=19, aCS=18)

# left pos and joystick offset
xl = 50
yl = 50
hl_off = -195  # TODO
vl_off = -384  # TODO

# right pos and joystick offset
xr = 50
yr = 50
hr_off = -195
vr_off = -384

Beispiel #4
0
import gc
gc.collect()
gc.mem_free()

pycom.heartbeat(False)
pycom.rgbled(0xff00)  # turn on the RGB LED in green colour
rep = 3

print("Startup Time")

os.uname()

#SPI using standard pins
spi = SPI(SPI.MASTER, baudrate=40000000, polarity=0, phase=0)
#arg1 = DC, arg2 = RES, arg3=CS
tft = TFT(spi, 'P4', 'P1', 'P3')
#tft=TFT(spi,16,17,18)
tft.initr()
tft.rgb(True)
tft.fill(TFT.BLACK)

v = 0
fft_print = "Startup"
tft.text((0, v), fft_print, TFT.WHITE, sysfont, 1)
time.sleep_ms(5000)
tft.fill(TFT.BLACK)

print("Go")

#====================================================================================================
# Setup
from ST7735 import TFT
from sysfont import sysfont
from machine import SPI, Pin
import network
import time
import math
spi = SPI(2,
          baudrate=20000000,
          polarity=0,
          phase=0,
          sck=Pin(05),
          mosi=Pin(23),
          miso=Pin(19))
tft = TFT(spi, 17, 9, 16)
tft.rgb(True)
tft.initg()
sta = network.WLAN(network.STA_IF)
sta.active(True)
sta.scan()
sta.isconnected()
sta.connect("SSID", "PASSWD")
sta.ifconfig()


def testlines(color):
    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((0, 0), (x, tft.size()[1] - 1), color)
    for y in range(0, tft.size()[1], 6):
        tft.line((0, 0), (tft.size()[0] - 1, y), color)
import os
os.listdir()

from ST7735 import TFT
from sysfont import sysfont
from machine import SPI,Pin
import time
import math
spi = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
tft=TFT(spi,16,17,18)
tft.initr()
tft.rgb(True)
tft.fill(TFT.BLACK);
v = 0
tft.text((0, v), "Hello World! abcdefghijkl", TFT.RED, sysfont, 2, nowrap=False)
Beispiel #7
0
from ST7735 import TFT
from sysfont import sysfont
from machine import SPI, Pin
import time
import math
#hardware SPI, HSPI
spi = SPI(1, baudrate=8000000, polarity=0, phase=0)
# dc, rst, cs
# tft=TFT(spi,2,16,0)
tft = TFT(spi, 2, 16)
tft.init_7735(tft.REDTAB)
'''
def testlines(color):
    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((0,0),(x, tft.size()[1] - 1), color)
    for y in range(0, tft.size()[1], 6):
        tft.line((0,0),(tft.size()[0] - 1, y), color)

    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((tft.size()[0] - 1, 0), (x, tft.size()[1] - 1), color)
    for y in range(0, tft.size()[1], 6):
        tft.line((tft.size()[0] - 1, 0), (0, y), color)

    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((0, tft.size()[1] - 1), (x, 0), color)
    for y in range(0, tft.size()[1], 6):
        tft.line((0, tft.size()[1] - 1), (tft.size()[0] - 1,y), color)
Beispiel #8
0
from ST7735 import TFT,TFTColor
from machine import SPI,Pin
#spi = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
#hardware SPI, HSPI
spi = SPI(1, baudrate=8000000, polarity=0, phase=0)
# dc, rst, cs
# tft=TFT(spi,2,16,0)
tft=TFT(spi,2,16)
tft.init_7735(tft.GREENTAB80x160)
tft.rotation(1)
tft.fill(TFT.BLACK)


f=open('flower128x160.bmp', 'rb')
if f.read(2) == b'BM':  #header
    dummy = f.read(8) #file size(4), creator bytes(4)
    offset = int.from_bytes(f.read(4), 'little')
    hdrsize = int.from_bytes(f.read(4), 'little')
    width = int.from_bytes(f.read(4), 'little')
    height = int.from_bytes(f.read(4), 'little')
    if int.from_bytes(f.read(2), 'little') == 1: #planes must be 1
        depth = int.from_bytes(f.read(2), 'little')
        if depth == 24 and int.from_bytes(f.read(4), 'little') == 0:#compress method == uncompressed
            print("Image size:", width, "x", height)
            rowsize = (width * 3 + 3) & ~3
            if height < 0:
                height = -height
                flip = False
            else:
                flip = True
            w, h = width, height
Beispiel #9
0

enable_lcd_power()

# Define variables for LCD access and print title
spi = machine.SPI(
    1,
    baudrate=27000000,
    polarity=0,
    phase=0,
    bits=8,
    firstbit=machine.SPI.MSB,
    sck=machine.Pin(13),
    mosi=machine.Pin(15)
)  # Set baudrate way high but will be clamped to a maximum in SPI constructor
tft = TFT(spi, 23, 18, 5)
tft.initr()  # Initialize LCD screen
tft.invertcolor(
    True
)  # This is required for RGB to be parsed correctly (for some reason, 0x00 and 0xFF are flipped on normal mode)
tft.rgb(True)
tft.rotation(3)  # Rotate to landscape mode
tft.fill(
)  # We use black background since text chars would be encapsulated by black background, not transparent

tft.text((20, 40), 'deLIGHT', TFT.YELLOW, sysfont, 3, nowrap=True)
tft.text((20, 70), 'Wi-Fi', TFT.CYAN, sysfont, 2, nowrap=True)


def station():
    # Enable station interface
Beispiel #10
0
import os
import time

from ST7735 import TFT,TFTColor
from machine import SPI,Pin


# hardware SPI, HSPI
# spi = SPI(1, baudrate=8000000, polarity=0, phase=0)
spi = SPI(1, baudrate=125200, polarity=0, phase=0)

tft=TFT(spi,0,0,2)
tft.init_7735(tft.GREENTAB128x128)
tft.rotation(2)
tft.fill(TFT.BLACK)

def load_image(path):
    f=open(path, 'rb')
    if f.read(2) == b'BM':  #header
        dummy = f.read(8) #file size(4), creator bytes(4)
        offset = int.from_bytes(f.read(4), 'little')
        hdrsize = int.from_bytes(f.read(4), 'little')
        width = int.from_bytes(f.read(4), 'little')
        height = int.from_bytes(f.read(4), 'little')
        if int.from_bytes(f.read(2), 'little') == 1: #planes must be 1
            depth = int.from_bytes(f.read(2), 'little')
            if depth == 24 and int.from_bytes(f.read(4), 'little') == 0:#compress method == uncompressed
                print("Image size:", width, "x", height)
                rowsize = (width * 3 + 3) & ~3
                if height < 0:
                    height = -height
Beispiel #11
0
beeper = PWM(Pin(26, Pin.OUT), freq=440, duty=512)

valid_tone = 'eagc'
invalid_tone = 'cgae'
rhythm =  l*[4]

#---RDM6300---
uart1 = UART(1, baudrate=9600, tx=39, rx=16)        # 39 possiblement à changer
buf = bytearray(4)                                  # 4 changeable 

#---RC522----
rdr = mfrc522.MFRC522(14, 13, 12, 5, 21)

#---ST735---
spi = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(27), mosi=Pin(32), miso=Pin(12))
tft=TFT(spi,33,17,18)
tft.initg()
tft.rgb(False)
tft.fill(TFT.BLACK)


#--------bouvcle principale------------
while True:

    #---lecture ID (125kHz)---#
    if uart1.any():
        uart1.readinto(buf)                          # UART.read([nbytes]) ou sinon UART.readinto(buf[, nbytes])
	ID = bytes(buf)
    
    #---lecture ID (13MHz)---#
    (stat, tag_type) = rdr.request(rdr.REQIDL)
Beispiel #12
0
    def __init__(self):
        self.font1 = {
            "Width":
            6,
            "Height":
            8,
            "Start":
            32,
            "End":
            127,
            "Data":
            bytearray([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x5F,
                0x06, 0x00, 0x00, 0x07, 0x03, 0x00, 0x07, 0x03, 0x00, 0x24,
                0x7E, 0x24, 0x7E, 0x24, 0x00, 0x24, 0x2B, 0x6A, 0x12, 0x00,
                0x00, 0x63, 0x13, 0x08, 0x64, 0x63, 0x00, 0x36, 0x49, 0x56,
                0x20, 0x50, 0x00, 0x00, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00,
                0x3E, 0x41, 0x00, 0x00, 0x00, 0x00, 0x41, 0x3E, 0x00, 0x00,
                0x00, 0x08, 0x3E, 0x1C, 0x3E, 0x08, 0x00, 0x08, 0x08, 0x3E,
                0x08, 0x08, 0x00, 0x00, 0xE0, 0x60, 0x00, 0x00, 0x00, 0x08,
                0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00,
                0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x3E, 0x51, 0x49,
                0x45, 0x3E, 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, 0x62,
                0x51, 0x49, 0x49, 0x46, 0x00, 0x22, 0x49, 0x49, 0x49, 0x36,
                0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, 0x2F, 0x49, 0x49,
                0x49, 0x31, 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30, 0x00, 0x01,
                0x71, 0x09, 0x05, 0x03, 0x00, 0x36, 0x49, 0x49, 0x49, 0x36,
                0x00, 0x06, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00, 0x6C, 0x6C,
                0x00, 0x00, 0x00, 0x00, 0xEC, 0x6C, 0x00, 0x00, 0x00, 0x08,
                0x14, 0x22, 0x41, 0x00, 0x00, 0x24, 0x24, 0x24, 0x24, 0x24,
                0x00, 0x00, 0x41, 0x22, 0x14, 0x08, 0x00, 0x02, 0x01, 0x59,
                0x09, 0x06, 0x00, 0x3E, 0x41, 0x5D, 0x55, 0x1E, 0x00, 0x7E,
                0x11, 0x11, 0x11, 0x7E, 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,
                0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, 0x7F, 0x41, 0x41,
                0x41, 0x3E, 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, 0x7F,
                0x09, 0x09, 0x09, 0x01, 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,
                0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x00, 0x41, 0x7F,
                0x41, 0x00, 0x00, 0x30, 0x40, 0x40, 0x40, 0x3F, 0x00, 0x7F,
                0x08, 0x14, 0x22, 0x41, 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,
                0x00, 0x7F, 0x02, 0x04, 0x02, 0x7F, 0x00, 0x7F, 0x02, 0x04,
                0x08, 0x7F, 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x7F,
                0x09, 0x09, 0x09, 0x06, 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,
                0x00, 0x7F, 0x09, 0x09, 0x19, 0x66, 0x00, 0x26, 0x49, 0x49,
                0x49, 0x32, 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01, 0x00, 0x3F,
                0x40, 0x40, 0x40, 0x3F, 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,
                0x00, 0x3F, 0x40, 0x3C, 0x40, 0x3F, 0x00, 0x63, 0x14, 0x08,
                0x14, 0x63, 0x00, 0x07, 0x08, 0x70, 0x08, 0x07, 0x00, 0x71,
                0x49, 0x45, 0x43, 0x00, 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,
                0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x41, 0x41,
                0x7F, 0x00, 0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x80, 0x80,
                0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x03, 0x07, 0x00, 0x00,
                0x00, 0x20, 0x54, 0x54, 0x54, 0x78, 0x00, 0x7F, 0x44, 0x44,
                0x44, 0x38, 0x00, 0x38, 0x44, 0x44, 0x44, 0x28, 0x00, 0x38,
                0x44, 0x44, 0x44, 0x7F, 0x00, 0x38, 0x54, 0x54, 0x54, 0x08,
                0x00, 0x08, 0x7E, 0x09, 0x09, 0x00, 0x00, 0x18, 0xA4, 0xA4,
                0xA4, 0x7C, 0x00, 0x7F, 0x04, 0x04, 0x78, 0x00, 0x00, 0x00,
                0x00, 0x7D, 0x40, 0x00, 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,
                0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x00, 0x7F,
                0x40, 0x00, 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78, 0x00, 0x7C,
                0x04, 0x04, 0x78, 0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38,
                0x00, 0xFC, 0x44, 0x44, 0x44, 0x38, 0x00, 0x38, 0x44, 0x44,
                0x44, 0xFC, 0x00, 0x44, 0x78, 0x44, 0x04, 0x08, 0x00, 0x08,
                0x54, 0x54, 0x54, 0x20, 0x00, 0x04, 0x3E, 0x44, 0x24, 0x00,
                0x00, 0x3C, 0x40, 0x20, 0x7C, 0x00, 0x00, 0x1C, 0x20, 0x40,
                0x20, 0x1C, 0x00, 0x3C, 0x60, 0x30, 0x60, 0x3C, 0x00, 0x6C,
                0x10, 0x10, 0x6C, 0x00, 0x00, 0x9C, 0xA0, 0x60, 0x3C, 0x00,
                0x00, 0x64, 0x54, 0x54, 0x4C, 0x00, 0x00, 0x08, 0x3E, 0x41,
                0x41, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x00,
                0x41, 0x41, 0x3E, 0x08, 0x00, 0x02, 0x01, 0x02, 0x01, 0x00,
                0x00, 0x3C, 0x26, 0x23, 0x26, 0x3C
            ])
        }
        #updated pins/buttons
        self.BTN_1 = 0
        self.BTN_2 = 1
        self.BTN_3 = 2
        self.BTN_4 = 3
        self.BTN_5 = 4
        self.BTN_6 = 5
        self.BTN_7 = 6
        self.BTN_8 = 7
        self.BTN_9 = 8
        self.BTN_ASTERISK = 9
        self.BTN_0 = 10
        self.BTN_HASHTAG = 11
        self.BTN_FUN_RIGHT = 12
        self.BTN_FUN_LEFT = 15
        self.BTN_A = 16
        self.BTN_B = 17
        #obsolete buttons, successor - readJoystickX/Y()
        # self.BTN_UP = 18
        # self.BTN_DOWN = 19
        # self.BTN_LEFT = 20
        # self.BTN_RIGHT = 21

        self._BL_PIN = 21
        self._PIXELS_PIN = 12
        self._SIM_PIXELS_ENABLE_PIN = 26
        self._NUM_PIXELS = 8

        self.i2c = I2C(scl=Pin(27), sda=Pin(14), freq=100000)  #ok
        self.buttons = buttons()
        #self.buttons = PCA9539(self.i2c, 0x21) #21 for main buttons, 20 for numerical keypad
        self.spi = SPI(2,
                       baudrate=20000000,
                       polarity=0,
                       phase=0,
                       sck=Pin(18),
                       mosi=Pin(23),
                       miso=Pin(19))  #ok
        self.display = TFT(self.spi, 0, 2, 4)  #ok
        self.display.initr()
        self.display.rgb(True)
        self.display.rotation(1)  #rotation changed to 1 (top left)
        self.display.fill(0)
        self.pixels = NeoPixel(Pin(self._PIXELS_PIN, Pin.OUT),
                               self._NUM_PIXELS,
                               timing=True)

        self.BLACK = 0
        self.RED = self.display.RED
        self.MAROON = self.display.MAROON
        self.GREEN = self.display.GREEN
        self.FOREST = self.display.FOREST
        self.BLUE = self.display.BLUE
        self.NAVY = self.display.NAVY
        self.CYAN = self.display.CYAN
        self.YELLOW = self.display.YELLOW
        self.PURPLE = self.display.PURPLE
        self.WHITE = self.display.WHITE
        self.GRAY = self.display.GRAY

        Pin(self._BL_PIN, Pin.OUT).value(0)
Beispiel #13
0
from machine import Pin, SPI
from ST7735 import TFT
from sysfont import sysfont
from time import sleep_ms

#led_r = Pin(13, Pin.OUT, value=0)
#led_g = Pin(14, Pin.OUT, value=0)
#led_b = Pin(15, Pin.OUT, value=0)

spi = SPI(0, 1000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19))
#spi = machine.SPI(0)
print(spi)
tft = TFT(spi, 22, 21, 20)  # DC, RST, CS
tft.initr()
tft.rgb()
tft.rotation(2)
tft.fill(TFT.BLACK)


def tft_draw_char(string, px, py):
    long = len(string)
    for x in range(long):
        c = string[x]
        tft.text((px, py), str(c), TFT.GREEN, sysfont, 1)
        sleep_ms(120)
        px = px + 6


while True:
    tft.fill(TFT.BLACK)
    sleep_ms(1200)
Beispiel #14
0
wlan.connect('Robots-JU', 'robotmaker')
time.sleep(2)

cnx = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
time.sleep(2)
cnx.connect(("192.168.2.106", 3714))  #####faire gaffe à l'addresse IP

time.sleep(0.5)
#cnx.send(b'GETcoucou')
print('ready')

#---ST735---
spi = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(27),
          mosi=Pin(32))  #, miso=Pin(12))

tft = TFT(spi, 33, 17, 18)
tft.initg()
tft.rgb(False)
tft.rotation(1)
time.sleep(0.1)
tft.fill(TFT.BLACK)

if uart1.any():
    uart1.read()

#--------bouvcle principale------------
while True:

    #---lecture ID (125kHz)---#
    if uart1.any():
        idi = uart1.read(13)
Beispiel #15
0
                tft._setwindowloc((0, 0), (w - 1, h - 1))
                for row in range(h):
                    if flip:
                        pos = offset + (height - 1 - row) * rowsize
                    else:
                        pos = offset + row * rowsize
                    if f.tell() != pos:
                        dummy = f.seek(pos)
                    for col in range(w):
                        bgr = f.read(3)
                        _tft._pushcolor(TFTColor(bgr[2], bgr[1], bgr[0]))
            else:
                print(FileName + 'is not 24bit pic')


tft = TFT(spi, dc, rst, cs)
tft.init_7735(TFT.GREENTAB80x160)
tft.rotation(3)
LCD_ShowBmp(tft, 'WeActStudiologo.bmp')
time.sleep(50)
LCD_LEDSet = 1
time.sleep(1000)
tft.fill(TFT.BLACK)
tft.text((0, 30), 'Hello WeAct!', TFT.WHITE, sysfont, 2, nowrap=False)

sensor.reset()  # Reset and initialize the sensor.
sensor.set_pixformat(
    sensor.RGB565)  # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)  # Set frame size to QVGA (320x240)

if sensor.get_id() == sensor.OV7725:
Beispiel #16
0
class main():

    x_min = 15
    x_max = 120
    y_top = 50
    y_bottom = 120
    temp = []
    pres = []
    water = []
    humi = []
    date = []
    ntp_url = 'ntp4.aliyun.com'
    dat_url = 'put your own address here'
    last_time_update = None

    def __init__(self, wlan, SSID, PASSWD):
        #init wlan
        self.wlan = wlan
        self.SSID = SSID
        self.PASSWD = PASSWD

        #init time
        print('ntp_url:', self.ntp_url)
        ntptime.host = self.ntp_url
        print('ntp_host:', ntptime.host)
        ntptime.time()
        ntptime.settime()
        self.last_time_update = time.time()
        print('init_time:', time.localtime(self.last_time_update + 3600 * 8))

        #init data
        print('dat_url:', self.dat_url)

        #init display mod
        '''
        mode:
            0:cycle
            1:temp only
            2:pres only
            3:water only
            4:humi only
        '''
        self.mode = 0
        '''
        last:
            0:temp
            1:pres
            2:water
            3:humi
        '''
        self.last = 0

        #init tft
        print('init TFT...')
        spi = SPI(1, baudrate=32000000, polarity=0, phase=0)
        self.tft = TFT(spi, 2, 16, 0)
        self.tft.init_7735(self.tft.GREENTAB128x128)
        self.tft.fill(TFT.WHITE)
        self.tft.text((5, 10), "initlizing", TFT.YELLOW, 2, nowrap=True)
        self.tft.text((5, 50), "please wait", TFT.YELLOW, 2, nowrap=True)

        self.run()

    def run(self):
        while True:
            self.display_time()
            self.get_dat()
            self.display_data()
            time.sleep(5)

    def get_time(self):
        time_now = time.time()
        if time_now - self.last_time_update >= 3600:
            ntptime.time()
            ntptime.settime()
            time_now = time.time()
            self.last_time_update = time_now
        return time.localtime(time_now + 3600 * 8)

    def display_time(self):
        time_now = self.get_time()
        print("p time", time_now)
        self.tft.fill(TFT.BLACK)
        self.tft.text(
            (5, 5),
            str(time_now[0]) + ' ' + str(time_now[1]) + ' ' + str(time_now[2]),
            TFT.GRAY,
            1.8,
            nowrap=True)
        self.tft.text(
            (35, 20),
            str(time_now[3]) + ':' + str(time_now[4]) + ':' + str(time_now[5]),
            TFT.GRAY,
            1.8,
            nowrap=True)

    def get_dat(self):
        req = requests.get(self.dat_url)
        data = req.json()
        if len(self.date) > 0 and self.date[len(self.date) -
                                            1] == data['date']:
            return
        if len(self.temp) >= 10:
            self.temp.pop(0)
            self.water.pop(0)
            self.humi.pop(0)
            self.pres.pop(0)
            self.date.pop(0)
        self.temp.append(data['tmp2'])
        self.water.append(data['tmp0'])
        self.humi.append(data['humi'])
        self.pres.append(data['pres'])
        self.date.append(data['date'])
        return

    def display_data(self):
        def draw_axis(self):

            self.tft.line((self.x_min, self.y_top),
                          (self.x_min, self.y_bottom), TFT.WHITE)
            self.tft.line((self.x_min, self.y_bottom),
                          (self.x_max, self.y_bottom), TFT.WHITE)
            self.tft.line((self.x_min, self.y_top),
                          (self.x_min - 5, self.y_top + 5), TFT.WHITE)
            self.tft.line((self.x_min, self.y_top),
                          (self.x_min + 5, self.y_top + 5), TFT.WHITE)
            self.tft.line((self.x_max, self.y_bottom),
                          (self.x_max - 5, self.y_bottom + 5), TFT.WHITE)
            self.tft.line((self.x_max, self.y_bottom),
                          (self.x_max - 5, self.y_bottom - 5), TFT.WHITE)
            self.tft.text((self.x_min, self.y_top - 10),
                          "y",
                          TFT.WHITE,
                          1,
                          nowrap=True)
            self.tft.text((self.x_max, self.y_bottom - 10),
                          "x",
                          TFT.WHITE,
                          1,
                          nowrap=True)
            for i in range(self.x_min, self.x_max,
                           floor((self.x_max - self.x_min) / 10)):
                self.tft.line((i, self.y_bottom - 2), (i, self.y_bottom + 3),
                              TFT.WHITE)

        def draw_points(self, data):
            self.y_top = self.y_top + 10
            x_dis = floor((self.x_max - self.x_min) / 10)
            x_now = self.x_min
            dat_min = 100000
            dat_max = -100000
            for i in data:
                if i < dat_min:
                    dat_min = i
                if i > dat_max:
                    dat_max = i

            if dat_min > dat_max:
                return

            points = []
            which = 0
            if dat_min == dat_max:
                for i in data:
                    points.append((floor(x_now),
                                   floor(self.y_bottom +
                                         (self.y_top - self.y_bottom) / 2)))
                    self.tft.circle(points[which], 2, TFT.YELLOW)
                    self.tft.text((points[which][0] - 5, points[which][1] + 5),
                                  str(i),
                                  TFT.CYAN,
                                  0.5,
                                  nowrap=True)
                    self.tft.text(
                        (points[which][0] - 5, points[which][1] - 10),
                        self.date[which][11:16],
                        TFT.CYAN,
                        0.6,
                        nowrap=True)
                    if which > 0:
                        self.tft.line(points[which - 1], points[which],
                                      TFT.YELLOW)
                    which = which + 1
                    x_now = x_now + x_dis
            else:
                for i in data:
                    points.append(
                        (floor(x_now),
                         floor(self.y_bottom + (self.y_top - self.y_bottom) *
                               ((i - dat_min) / (dat_max - dat_min)))))
                    self.tft.circle(points[which], 2, TFT.YELLOW)
                    self.tft.text((points[which][0] - 5, points[which][1] + 5),
                                  str(i),
                                  TFT.CYAN,
                                  0.5,
                                  nowrap=True)
                    self.tft.text(
                        (points[which][0] - 5, points[which][1] - 10),
                        self.date[which][11:16],
                        TFT.CYAN,
                        0.6,
                        nowrap=True)
                    if which > 0:
                        self.tft.line(points[which - 1], points[which],
                                      TFT.YELLOW)
                    which = which + 1
                    x_now = x_now + x_dis

            self.y_top = self.y_top - 10

        draw_axis(self)

        if self.mode == 0:

            if self.last == 0:
                self.last = 1
                self.tft.text((50, 45), "pres", TFT.YELLOW, 1, nowrap=True)
                draw_points(self, self.pres)

            elif self.last == 1:
                self.last = 2
                self.tft.text((50, 45), "water", TFT.YELLOW, 1, nowrap=True)
                draw_points(self, self.water)

            elif self.last == 2:
                self.last = 3
                self.tft.text((50, 45), "humi", TFT.YELLOW, 1, nowrap=True)
                draw_points(self, self.humi)

            elif self.last == 3:
                self.last = 0
                self.tft.text((50, 45), "temp", TFT.YELLOW, 1, nowrap=True)
                draw_points(self, self.temp)

        elif self.mode == 1:
            self.last = 0
            self.tft.text((50, 45), "temp", TFT.YELLOW, 1, nowrap=True)
            draw_points(self, self.temp)

        elif self.mode == 2:
            self.last = 1
            self.tft.text((50, 45), "pres", TFT.YELLOW, 1, nowrap=True)
            draw_points(self, self.pres)

        elif self.mode == 3:
            self.last = 2
            self.tft.text((50, 45), "water", TFT.YELLOW, 1, nowrap=True)
            draw_points(self, self.water)

        elif self.mode == 4:
            self.last = 3
            self.tft.text((50, 45), "humi", TFT.YELLOW, 1, nowrap=True)
            draw_points(self, self.humi)
Beispiel #17
0
from machine import Pin, SPI, Timer
from ST7735 import TFT
from sysfont import sysfont
#from time import sleep_ms

# SETUP THE TFT DISPLAY USING SPI
spi = SPI(0, 1000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19))
print(spi)
tft = TFT(spi, 22, 21, 20)  # DC, RST, CS
tft.initr()
tft.rgb()
tft.rotation(2)
tft.fill(TFT.BLACK)
tft.text((5, 70), "eFreq  >>", TFT.GREEN, sysfont, 1)
tft.text((5, 80), "eTicks >>", TFT.GREEN, sysfont, 1)

# SETUP INTERRUPT COUNTER & PICO IRQ PIN
motorEncoderCnt = 0
motorEncoderPin = Pin(6, Pin.IN,
                      Pin.PULL_UP)  #setup the interrupt pin on the pico
val_old = 0


# SETUP THE CALLBACK FUNCTION ON RECEIPT OF AN INTERRUPT
def motorEncoderCallback(motorEncoderPin):
    global motorEncoderCnt
    motorEncoderCnt += 1  # increment the encoder count by 1 for every interrrupt pulse


# SETUP THE INTERRUPT AND START LISTENING FOR PULSES
motorEncoderPin.irq(trigger=Pin.IRQ_FALLING, handler=motorEncoderCallback)
Beispiel #18
0
from ST7735 import TFT
from machine import SPI, Pin
spi = SPI(2,
          baudrate=20000000,
          polarity=0,
          phase=0,
          sck=Pin(14),
          mosi=Pin(13),
          miso=Pin(12))
tft = TFT(spi, 16, 17, 18)
tft.initb2()
tft.rgb(True)

# Assign 2 pixels for fixed and invisible area
# (ST7735S frame buffer vertical size is 162 pixels)
tft.setvscroll(1, 1)

# Wrapper object for FBConsole
from ST7735fb import TFTfb
from petme128 import petme128
fb = TFTfb(tft, petme128)

# redirect MicroPython terminal to ST7735
from fbconsole import FBConsole
scr = FBConsole(fb, TFT.BLACK, TFT.WHITE)

import os
os.dupterm(scr)
    def TFT_setup(self, spi, dc, reset, cs):

        # setup TFT
        tft = TFT(spi=spi, aDC=dc, aReset=reset, aCS=cs)
        tft.initr()
        tft.rgb(True)
        tft.rotation(3)
        tft.fill(tft.BLACK)
        tft.text((0, 0), ESPCAM_VERSION, tft.WHITE, terminalfont)
        return tft
Beispiel #20
0
from ST7735 import TFT, TFTColor
from machine import SPI, Pin
#spi = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
#hardware SPI, HSPI
spi = SPI(1, baudrate=8000000, polarity=0, phase=0)
#
tft = TFT(spi, 2, 16, 0)
tft.initr()
tft.rgb(True)
tft.fill(TFT.BLACK)

f = open('test128x160.bmp', 'rb')
if f.read(2) == b'BM':  #header
    dummy = f.read(8)  #file size(4), creator bytes(4)
    offset = int.from_bytes(f.read(4), 'little')
    hdrsize = int.from_bytes(f.read(4), 'little')
    width = int.from_bytes(f.read(4), 'little')
    height = int.from_bytes(f.read(4), 'little')
    if int.from_bytes(f.read(2), 'little') == 1:  #planes must be 1
        depth = int.from_bytes(f.read(2), 'little')
        if depth == 24 and int.from_bytes(
                f.read(4), 'little') == 0:  #compress method == uncompressed
            print("Image size:", width, "x", height)
            rowsize = (width * 3 + 3) & ~3
            if height < 0:
                height = -height
                flip = False
            else:
                flip = True
            w, h = width, height
            if w > 128: w = 128
Beispiel #21
0
def LCD_LEDCtrl(timer):
    global Lcd_LEDCount, LCD_LEDSet
    Lcd_LEDCount = Lcd_LEDCount + 1
    if Lcd_LEDCount == 10:
        Lcd_LEDCount = 0
    if LCD_LEDSet > Lcd_LEDCount:
        lcd_led.value(0)
    else:
        lcd_led.value(1)


lcd_led_tim = pyb.Timer(2)
lcd_led_tim.init(freq=4000)  # Freq: 4KHz
lcd_led_tim.callback(LCD_LEDCtrl)
tft = TFT(spi2, dc, rst, cs)
tft.init_7735(TFT.REDTAB)
tft.rotation(2)
tft.rgb(True)


def display_weact_logo():
    tft.fill(TFT.BLACK)
    f = open('WeAct_logo_128_160.bmp', 'rb')
    if f.read(2) == b'BM':  # header
        dummy = f.read(8)  # file size(4), creator bytes(4)
        offset = int.from_bytes(f.read(4), 'little')
        hdrsize = int.from_bytes(f.read(4), 'little')
        width = int.from_bytes(f.read(4), 'little')
        height = int.from_bytes(f.read(4), 'little')
        buf = bytearray(width * 2)  # init buf
Beispiel #22
0
SPI_MOSI = 23

DC = 17  # PWM1
RST = 16  # PWM2
CS = 5  # SCE0

print("--- TFT 128x160px test ---")

spi = SPI(2,
          baudrate=20000000,
          polarity=0,
          phase=0,
          sck=Pin(SPI_SCLK),
          mosi=Pin(SPI_MOSI),
          miso=Pin(SPI_MISO))
tft = TFT(spi, DC, RST, CS)
tft.initr()
tft.rgb(True)

tft.fill(TFT.BLACK)
v = 30
tft.text((0, v), "octopus LAB (1)", TFT.RED, sysfont, 1, nowrap=True)
v += sysfont["Height"]

tft.fill(TFT.BLACK)
tft.rotation(1)

# size = 3
cursor = Point2D(63, 81)
matrix = Point2D(63 / 3, 81 / 3)
mx = {}  # set
from ST7735 import TFT
from sysfont import sysfont
from machine import SPI, Pin
import time
import math
#hardware SPI, HSPI
spi = SPI(1, baudrate=8000000, polarity=0, phase=0)

tft = TFT(spi, 16)
tft.init_7735(tft.GREENTAB128x128)


def testlines(color):
    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((0, 0), (x, tft.size()[1] - 1), color)
    for y in range(0, tft.size()[1], 6):
        tft.line((0, 0), (tft.size()[0] - 1, y), color)

    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((tft.size()[0] - 1, 0), (x, tft.size()[1] - 1), color)
    for y in range(0, tft.size()[1], 6):
        tft.line((tft.size()[0] - 1, 0), (0, y), color)

    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((0, tft.size()[1] - 1), (x, 0), color)
    for y in range(0, tft.size()[1], 6):
        tft.line((0, tft.size()[1] - 1), (tft.size()[0] - 1, y), color)
Beispiel #24
0
from ST7735 import TFT
from sysfont import sysfont
from machine import SPI,Pin
import time
import math
#hardware SPI, HSPI
spi = SPI(1, baudrate=8000000, polarity=0, phase=0)
# dc, rst, cs
tft=TFT(spi,16)
tft.init_7735(tft.GREENTAB80x160)

def testlines(color):
    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((0,0),(x, tft.size()[1] - 1), color)
    for y in range(0, tft.size()[1], 6):
        tft.line((0,0),(tft.size()[0] - 1, y), color)

    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((tft.size()[0] - 1, 0), (x, tft.size()[1] - 1), color)
    for y in range(0, tft.size()[1], 6):
        tft.line((tft.size()[0] - 1, 0), (0, y), color)

    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((0, tft.size()[1] - 1), (x, 0), color)
    for y in range(0, tft.size()[1], 6):
        tft.line((0, tft.size()[1] - 1), (tft.size()[0] - 1,y), color)

    tft.fill(TFT.BLACK)
Beispiel #25
0
from sysfont import sysfont
import machine

from machine import SPI, Pin
import time
import math
backlight = machine.Pin(15, machine.Pin.OUT)
backlight.value(0)
spi = SPI(-1,
          baudrate=70000000,
          polarity=0,
          phase=0,
          sck=Pin(18),
          mosi=Pin(23),
          miso=Pin(19))
tft = TFT(spi, 27, 33, 14)
tft.initr()
tft.rgb(True)


def testlines(color):
    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((0, 0), (x, tft.size()[1] - 1), color)
    for y in range(0, tft.size()[1], 6):
        tft.line((0, 0), (tft.size()[0] - 1, y), color)

    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((tft.size()[0] - 1, 0), (x, tft.size()[1] - 1), color)
    for y in range(0, tft.size()[1], 6):
Beispiel #26
0
class GameEngine:
    def __init__(self, screensize):
        spi = SPI(1, baudrate=20000000, polarity=0, phase=0,
                  sck=Pin(SPI_SCK), mosi=Pin(SPI_SDO), miso=None)
        # def __init__( self, spi, aDC, aReset, aCS) :
        # Pin details for SPI interface for screen
        self.tft = TFT(spi, SPI_DC, SPI_RS, SPI_CS)
        self.tft.initg()   # Change this to make screen dimensions match board i.e if you get a line around the edge driver needs rewwwok for this
        self.tft.rgb(True)
        self.tft.set_size(screensize)
        self.set_caption("Tetris")
        self.level = 2
        self.screenSize = screensize
        # Board offsets
        self.x = 4
        self.y = 10
        
        # Pin details for buttons.
        self.right_button = button(19)
        self.left_button = button(14)

    def set_caption(self, caption):
        self.tft.fill(TFT.BLACK)
        v = 30
        v += sysfont["Height"] * 2
        self.tft.text((20, v), caption, TFT.GREEN, sysfont, 2, nowrap=True)
        time.sleep_ms(1000)

    def render_text(self, aText, aColour, vPos, fSize):
        self.tft.text((8, vPos), aText, aColour, sysfont, fSize, nowrap=True)

    # Draw a grid by drawing hollow rectangles starting a smallest coordinate'''
    # Then fill the hollow retangles with colours of fallen frozen blocks '''
    # For the filled rectangle.  aStart is the smallest coordinate corner
    # and aSize is a tuple indicating width, heightalready rededuced for  the ineer block
    def draw_board(self, myTetris):
        gridLineColour = TFT.RED

        # print (' blockOuter: {0} blockInner: {1}  TWidth: {2} THeight: {3}'.format( blockOuter, blockInner, myTetris.width, myTetris.height))
      
        for i in range(0, myTetris.width):
            for j in range(0, myTetris.height):

                # Render grid
                self.tft.rect((self.x + 12 * i  , self.y + 7*j ),
                             (120//10+1, 155//20+1), gridLineColour)
             
    def render_all(self,myTetris):
        for i in range(0, myTetris.width):
            for j in range(0, myTetris.height):
                self.tft.fillrect((self.x + 12 * i +1 , self.y + 7 * j + 1),
                                    (11,5)  , (myTetris.field[j][i]))
                
        #print('\n'.join(' '.join(map(str,sl)) for sl in myTetris.field))
        
    def render_frozen(self,myTetris):
        for i in range(0, myTetris.width):
            for j in range(0, myTetris.height):
                if myTetris.field[j][i] > 0:
                    #(120//10-2, 155//20-2)
                    self.tft.fillrect((self.x + 12 * i , self.y + 7 * j),
                                  (12,7)    , (myTetris.field[j][i]))
       
       
    def hide_figure(self,figure):
        for i in range(4):
            for j in range(4):
                p = i * 4 + j        
                if p in figure.orientation():
                    blockColor = TFT.BLACK
                    fx = figure.x
                    fy = figure.y
                    self.tft.fillrect(
                                (self.x + 12 * (j + fx) + 1, self.y + 7 * (fy + i) + 1),  (120//10-2, 155//20-1),  blockColor)
   # Render the floating blocks 
    def render_figure(self, figure):
        if figure is not None:
           # print("fig or last:" + str(figure.orientation_last()))
            for i in range(4):
                for j in range(4):
                    p = i * 4 + j
                    if p in figure.orientation_last():
                        blockColor = TFT.BLACK
                        fx = figure.x_org
                        fy = figure.y_org

                        self.tft.fillrect(
                            (self.x + 12 * (j + fx) +1 , self.y + 7 * (fy + i) +1 ), (11,5) ,  blockColor)
                for i in range(4):
                    for j in range(4):
                        p = i * 4 + j        
                        if p in figure.orientation():
                            blockColor = figure.color
                            fx = figure.x 
                            fy = figure.y

                            self.tft.fillrect(
                                (self.x + 12 * (j + fx) +1, self.y + 7 * (fy + i)+1), (11,5) ,  blockColor)


    def game_end(self):
        self.tft.fill(TFT.BLACK)
        self.render_text("Game Over", TFT.ORANGE, 50, 2)
        self.render_text("PRESS ANY KEY", TFT.ORANGE, 90, 1)

    def game_score(self, ascore):
        self.render_text("Tetris Score: " + str(ascore), TFT.ORANGE, 1, 1)

    def game_quit(self):
        self.tft.fill(TFT.BLACK)
        self.render_text("Game END", TFT.ORANGE, 50, 2)
        return
Beispiel #27
0
from machine import SPI, Pin
from petme128 import petme128
import threading
import utime
import machine
from Temp_Hum import get_temp_hum
weather_data = get_temp_hum()

spi = SPI(2,
          baudrate=20000000,
          polarity=0,
          phase=0,
          sck=Pin(19),
          mosi=Pin(18),
          miso=Pin(21))
tft = TFT(spi, 5, 4, 2)
tft.initr()
tft.rgb(True)
tft.fill(TFT.BLACK)


def currt_time(callback):

    t = [
        "0" + str(i) if len(str(i)) < 2 else str(i) for i in utime.localtime()
    ]
    time = "%s:%s:%s" % ("0" + str(int(t[3]) + 8) if len(str(int(t[3]) + 8)) <
                         2 else str(int(t[3]) + 8), t[4], t[5])
    tft.text(aPos=[70, 12],
             aString=time,
             aFont=petme128,
Beispiel #28
0
from ST7735 import TFT
from sysfont import sysfont
from machine import SPI, Pin
import time
import math
spi = SPI(2,
          baudrate=20000000,
          polarity=0,
          phase=0,
          sck=Pin(14),
          mosi=Pin(13),
          miso=Pin(12))
tft = TFT(spi, 16, 17, 18)
tft.initr()
tft.rgb(True)


def testlines(color):
    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((0, 0), (x, tft.size()[1] - 1), color)
    for y in range(0, tft.size()[1], 6):
        tft.line((0, 0), (tft.size()[0] - 1, y), color)

    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((tft.size()[0] - 1, 0), (x, tft.size()[1] - 1), color)
    for y in range(0, tft.size()[1], 6):
        tft.line((tft.size()[0] - 1, 0), (0, y), color)

    tft.fill(TFT.BLACK)
from ST7735 import TFT
from sysfont import sysfont
from machine import SPI, Pin
import time
import math

spi = SPI(1,
          baudrate=20000000,
          polarity=0,
          phase=0,
          sck=Pin(10),
          mosi=Pin(11),
          miso=None)
# def __init__( self, spi, aDC, aReset, aCS) :
tft = TFT(spi, 3, 2, 4)

tft.initg()
tft.rgb(True)


def testlines(color):
    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((0, 0), (x, tft.size()[1] - 1), color)
    for y in range(0, tft.size()[1], 6):
        tft.line((0, 0), (tft.size()[0] - 1, y), color)

    tft.fill(TFT.BLACK)
    for x in range(0, tft.size()[0], 6):
        tft.line((tft.size()[0] - 1, 0), (x, tft.size()[1] - 1), color)