Example #1
0
 def __init__(self):
     import machine
     self.disconnectWLAN()
     self.original_term = os.dupterm()
     os.dupterm(None) # disconnect the current serial port connection
     self.serial = machine.UART(0, 115200)
     self.poll = select.poll()
     self.poll.register(self.serial, select.POLLIN)
     self.write = self.serial.write
Example #2
0
  Add a Terminal widget, bind it to Virtual Pin V5.
  Run the App (green triangle in the upper right corner).

Don't forget to change WIFI_SSID, WIFI_AUTH and BLYNK_AUTH ;)
"""

import BlynkLib
from network import WLAN
import os

WIFI_SSID  = 'YOUR_WIFI'
WIFI_AUTH  = (WLAN.WPA2,'YOUR_PASS')
BLYNK_AUTH = 'YOUR_AUTH_TOKEN'

# connect to WiFi
wifi = WLAN(mode=WLAN.STA)
wifi.connect(WIFI_SSID, auth=WIFI_AUTH)
while not wifi.isconnected():
    pass

print('IP address:', wifi.ifconfig()[0])

# initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

term = blynk.repl(5)
os.dupterm(term)

# start Blynk (this call should never return)
blynk.run()
Example #3
0
from machine import UART
import time
import os

os.dupterm(None)

repl_u = UART(0, baudrate=921600, timeout_chars=10)

if 'FiPy' in os.uname().sysname:
    lte_u = UART(1, baudrate=921600, pins=('P20', 'P18', 'P19', 'P17'), timeout_chars=10)
else:
    lte_u = UART(1, baudrate=921600, pins=('P5', 'P98', 'P7', 'P99'), timeout_chars=10)

while True:
    if repl_u.any():
        lte_u.write(repl_u.read())
    if lte_u.any():
        repl_u.write(lte_u.read())
    time.sleep_ms(2)
Example #4
0
 def shutdown(self):
     """Shut down Terminal and UART0 interface."""
     os.dupterm(None)
     self.deinit()
Example #5
0
 def destroy(self):
     os.dupterm(self.original_term)
Example #6
0
        # stop battery manangement
        if 112 in i2c.scan():
            i2c.mem_write(0, 112, 0)
        # sync filesystem
        os.sync()
        time.sleep_ms(300)
    finally:
        # disable power
        pwr.off()
    time.sleep_ms(300)
    # will never reach here
    for led in leds:
        led.toggle()


pyb.ExtInt(pyb.Pin('B1'), pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_NONE, pwrcb)

# configure usb from start if you want,
# otherwise will be configured after PIN
# pyb.usb_mode("VCP+MSC") # debug mode with USB and mounted storages from start
# pyb.usb_mode("VCP") # debug mode with USB from start
# disable at start
pyb.usb_mode(None)
os.dupterm(None, 0)
os.dupterm(None, 1)

# inject version and i2c to platform module
import platform
platform.version = version
platform.i2c = i2c
def enable_console_on_serial():
    """Enable REPL on USB serial connection"""
    global uart
    uart = UART(0, 115200)
    os.dupterm(uart)
Example #8
0
def set_usb_mode(dev=False, usb=False):
    if simulator:
        print("dev:", dev, ", usb:", usb)
    # now get correct mode
    if usb and not dev:
        pyb.usb_mode("VCP")
        if not simulator:
            os.dupterm(None, 0)
            os.dupterm(None, 1)
    elif usb and dev:
        pyb.usb_mode("VCP+MSC")
        if not simulator:
            # duplicate repl to stlink
            # as usb is busy for communication
            os.dupterm(stlk, 0)
            os.dupterm(None, 1)
    elif not usb and dev:
        pyb.usb_mode("VCP+MSC")
        usb = pyb.USB_VCP()
        if not simulator:
            os.dupterm(None, 0)
            os.dupterm(usb, 1)
    else:
        pyb.usb_mode(None)
        if not simulator:
            os.dupterm(None, 0)
            os.dupterm(None, 1)
Example #9
0
def start():
    uart = BLEUART(name="upy-repl")
    stream = BLEUARTStream(uart)

    os.dupterm(stream)
  Downloads, docs, tutorials: http://www.blynk.cc
  Sketch generator:           http://examples.blynk.cc
  Blynk community:            http://community.blynk.cc
  Social networks:            http://www.fb.com/blynkapp
                              http://twitter.com/blynk_app

This example shows how to turn a Terminal widget into
the REPL console.

In your Blynk App project:
  Add a Terminal widget, bind it to Virtual Pin V5.
  Run the App (green triangle in the upper right corner).
"""

import BlynkLib
import os

BLYNK_AUTH = 'YourAuthToken'

def hello():
    print('Welcome!')

# initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

term = blynk.repl(5)
os.dupterm(term)

# start Blynk (this call should never return)
blynk.run()
Example #11
0
# REPL duplication on UART0 for serial connection
from machine import UART
import os

usb = UART(0, 115200)
os.dupterm(usb)

# Disable heartbeat LED
from pycom import heartbeat

heartbeat(False)

# Disable WiFi radio
from pycom import wifi_on_boot

wifi_on_boot(False)
Example #12
0
def start():
    ble = bluetooth.BLE()
    uart = BLEUART(ble, name="mpy-repl")
    stream = BLEUARTStream(uart)

    os.dupterm(stream)
Example #13
0
def stop():
    if self._repl_task:
        self._repl_task.cancel()
        self._repl_task = None
    self.mqclient = None
    os.dupterm(None)
Example #14
0
 def switch_ssl_repl(self):
     print('>>> ')
     self.wrepl = os.dupterm(self.cli_soc, 0)
Example #15
0
# boot.py -- run on boot-up
# can run arbitrary Python, but best to keep it minimal

# Copy config.example.py to config.py and modify to your needs first!
import config
import machine

#from machine import UART
from os import dupterm
uart = machine.UART(0, 115200)
dupterm(uart)

if machine.reset_cause() != machine.SOFT_RESET:
    from network import WLAN
    wifi = WLAN()
    wifi.mode(WLAN.STA)
    ssids = wifi.scan()
    found = False
    for net in ssids:
        print("Checking %s" % net.ssid)
        if net.ssid == config.HOME_SSID:
            print("Found %s!" % net.ssid)
            wifi.connect(config.HOME_SSID, auth=(WLAN.WPA, config.HOME_PASSWORD))
            found = True
            break
    if not found:
        print("No eligible WiFi found.")
        wifi.mode(WLAN.AP)
Example #16
0
 def switch_wrepl(self):
     print('>>> ')
     self.cli_soc = os.dupterm(self.wrepl, 0)
Example #17
0
# poweroff on button press
pwrcb = lambda e: pwr.off()
pyb.ExtInt(pyb.Pin('B1'), pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_NONE, pwrcb)

import platform

# uncomment this lines if you want to override DEV_ENABLED
# platform.DEV_ENABLED = True
# platform.USB_ENABLED = True

# set up usb mode
if platform.USB_ENABLED and platform.DEV_ENABLED:
    pyb.usb_mode('CDC+MSC')
elif platform.USB_ENABLED:
    pyb.usb_mode('CDC')
elif platform.DEV_ENABLED:
    pyb.usb_mode('MSC')
else:
    pyb.usb_mode(None)

if platform.DEV_ENABLED:
    repl = pyb.UART('YB',115200)
    # redirect REPL to STLINK UART
    os.dupterm(repl,0)
if platform.USB_ENABLED:
    # unconnect REPL from USB
    os.dupterm(None, 1)

# uncomment this line to get interactive access over REPL
# pyb.main('repl.py')
Example #18
0
def configure_uart():
    uart = machine.UART(0, 115200)
    os.dupterm(uart)
Example #19
0
from machine import Pin, UART
uart1 = UART(1, baudrate=115200, tx=17, rx=18)
#uart1.init(115200, bits=8, parity=None, stop=1)


def test():
    import time
    for i in range(50):
        time.sleep(0.1)
        uart1.write('hello world!')
        print(uart1.read(uart1.any()))


import os
os.dupterm(uart1)
print(os)
Example #20
0
 def enable_terminal(self):
     self.__terminal_enabled = True
     os.dupterm(self.__terminal)
Example #21
0
# boot.py -- run on boot-up
# can run arbitrary Python, but best to keep it minimal
from machine import UART
from network import WLAN
from os import dupterm
from time import sleep_ms

# enable the UART on the USB-to-serial port
uart = UART(0, baudrate=115200)
# duplicate the terminal on the UART
dupterm(uart)
print('UART initialised!')

import settings

# login to the local network
print('Initialising WLAN in station mode...', end=' ')
wlan = WLAN(mode=WLAN.STA)
print('done.\nConnecting to WiFi network...', end='')
wlan.ifconfig(config='dhcp')
AUTH = (WLAN.WPA2, settings.wifiKey)
wlan.connect(ssid= settings.SSID, auth=AUTH)
while not wlan.isconnected():  
    sleep_ms(500)
    print('.', end='')
print(' done.\n')

# print
ip, mask, gateway, dns = wlan.ifconfig()
print('IP address: ', ip)
print('Netmask:    ', mask)
Example #22
0
 def stop(self):
     os.dupterm(None)
     if self.client_s:
         self.client_s.close()
     if self.listen_s:
         self.listen_s.close()
Example #23
0
import ili9341
from machine import Pin, SPI
spi = SPI(1, baudrate=40000000, polarity=0, phase=0)
display = ili9341.ILI9341(spi,
                          cs=Pin(15),
                          dc=Pin(16),
                          rst=None,
                          width=320,
                          height=240)
import ili9341_fb
fb = ili9341_fb.Ili9341Framebuffer(display)
import ps2
ps2.init(clock=5, data=0)
from fbconsole import FBConsole
console = FBConsole(fb)
import os
os.dupterm(console)


def cls():
    console.cls()


def on():
    console.on()


def off():
    console.off()
Example #24
0
# can run arbitrary Python, but best to keep it minimal

import os

import machine
from network import WLAN

# disable LED matrix first
latch = machine.Pin('GP13', mode=machine.Pin.OUT)
latch.value(0)

spi = machine.SPI(0, mode=machine.SPI.MASTER, bits=32, pins=('GP14', 'GP16', 'GP15'))
spi.write(b'\x00\x00\x00\x00')
latch.value(1)

# repl on serial
os.dupterm(machine.UART(0, 115200))

# now wifi
wlan = WLAN()

if machine.reset_cause() != machine.SOFT_RESET:
    wlan.init(WLAN.STA)
    wlan.ifconfig(config=('192.168.1.254', '255.255.255.0', '192.168.1.1', '192.168.1.1'))

if not wlan.isconnected():
    # change the line below to match your network ssid, security and password
    wlan.connect('XXX', auth=(WLAN.WPA2, 'XXX'), timeout=5000)
    while not wlan.isconnected():
        machine.idle()
Example #25
0
    def __init__(self, aPort, aSpeed):
        # diasable terminal echo to uart
        os.dupterm(None, aPort)

        self.uart = machine.UART(aPort)
        self.uart.init(9600, timeout=1000)
Example #26
0
from machine import UART
import machine
import os

uart = UART(0, baudrate=115200)
os.dupterm(uart)

machine.main('main.py')
        
Example #27
0
# (c) 2019-2020 Andreas Motl <*****@*****.**>
# (c) 2019-2020 Jan Hoffmann <*****@*****.**>
# (c) 2019-2020 Richard Pobering <*****@*****.**>
#
# License: GNU Affero General Public License, Version 3
#
# Documentation: https://terkin.org
#
# Have fun!


# Required to receive logging output when freezing the firmware.
try:
    import os
    from machine import UART
    os.dupterm(UART(0, 115200))
except:
    pass

# Global reference to Bootloader object.
bootloader = None


if __name__ == '__main__':

    import sys
    print('[boot.py] INFO: Python module search path is:', sys.path)

    # Extend module search path.
    print('[boot.py] INFO: Universal MicroPython Application Loader (umal)')
    from umal import MicroPythonBootloader
Example #28
0
from machine import Pin
import os
import time

mch = os.uname().machine
if 'LaunchPad' in mch:
    uart_id_range = range(0, 2)
    uart_pins = [[('GP12', 'GP13'), ('GP12', 'GP13', 'GP7', 'GP6')], [('GP16', 'GP17'), ('GP16', 'GP17', 'GP7', 'GP6')]]
elif 'WiPy' in mch:
    uart_id_range = range(0, 2)
    uart_pins = [[('GP12', 'GP13'), ('GP12', 'GP13', 'GP7', 'GP6')], [('GP16', 'GP17'), ('GP16', 'GP17', 'GP7', 'GP6')]]
else:
    raise Exception('Board not supported!')

# just in case we have the repl duplicated on any of the uarts
os.dupterm(None)

for uart_id in uart_id_range:
    uart = UART(uart_id, 38400)
    print(uart)
    uart.init(57600, 8, None, 1, pins=uart_pins[uart_id][0])
    uart.init(baudrate=9600, stop=2, parity=UART.EVEN, pins=uart_pins[uart_id][1])
    uart.init(baudrate=115200, parity=UART.ODD, stop=0, pins=uart_pins[uart_id][0])
    uart = UART(baudrate=1000000)
    uart.sendbreak()

uart = UART(baudrate=1000000)
uart = UART()
print(uart)
uart = UART(baudrate=38400, pins=('GP12', 'GP13'))
print(uart)
Example #29
0
def enable_console_on_serial():
    """Enable REPL on USB serial connection"""
    global uart
    uart = UART(0, 115200)
    os.dupterm(uart)
def enable_expansion_usb_uart():
    uart = UART(0, 115200)
    os.dupterm(uart)
Example #31
0
# Copyright 2021 FMR LLC <*****@*****.**>
# SPDX-License-Identifer: MIT

# boot.py -- run on boot-up
# can run arbitrary Python, but best to keep it minimal

import machine
import pyb
pyb.country('US') # ISO 3166-1 Alpha-2 code, eg US, GB, DE, AU
#pyb.main('main.py') # main script to run after this one
#pyb.usb_mode('VCP+MSC') # act as a serial and a storage device
#pyb.usb_mode('VCP+HID') # act as a serial device and a mouse

# move this to boot.py
import os, pyb
stlk = pyb.UART("YB", 9600)
os.dupterm(stlk, 0)
os.dupterm(None, 1)
# end
Example #32
0
# boot.py -- run on boot-up
# can run arbitrary Python, but best to keep it minimal
# setup UART on USB

import micropython
micropython.alloc_emergency_exception_buf(100)

from machine import UART
import os
uart = UART(0, baudrate=115200)
os.dupterm(uart)
print ('UART initialised')
#uart.irq(trigger=UART.RX_ANY, wake=machine.IDLE)
	
from machine import Pin
from machine import Timer

led_out = Pin('GP16', mode=Pin.OUT)
tim = Timer(1, mode=Timer.PERIODIC)
tim_a = tim.channel(Timer.A, freq=5)
# The slowest frequency the timer can run at is 5Hz
# so we divide the frequency down to toggle the LED
# BUT the callback function doesn't appear to have been developed
# Worth trying again as it is now included in the documentation
	
tim_a.irq(handler=lambda t:led_out.toggle(), trigger=Timer.TIMEOUT)	# Toggle LED on Timer interrupt

#btn_in = Pin('GP17', mode=Pin.IN, pull=Pin.PULL_UP)


# Connect to my WiFi
Example #33
0
# REPL duplication on UART0 for serial connection
from machine import UART
import os
uart0 = UART(0, 115200)
os.dupterm(uart0)

# Disable heartbeat LED
from pycom import heartbeat
heartbeat(False)

# Disable WiFi radio
from pycom import wifi_on_boot
wifi_on_boot(False)