def initSDCard(): # uos.sdconfig(uos.SDMODE_4LINE, sdCardCLK , sdCardMOSI, sdCardMiso, sdCardCS) uos.sdconfig(uos.SDMODE_4LINE) try: uos.mountsd() except Exception as e: print(e)
def __init__(self): self.wordList = [ "それな", "そやな", "しらんがな", "まじか…", "SORENA", "SOYANA", "わかる", "うける", "はつみみ", "あー、あれね", "どゆこと?", "なるほどー", "完全に理解", "しってた", "そっちかー", "はじまったな", "そっすね", "それだ!", "ええーっ!?", "何だってー!", "株の買い時!", "最の高では?", "と、いうと?", "神!", "ふーん", "わかるわかる", "なんでや!", "ワンチャン", "ションボリ", "もう限界では", "まだいける!", "がんばるぞい" ] #self.sakuraList = ["/sd/sakura01.jpg","/sd/sakura01.jpg","/sd/sakura01.jpg","/sd/sakura01.jpg","/sd/sakura01.jpg","/sd/sakura01.jpg","/sd/sakura02.jpg"] self.sakuraList = ["/sd/nisenise01.jpg"] uos.mountsd() self.jpfontObj = jpfont() random.seed(int(time.time())) #Yahooヘッドライン取得(XML) self.maxCategoty = YahooHeadline.getCategoryCount() self.nowCategory = 4 self.titleTextList = YahooHeadline.getYahooHeadline(self.nowCategory) self.nowTitleIndex = 0 #最大 13x8 lcd.clear() lcd.image(0, 0, random.choice(self.sakuraList)) lcd.setCursor(0, 0) lcd.setColor(lcd.BLACK) self.nextNews() buttonA.wasPressed(self.on_AwasPressed) buttonB.wasPressed(self.on_BwasPressed) buttonC.wasPressed(self.on_CwasPressed) self.autoNewsCount = 0 self.autoNews()
def __init__(self): lcd.clear() uos.mountsd() self.jpfontSmaponObj = jpfontSmapon() random.seed(int(time.time())) #Yahooヘッドライン取得(XML) self.maxCategoty = YahooHeadline.getCategoryCount() self.nowCategory = 4 self.titleTextList = YahooHeadline.getYahooHeadline(self.nowCategory) self.nowTitleIndex = 0 lcd.setCursor(0, 0) lcd.setColor(lcd.BLACK) self.nextNews() self.autoNewsCount = 0 self.autoNews()
def fileCheck(self): try: uos.stat('/sd') lcd.println('SD card has already been mounted.') except: try: uos.mountsd() lcd.println('SD card is mounted.') except: lcd.println('No SD card is found.') return -1 try: sdFiles = uos.listdir('/sd') if self.DNAME_ROOT not in sdFiles: uos.mkdir('/sd/' + self.DNAME_ROOT) lcd.println('mkdir /sd/%s/' % self.DNAME_ROOT) except: lcd.println('The SD card is not writable.') return -2 return 0
def mountsd(addlib=True): #use SDCard # SDCard configuration for M5Stack try: #crude way to detect if the sd is already loaded _ = os.stat('/sd') except: #if _ = os.sdconfig(os.SDMODE_SPI, clk=18, mosi=23, miso=19, cs=4) _ = os.mountsd() if addlib: #very simple , just try to create and add the /sd/lib folder to the path #create Library for modules on the sd card try: os.mkdir('/sd/lib') except: pass #if exist sys.path.append('/sd/lib')
def mount_sd(): uos.sdconfig(uos.SDMODE_SPI,clk=18,mosi=23,miso=19,cs=4, maxspeed=16) try: uos.mountsd() except: pass
# Init GPS lcd.print('UART:Initializing\n', 0, 0) gps_s = UART(2, tx=17, rx=16, baudrate=9600, timeout=200, buffer_size=256, lineend='\r\n') # micropyGPS.MicropyGPS.supported_sentences.update({'GNGSA': micropyGPS.MicropyGPS.gpgsa}) gps = micropyGPS.MicropyGPS(9, 'dd') lcd.print('UART:Initialized\n') # Init RTC lcd.print('RTC:Initializing\n') rtc = RTC() rtc.ntp_sync(server='hr.pool.ntp.org', tz='CET-1CEST') lcd.print('RTC:Initialize status %s\n' % rtc.synced()) # Mount SD result = uos.mountsd() lcd.print('SDCard:Mount result %s\n' % result) lcd.print('SDCard:listdir %s\n' % uos.listdir('/sd')) def watchGPS(): lcd.print('GPS:Start loop\n') n = 0 tm_last = 0 satellites = dict() satellites_used = dict() fp = open('/sd/gpslog.txt', 'a') lcd.print('fp %s\n' % fp)
# This file is executed on every boot (including wake-boot from deepsleep) import sys sys.path[1] = '/flash/lib' import uos uos.sdconfig(uos.SDMODE_SPI, clk=14, mosi=17, miso=2, cs=13) uos.mountsd(True) import blink blink.poo()
#print( face['faceAttributes']['age'] ) print( "with {} hair, {} and {}".format( face['faceAttributes']['hair']['hairColor'][0]['color'], #main haircolor ", ".join( face['faceAttributes']['facialHair'] ), face['faceAttributes']['glasses'] )) emotion = face['faceAttributes']['emotion'] print ( sorted(emotion, key=emotion.__getitem__)[:1] ) # In order of sorted values: [1, 2, 3, 4] #Demo from /flash/foto if True: for fname in os.listdir('/flash/foto'): print('---------------------------------------------------------------') print( "Foto : /flash/foto/{}".format(fname) ) faces = detect_faces_binary( "/flash/foto/{}".format(fname)) process_faces(faces) print('---------------------------------------------------------------') #demo from /sd/foto if False: os.sdconfig(os.SDMODE_SPI, clk=18, mosi=23, miso=19, cs=4) os.mountsd() for fname in os.listdir('/sd/foto2'): print('---------------------------------------------------------------') print( "Foto : /sd/foto/{}".format(fname) ) faces = detect_faces_binary( "/sd/foto/{}".format(fname) ) process_faces(faces) print('---------------------------------------------------------------')
def mount_sd(): uos.sdconfig(uos.SDMODE_SPI, clk=18, mosi=23, miso=19, cs=4) uos.mountsd()
def spi16(): uos.sdconfig(uos.SDMODE_SPI, clk=14, mosi=15, miso=2, cs=13, maxspeed=16) uos.mountsd()
def l4_40(): uos.sdconfig(uos.SDMODE_4LINE, maxspeed=40) uos.mountsd()
def l4_16(): uos.sdconfig(uos.SDMODE_4LINE, maxspeed=16) uos.mountsd()
def l4_8(): uos.sdconfig(uos.SDMODE_4LINE, maxspeed=8) uos.mountsd()
def main(): ########## 初期化 ########## # 液晶画面を初期化する lcd.setColor(color, background_color) lcd.clear() # センサーを初期化する sensor = DHT12() # 温度計、湿度計の表示を初期化する temperature_view = ThermometerView(10, 10, min_value=-15, max_value=45) humidity_view = ThermometerView(80, 10, min_value=0, max_value=100, color=lcd.BLUE, label='%') # SDカードのマウント uos.mountsd() # 背景の描画 temperature_view.init() humidity_view.init() ########## 無限ループ ########## while not buttonC.isPressed(): # センサーで温度と湿度を計測する sensor.measure() temperature = sensor.temperature() humidity = sensor.humidity() # デバッグ用 print("Temperature: {} `C, Humidity: {} %".format( temperature, humidity)) # 温度計、湿度計の表示を更新する temperature_view.update(temperature) humidity_view.update(humidity) # WBGT値を求める try: wbgt = calc_wbgt(temperature, humidity) except ValueError: wbgt = None # WBGT値を画面に表示する lcd.font(lcd.FONT_Default, color=color, transparent=False) lcd.textClear(160, 30, 'WBGT: Unknown') if wbgt is not None: lcd.text(160, 30, 'WBGT: {}'.format(wbgt)) else: lcd.text(160, 30, 'WBGT: Unknown') image_path = None # WBGT値に応じて画像を描画する # 31度以上 : 危険 # 28度以上31度未満 : 厳重警戒 # 25度以上28度未満 : 警戒 # 25度未満 : 注意 if temperature >= 21 and wbgt is not None: if wbgt >= 31: # 危険 image_path = image_path_kiken elif wbgt >= 28: # 厳重警戒 image_path = image_path_genjukeikai elif wbgt >= 25: # 警戒 image_path = image_path_keikai # 湿度に応じてインフルエンザ注意情報を表示する # 湿度40%未満 : インフルエンザ感染注意 if humidity < 40: image_path = image_path_influenza if image_path is not None: # 画像を描画する lcd.image(image_x, image_y, image_path) else: # 画像を描画した領域を背景色で塗りつぶす lcd.rect(image_x, image_y, image_width, image_height, background_color, background_color) # 表示の更新間隔 utime.sleep(interval)
def main(): import time import uos from m5stack import lcd, buttonA, buttonB, buttonC import network import binascii DNAME_ROOT = 'wifi_analyzer' def drawNaviButton(strA='START', strB='STOP', strC='EXIT'): lcd.text(40, 215, strA, lcd.WHITE) lcd.text(135, 215, strB, lcd.WHITE) lcd.text(240, 215, strC, lcd.WHITE) def fnameGen(): currentFileList = list( filter(lambda x: 'WA_' in x, uos.listdir('/sd/' + DNAME_ROOT))) currentFileList = list(map(lambda x: x.lower(), currentFileList)) if 'wa_0001.csv' not in currentFileList: return 'WA_0001.csv' else: currentFileList.sort() newestFileName = currentFileList[-1] no = int(newestFileName[3:7]) return 'WA_%s.csv' % (('%4d' % (no + 1)).replace(' ', '0')) def resdisplay(apresults, n, time): lcd.rect(0, 0, 320, 24, lcd.BLUE, lcd.BLUE) lcd.font(lcd.FONT_Ubuntu, transparent=True) lcd.text(0, 2, 'N_AP:%d N_SCAN:%d TIME:%d' % (len(apresults), n, time), lcd.WHITE) lcd.rect(0, 24, 320, 186, lcd.BLACK, lcd.BLACK) lcd.setCursor(0, 24) lcd.font(lcd.FONT_DefaultSmall) if len(apresults) < 15: i = 0 for apresult in apresults: resstr = '%02d, ch: %02d, rs: %d, %s\n' % ( i + 1, apresult[2], apresult[3], apresult[0].decode()) lcd.print(resstr, color=lcd.WHITE) i = i + 1 else: for i in range(0, 15): apresult = apresults[i] resstr = '%02d, ch: %02d, rs: %d, %s\n' % ( i + 1, apresult[2], apresult[3], apresult[0].decode()) lcd.print(resstr, color=lcd.WHITE) try: uos.stat('/sd') except: try: uos.mountsd() except: lcd.println('No SD card is found.') return -1 try: sdFiles = uos.listdir('/sd') if DNAME_ROOT not in sdFiles: uos.mkdir('/sd/' + DNAME_ROOT) except: lcd.println('The SD card is not writable.') return -2 try: drawNaviButton() lcd.setCursor(0, 0) lcd.println('Press START to start') while not buttonA.isPressed(): time.sleep(.5) if buttonC.isPressed(): return 0 wlan = network.WLAN(network.STA_IF) wlan.active(True) fname = fnameGen() lcd.println('Recording into %s...' % fname) ts = time.time() n = 0 while not buttonB.isPressed(): buf = '' aps = wlan.scan() n += 1 te = time.time() - ts for ap in aps: # (ssid, bssid, primary_chan, rssi, auth_mode, auth_mode_string, hidden) mac = (binascii.hexlify(ap[1])).decode() mac = ':'.join([ mac[:2], mac[2:4], mac[4:6], mac[6:8], mac[8:10], mac[10:12] ]) buf += '%.3f,%s,%s,%d,%s\n' % (te, mac, ap[0].decode(), ap[3], ap[2]) print(buf + '---------------------') resdisplay(aps, n, int(te)) with open('/sd/' + DNAME_ROOT + '/' + fname, 'a') as o: o.write(buf) lcd.println('Exit.') except: print('Exit since error.') pass
if 'demo' in dir(): import machine print("Please reset MCU to avoid init the display in 2 different contexts") machine.reset() #Assumes a SD card is inserted from upysh import * import uos as os _ = os.sdconfig(os.SDMODE_SPI, clk=18, mosi=23, miso=19, cs=4) _ = os.mountsd() cp("/flash/fred.jpg", "/sd/fred.jpg") import time from pause import * from upysh import * import windows tft = windows.tft pause('Show Screen Size') tft.resetwin() tft.clear(tft.BLACK) #get the screensize screen_w, screen_h = tft.screensize() tft.text(120, int(screen_h / 2), "{} by {}".format(*tft.screensize()), color=tft.RED) time.sleep(0.5)
def sysInit(): try: uos.mountsd() except: lcd.print('Cannot mount SD card!')
gps = GPS(uart) gps.startservice() if BME_present: i2c1 = I2C(id=1, scl=Pin(I2C1_PIN_SCL), sda=Pin(I2C1_PIN_SDA), speed=400000) bme = bme280.BME280(i2c=i2c1) else: print("No BMx280 sensor") uos.sdconfig(uos.SDMODE_1LINE) SD_present = True try: uos.mountsd() except OSError as e: if e.args[0] == errno.EIO: SD_present = False pass DefaultSettings = True if SD_present: DefaultSettings = False settings_file = SDFolder + '/' + SETTINGS try: uos.stat(settings_file) except OSError as e: if e.args[0] == errno.ENOENT: DefaultSettings = True pass
def main(): print( ' __ __ ___ _______ ______ _______ _______ __ __ _______ _______ ' ) print( '| |_| || | | || _ | | || || | | || || |' ) print( '| || | | || | || | _ || _ || |_| || _ || _____|' ) print( '| || | | || |_||_ | | | || |_| || || | | || |_____ ' ) print( '| || | | _|| __ || |_| || ___||_ _|| |_| ||_____ |' ) print( '| ||_|| || | | |_ | | | || || | | | | | _____| |' ) print( '|_| |_||___| |_______||___| |_||_______||___| |___| |_______||_______|' ) print('small OS for micropython ver ' + version + ' by theCodeman') print('https://github.com/TheCodeman/myos') print('MicroPython Version : {} Platform : {}'.format( sys.version, sys.platform)) timer.init(period=1000, mode=machine.Timer.PERIODIC, callback=intCallback) while True: str = input(uos.getcwd() + '>') cmd = str.split() # print(cmd) if len(str) != 0: if cmd[0] == 'cd': try: uos.chdir(cmd[1]) except: print('bad dir') elif cmd[0] == 'ls': print('Current Directory ', uos.getcwd()) total = 0 #F 1366 lora.py print('Type Size Filename') print('----------------------------------') if len(cmd) == 2: path = cmd[1] else: path = uos.getcwd() try: for l in uos.ilistdir(path): if l[1] & 0x4000: print('D{0:>31}'.format(l[0])) else: # F 3360 myos.py total += int(uos.stat(l[0])[6]) print('F {0:<8}{1:>16}'.format( uos.stat(l[0])[6], l[0])) print('----------------------------------') print('File Size Total: {0}'.format(total)) except Exception as e: print(e) elif cmd[0] == 'cp': if len(cmd) == 3: try: with open(cmd[1], 'rb') as source: print('Source {0}'.format(cmd[1])) data = source.read() source.close() except Exception as e: print(e) try: with open(cmd[2], 'wb') as dest: print('Dest {0}'.format(cmd[2])) dest.write(data) dest.close() except Exception as e: print(e) else: print( 'cp requires source filename and destination filename ' ) elif cmd[0] == 'run': if len(cmd) == 2: __import__(cmd[1]) del sys.modules[cmd[1]] else: print('Need File Name') elif cmd[0] == 'lr': if networkUp: if len(cmd) == 1: res = ssh.list(settings.remoteIP + settings.remotePath, settings.uname, settings.upass) else: res = ssh.list( settings.remoteIP + settings.remotePath + cmd[1], settings.uname, settings.upass) print(res[0]) if res[0] == 0: print(res[1]) print(res[2]) else: print('No Network Connection') elif cmd[0] == 'put': if networkUp: res = ssh.put(settings.remoteIP + settings.remotePath + cmd[1], settings.uname, settings.upass, file=cmd[1]) if res[0] == 0: print('File %s copied to %s' % (cmd[1], settings.remotePath)) else: print('No Network Connection') elif cmd[0] == 'get': if networkUp: res = ssh.get(settings.remoteIP + settings.remotePath + cmd[1], settings.uname, settings.upass, file='$$$.tmp') if res[0] == 0: try: uos.remove(cmd[1]) except: pass uos.rename('$$$.tmp', cmd[1]) print('File %s copied from %s' % (cmd[1], settings.remotePath)) else: uos.remove('$$$.tmp') print('File Not Found') else: print('No Network Connection') elif cmd[0] == 'edit': pye(cmd[1]) elif cmd[0] == 'rm': try: uos.remove(cmd[1]) except: print('no file') elif cmd[0] == 'md': try: uos.mkdir(cmd[1]) except: print("Need Directory Name") elif cmd[0] == 'rmdir': try: uos.rmdir(cmd[1]) except: print("Need Directory Name") elif cmd[0] == 'reset': machine.reset() elif cmd[0] == 'cat': line = 0 try: f = open(cmd[1], 'r') while True: str = f.readline() if str == "": break print(str, end="") line += 1 if line > 25: print( '----- press space to continue or q to quit -----', end="") ret = getch() print( '\r \r', end="") if ret == 'q': break else: line = 0 f.close() except: print('no file') elif cmd[0] == 'time': print('Time set to: {}'.format( utime.strftime('%c', utime.localtime()))) elif cmd[0] == 'df': if len(cmd) == 1: fs_stat = uos.statvfs(uos.getcwd()) else: fs_stat = uos.statvfs(cmd[1]) fs_size = fs_stat[0] * fs_stat[2] fs_free = fs_stat[0] * fs_stat[3] print('File System Size {:,} - Free Space {:,}'.format( fs_size, fs_free)) elif cmd[0] == 'wget': if networkUp: try: response = urequests.get(cmd[1]) if response.status_code == 200: print(type(response)) print(response.text) print(type(response.text)) fileName = cmd[1].split('/') print(fileName) print(fileName[-1]) f = open(fileName[-1], 'w') f.write(response.text) f.close() else: print('Error: {0} {1}'.format( response.status_code, response.reason.decode('utf-8'))) except Exception as e: print(e) else: print('No Network Connection') elif cmd[0] == 'wifi': try: if cmd[1] == 'active': nic.active(True) if cmd[1] == 'deactive': nic.active(False) if cmd[1] == 'config': status = nic.ifconfig() print( 'IP: {0}\n\rSubnet: {1}\r\nGateway: {2}\r\nDNS: {3}' .format(status[0], status[1], status[2], status[3])) if cmd[1] == 'isconnected': print(nic.isconnected()) if cmd[1] == 'connect': try: nic.connect(cmd[2], cmd[3]) except Exception as e: print(e) if cmd[1] == 'scan': stations = nic.scan() for s in stations: if s[4] == 0: authmode = 'Open' if s[4] == 1: authmode = 'Wep' if s[4] == 2: authmode = 'WPA-PSK' if s[4] == 3: authmode = 'WPA2-PSK' if s[4] == 4: authmode = 'WPA/WPA2-PSK' print( 'SSID: {0:<32} Channel: {1} RSSSI: {2} Auth Type: {3}' .format(s[0].decode('utf-8'), s[2], s[3], authmode)) except Exception as e: print(e) print(' no action') elif cmd[0] == 'umountsd': try: uos.umountsd() except Exception as e: print(e) elif cmd[0] == 'mountsd': try: uos.mountsd() except Exception as e: print(e) elif cmd[0] == 'help': print('Command List') print('----------------------------------') print('ls - list files current directory') print( 'lr - list files on remote server optional directory') print('cat - display file') print('rm - remove file') print('df - display drive space') print('time - display time and date') print('get - scp from server') print('put - scp to server') print('md - make directory') print('rmdir - remove directory') print('run - run python script') print('edit - edit file using pye') print('modules - list installed modules') print('reset - reset board') print('wget - get file over http and save to file') print('----------------------------------') elif cmd[0] == 'exit': timer.deinit() return 1 elif cmd[0] == 'update': if networkUp: res = ssh.get(settings.remoteIP + settings.remotePath + 'micropyos.py', settings.uname, settings.upass, file='$$$.tmp') if res[0] == 0: try: uos.remove('micropyos.py') except: pass uos.rename('$$$.tmp', 'micropyos.py') print('File %s copied from %s' % ('micropyos.py', settings.remotePath)) else: uos.remove('$$$.tmp') print('File Not Found') timer.deinit() return 2 else: print('No Network Connection') elif cmd[0] == 'modules': for m in sys.modules: print(m) elif cmd[0] == 'settings': pye('settings.py') else: print('unknown command')