value = min(max(input_min, value), input_max)
    value_deal = (value - input_min) * (aims_max - aims_min) / (
        input_max - input_min) + aims_min
    return round(value_deal, 2)


# ------------------ M5Stack -------------------
# Node ID
node_id = ubinascii.hexlify(machine.unique_id()).decode('utf-8')
print('\nDevice ID:' + node_id)
print('LCD initializing...', end='')

# pin Analog and digital

# LCD
lcd = lcd.TFT()
lcd.init(lcd.M5STACK,
         width=240,
         height=320,
         speed=40000000,
         rst_pin=33,
         miso=19,
         mosi=23,
         clk=18,
         cs=14,
         dc=27,
         bgr=True,
         invrot=3,
         expwm=machine.PWM(32, duty=0, timer=1))
lcd.setBrightness(30)
lcd.clear()
"""
Demo program demonstrating the capabities of the MicroPython display module
Author:	LoBo (https://github/loboris)
Date:	08/10/2017

"""

import machine, display, time, math

tft = display.TFT()

#ESP32-WROVER-KIT v3:
#tft.init(tft.ST7789, rst_pin=18, backl_pin=5, miso=25, mosi=23, clk=19, cs=22, dc=21)

#Adafruit:
tft.init(tft.ILI9341, width=240, height=320, miso=19, mosi=18, clk=5, cs=15, dc=33, bgr=True, hastouch=tft.TOUCH_STMPE, tcs=32)

#Set correct configuration
#tft.init(tft.ILI9341, width=240, height=320, miso=19,mosi=23,clk=18,cs=5,dc=26,tcs=27,hastouch=True, bgr=True)
#tft.init(tft.ST7735R, speed=10000000, spihost=tft.HSPI, mosi=13, miso=12, clk=14, cs=15, dc=27, rst_pin=26, hastouch=False, bgr=False, width=128, height=160)


def testt():
    while True:
        lastx = 0
        lasty = 0
        t,x,y = tft.gettouch()
        if t:
            dx = abs(x-lastx)
            dy = abs(y-lasty)
            if (dx > 2) and (dy > 2):
    def __init__(self):
        # True =  SPI display, False = I2C display

        self.ESP32 = True
        self.useSPI = True
        self.displayTimer = ticks_ms()
        self.vol = int(self.max_vol)
        seed(ticks_us())
        self.btnU = 1 << 1
        self.btnL = 1 << 2
        self.btnR = 1 << 3
        self.btnD = 1 << 4
        self.btnA = 1 << 5
        self.btnB = 1 << 6
        self.btnMenu = 1 << 7
        self.btnVol = 1 << 8
        self.btnSel = 1 << 9
        self.btnSt = 1 << 10

        self.btnUval = 0
        self.btnDval = 0
        self.btnLval = 0
        self.btnRval = 0
        self.btnAval = 0
        self.btnBval = 0
        self.btnMenuval = 0
        self.btnVolval = 0
        self.btnSelval = 0
        self.btnStval = 0
        self.frameRate = 30
        self.maxBgm = 1
        self.bgm = 1
        self.songIndex = 0
        self.songStart = -1
        self.songEnd = -2
        self.songLoop = -3
        self.silence = 0
        self.songSpeed = 1
        self.timeunit = 1
        self.notes = False
        self.songBuf = []
        self.Btns = 0
        self.lastBtns = 0

        self.dac_pin = Pin(25, Pin.OUT, value=1)  # switch speaker on
        self.PinBuzzer = Pin(26, Pin.OUT)
        self.beeper = PWM(self.PinBuzzer, 500, duty=0)
        self.beeper2 = PWM(self.PinBuzzer, 500, duty=0)
        self.timerInitialized = False
        self.tft = display.TFT()
        self.tft.init(self.tft.ILI9341,
                      width=240,
                      height=320,
                      speed=40000000,
                      backl_pin=14,
                      backl_on=1,
                      miso=19,
                      mosi=23,
                      clk=18,
                      cs=5,
                      dc=21,
                      hastouch=False)
        self.tft.clear(self.tft.BLACK)
        self.tft.orient(self.tft.LANDSCAPE_FLIP)
        self.screenW, self.screenH = self.tft.screensize()
        ''' fonts available in ili9341
        tft.FONT_Small, 8x12
        tft.FONT_Default, 13x13
        tft.FONT_7seg, 18x31
        tft.FONT_Ubuntu, 15x16
        tft.FONT_Comic, 25x28
        tft.FONT_Tooney, 32x37
        tft.FONT_Minya, 20x24
        '''
        self.tft.font(self.tft.FONT_Ubuntu, rotate=0)

        self.PinBtnA = Pin(BUTTON_A_PIN, Pin.IN, Pin.PULL_UP)
        self.PinBtnB = Pin(BUTTON_B_PIN, Pin.IN, Pin.PULL_UP)
        self.PinBtnMenu = Pin(BUTTON_MENU_PIN, Pin.IN, Pin.PULL_UP)
        self.PinBtnVol = Pin(BUTTON_VOLUME_PIN, Pin.IN, Pin.PULL_UP)
        self.PinBtnSel = Pin(BUTTON_SELECT_PIN, Pin.IN, Pin.PULL_UP)
        self.PinBtnSt = Pin(BUTTON_START_PIN, Pin.IN)

        self.adcX = ADC(BUTTON_JOY_X_PIN)
        self.adcY = ADC(BUTTON_JOY_Y_PIN)
        #self.adc = ADC(PADDLE_PIN)
        self.adcX.atten(ADC.ATTN_11DB)
        self.adcY.atten(ADC.ATTN_11DB)
Esempio n. 4
0
def main():
    # 创建lcd display对象
    global disp
    disp = display.TFT()
    disp.font(disp.FONT_Default)

    # 连接网络
    connect_wifi(SSID, PWD)

    # 初始化摄像头, UART Rx PIN=33, TX PIN=32,M5STACK-CORE2上对应PORTA
    ucamera.init('uart', 33, 32)

    # 创建AI对象
    ai = uai.AI(uai.AI_ENGINE_ALIYUN, ACCESS_KEY, ACCESS_SECRET)

    while True:
        # 抓取一帧图像
        frame = ucamera.capture()
        if (frame != None):
            # 显示图像
            disp.image(0, 0, frame, 0)
            # 设置显示字体
            disp.font(disp.FONT_DejaVu18)
            # 显示文字
            disp.text(10, 30, 'Recognizing face...', disp.WHITE)
            # 上传图片到OSS
            image = oss.uploadContent(ACCESS_KEY, ACCESS_SECRET, OSS_ENDPOINT,
                                      OSS_BUCKET, frame, "oss/test.jpg")
            print('content: %s' % image)
            if image != None:
                # 抓取一帧图像
                frame = ucamera.capture()
                # 显示图像
                disp.image(0, 0, frame, 0)
                # 显示文字
                disp.text(10, 30, 'Detecting Pedestrian...', disp.WHITE)
                # 人体检测
                resp = ai.detectPedestrian(image)
                print(resp)
                if (resp != None):
                    i = 0
                    # 解析识别结果
                    while (i < len(resp)):
                        type = resp[i]['type']
                        score = resp[i]['score']
                        x = resp[i]['x']
                        y = resp[i]['y']
                        w = resp[i]['w']
                        h = resp[i]['h']
                        # 当得分 > 0.6,表示识别成功
                        if score > 0.6:
                            # 清除屏幕内容
                            disp.clear()
                            # 设置文字字体
                            disp.font(disp.FONT_DejaVu40)
                            # 显示识别结果
                            disp.text(30, 90, 'Pedestrian', disp.RED)
                            disp.text(30, 130, 'Detected!!!', disp.RED)
                            print('Pedestrian Detected!!!')
                            utime.sleep(2)
                        i += 1
            # 释放当前帧内容
            del frame
Esempio n. 5
0
    def __init__(self,
                 solar_topic,
                 grid_topic,
                 mqtt_broker,
                 wifi_credentials,
                 graph_interval_s=60,
                 update_interval_ms=1000):
        self._solar_topic = solar_topic
        self._grid_topic = grid_topic
        self._mqtt_broker = mqtt_broker
        self._wifi_credentials = wifi_credentials
        self._graph_interval = graph_interval_s
        self._update_interval = update_interval_ms
        self._graph_window = Monitor._shorten(self._graph_interval * 320)

        self._tft = None
        self._wlan = None
        self._mqtt = None

        self._battery = IP5306(I2C(scl=Pin(22), sda=Pin(21)))
        self._timer = Timer(0)
        self._rtc = RTC()
        self._button_a = ButtonA(callback=self._button_a_pressed)
        self._button_c = ButtonC(callback=self._button_c_pressed)

        self._solar = None
        self._usage = None
        self._grid = None
        self._importing = None
        self._prev_importing = None
        self._solar_avg_buffer = []
        self._grid_avg_buffer = []
        self._usage_buffer = []
        self._solar_buffer = []
        self._last_update = (0, 0, 0, 0, 0, 0)
        self._data_counter = 0
        self._buffer_updated = False
        self._realtime_updated = False
        self._last_value_added = None
        self._menu_horizontal_pointer = 0
        self._blank_menu = False

        self._log('Initializing TFT...')
        self._tft = display.TFT()
        self._tft.init(self._tft.M5STACK,
                       width=240,
                       height=320,
                       rst_pin=33,
                       backl_pin=32,
                       miso=19,
                       mosi=23,
                       clk=18,
                       cs=14,
                       dc=27,
                       bgr=True,
                       backl_on=1)
        self._tft.tft_writecmd(0x21)  # Invert colors
        self._tft.clear()
        self._tft.font(self._tft.FONT_Default)
        self._tft.text(0, 0, 'USAGE', self._tft.DARKGREY)
        self._tft.text(self._tft.CENTER, 0, 'IMPORTING', self._tft.DARKGREY)
        self._tft.text(self._tft.RIGHT, 0, 'SOLAR', self._tft.DARKGREY)
        self._tft.text(0, 14, 'Loading...', self._tft.DARKGREY)
        self._log('Initializing TFT... Done')
Esempio n. 6
0
def main():
    # 创建lcd display对象
    global disp
    disp = display.TFT()
    disp.font(disp.FONT_Default)

    # 连接网络
    connect_wifi(SSID, PWD)

    # 初始化摄像头, UART Rx PIN=33, TX PIN=32,M5STACK-CORE2上对应PORTA
    ucamera.init('uart', 33, 32)

    # 创建AI对象
    ai = uai.AI(uai.AI_ENGINE_ALIYUN, ACCESS_KEY, ACCESS_SECRET)

    while True:
        # 抓取一帧图像
        frame = ucamera.capture()
        if (frame != None):
            # 显示图像
            disp.image(0, 0, frame, 0)
            # 设置显示字体
            disp.font(disp.FONT_DejaVu18)
            # 显示文字
            disp.text(10, 30, 'Recognizing face...', disp.WHITE)
            # 上传图片到OSS
            image = oss.uploadContent(ACCESS_KEY, ACCESS_SECRET, OSS_ENDPOINT,
                                      OSS_BUCKET, frame, "oss/test.jpg")
            print('content: %s' % image)
            #image = 'http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/DetectFruits/DetectFruits1.jpg'
            if image != None:
                frame = ucamera.capture()
                disp.image(0, 0, frame, 0)
                disp.text(10, 30, 'Detecting Fruits...', disp.WHITE)
                # 水果识别
                resp = ai.detectFruits(image)
                print(resp)
                if (resp != None):
                    i = 0
                    # 解析识别结果
                    while (i < len(resp)):
                        name = resp[i]['name']
                        score = resp[i]['score']
                        x = resp[i]['x']
                        y = resp[i]['y']
                        w = resp[i]['w']
                        h = resp[i]['h']
                        # 当得分 > 0.6,表示识别成功
                        if score > 0.6:
                            name = translateName(name)
                            # 清除屏幕内容
                            disp.clear()
                            # 设置文字字体
                            disp.font(disp.FONT_DejaVu40)
                            # 显示识别结果
                            disp.text(40, 80, name, disp.RED)
                            disp.text(40, 120, 'Deteted!!!', disp.RED)
                            utime.sleep(2)
                        i += 1
            # 释放当前帧内存
            del frame
Esempio n. 7
0
import sys
from collections import OrderedDict

import display
import machine
import network
from machine import Pin
from micropython import const
from utime import sleep_ms

machine.freq(240000000)

TFT = display.TFT()
# 320 * 240, but in reality x goes from 40 to 279 and y goes from 53 to 187 -> 239 * 134 --> 1.78 ratio instead of 1.33
# --> 240 * 135
TFT.init(
    TFT.ST7789,
    rot=TFT.LANDSCAPE_FLIP,
    miso=17,
    backl_pin=4,
    backl_on=1,
    mosi=19,
    clk=18,
    cs=5,
    dc=16,
    splash=False,
)
TFT.tft_writecmd(0x21)
TFT.setwin(39, 52, 279, 187)  # 240 * 135
TFT.savewin()
WINDOW_SIZE = TFT.winsize()
Esempio n. 8
0
def main():
    # 创建lcd display对象
    global disp
    disp = display.TFT()
    disp.font(disp.FONT_Default)

    # 连接网络
    connect_wifi(SSID, PWD)

    # 初始化摄像头, UART Rx PIN=33, TX PIN=32,M5STACK-CORE2上对应PORTA
    ucamera.init('uart', 33, 32)

    # 创建AI对象
    ai = uai.AI(uai.AI_ENGINE_ALIYUN, ACCESS_KEY, ACCESS_SECRET)

    while True:
        # 抓取一帧图像
        frame = ucamera.capture()
        if (frame != None):
            # 显示图像
            disp.image(0, 0, frame, 0)
            # 设置显示字体
            disp.font(disp.FONT_DejaVu18)
            # 显示文字
            disp.text(10, 30, 'Recognizing face...', disp.WHITE)
            # 上传图片到OSS
            image = oss.uploadContent(ACCESS_KEY, ACCESS_SECRET, OSS_ENDPOINT, OSS_BUCKET, frame, "oss/test.jpg")
            print('content: %s' %image)
            #image = 'http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/DetectFruits/DetectFruits1.jpg'
            if image != None:
                frame = ucamera.capture()
                disp.image(0, 0, frame, 0)
                disp.text(0, 30, 'Recognizing License Plate...', disp.WHITE)
                # 车牌识别
                resp = ai.recognizeLicensePlate(image)
                print(resp)
                if (resp != None):
                    i = 0
                    # 解析识别结果
                    while (i < len(resp)):
                        plateNumber = resp[i]['plateNumber']
                        plateType = resp[i]['plateType']
                        confidence = resp[i]['confidence']
                        plateTypeConfidence = resp[i]['plateTypeConfidence']
                        x = resp[i]['x']
                        y = resp[i]['y']
                        w = resp[i]['w']
                        h = resp[i]['h']
                        # 当置信度 > 0.6,表示识别成功
                        if confidence > 0.6:
                            # 清除屏幕内容
                            disp.clear()
                            # 设置文字字体
                            disp.font(disp.FONT_DejaVu40)
                            # 显示识别的车牌号
                            disp.text(25, 90, plateNumber, disp.RED)
                            disp.text(25, 130, 'Deteted!!!', disp.RED)
                            utime.sleep(2)
                        else:
                            print('Recognizing license plate...')
                        i += 1
                else:
                    print('Recognizing license plate...')
            # 释放当前帧内存
            del frame
Esempio n. 9
0
def main():
    # If you want to turn off the display,
    # simply run the tft.init again with backl_on=0
    tft = display.TFT()
    tft.init(
        tft.ST7789,
        bgr=False,
        rot=tft.LANDSCAPE,
        miso=17,
        backl_pin=4,
        backl_on=1,
        mosi=19,
        clk=18,
        cs=5,
        dc=16,
    )

    # corrections des erreurs de loboris micropython
    tft.tft_writecmd(0x21)  # correct the colors
    tft.setwin(40, 52, 279,
               186)  # adjust the size of the windows for the display 135x240
    # get the real size of the tft
    tft_width, tft_height = tft.winsize()
    # draw a rectangle
    margin = 0
    tft.rect(margin, margin, tft_width - margin, tft_height - margin, tft.RED)

    txt = "ESP32 with Micropython!\n"
    tft.text(
        int(tft_width / 2) - int(tft.textWidth(txt) / 2),
        int(tft_height / 4) - int(tft.fontSize()[1] / 2),
        txt,
        0xFFFFFF,
    )
    time.sleep(3)

    tft.clear()
    tft.font(tft.FONT_Comic)

    txt_height = int(tft.fontSize()[1])
    top_pos = int(txt_height / 2)

    # displax text for sensors
    temp = get_temp_lobo()
    nbre_sensors = str(len(temp))
    # read the temperatures
    k = 0
    while True:
        tft.clear()
        txt = nbre_sensors + ' ds18b20 actif(s)'
        tft.text(0, top_pos + txt_height * 0 - int(tft.fontSize()[1] / 2), txt,
                 0xFFFFFF)
        txt = 'passe : ' + str(k)
        tft.text(0, top_pos + txt_height * 1 - int(tft.fontSize()[1] / 2), txt,
                 0xFFFFFF)
        k += 1
        temp = get_temp_lobo()

        for i, t in enumerate(temp):
            sensor_id = t[0][:5] + '..' + t[0][-4:] + ' ='
            sensor_val = t[1]
            txt = sensor_id + ' ' + sensor_val
            tft.text(
                0, top_pos + txt_height * (i + 2) - int(tft.fontSize()[1] / 2),
                txt, 0xFFFFFF)
            print(txt)
        print()

        time.sleep(60)