コード例 #1
0
ファイル: UART.py プロジェクト: FlorianHou/esp32_lernen
from machine import UART, Pin
from machine import ADC
from time import sleep_ms

#UART
uart = UART(1,
            baudrate=115200,
            bits=8,
            parity=None,
            stop=1,
            tx=17,
            rx=16,
            rts=-1,
            cts=-1,
            txbuf=256,
            rxbuf=256,
            timeout=1000,
            timeout_char=2)
#Links Joystick
p_l = Pin(33, Pin.IN)
x_l = ADC(Pin(35))
x_l.atten(ADC.ATTN_11DB)
x_l.width(ADC.WIDTH_12BIT)
y_l = ADC(Pin(32))
y_l.atten(ADC.ATTN_11DB)
y_l.width(ADC.WIDTH_12BIT)

#Rechts Joystick
p_r = Pin(34, Pin.IN)
x_r = ADC(Pin(36))
x_r.atten(ADC.ATTN_11DB)
コード例 #2
0
from machine import UART
import machine
from pytrack import Pytrack
import utime
import pycom

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

machine.main('main.py')

end = utime.ticks_us()
took = end - start
print("boot.py ... done in: {} uSec".format(took))
コード例 #3
0
import machine
import time, ubinascii
import utime as time
from machine import UART, Pin, ADC
from cayennelpp import CayenneLPP
from Fssd1306 import SSD1306_I2C

led = Pin(2, Pin.OUT)
relay1 = Pin(12, Pin.OUT)

WaterValue = 1200  # WaterValue = 1680;
AirValue = 3035  # AirValue = 3620;

i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
oled = SSD1306_I2C(128, 64, i2c)
uart = UART(2, 115200, timeout=300)
pot = ADC(Pin(34))
pot.atten(ADC.ATTN_11DB)  # Full range: 3.3v

rstr = ""


def sendATcommand(ATcommand):
    print("Command: {0}\r\n".format(ATcommand))
    uart.write("{0}\r\n".format(ATcommand))
    rstr = uart.read().decode("utf-8")
    print(rstr)
    return rstr


def Oledhello():
コード例 #4
0
from machine import Pin, UART, unique_id, Timer, RTC
from umqtt.robust import MQTTClient
import time
import ubinascii
import machine
import math
import boot
import uos

uos.dupterm(None, 1)
uart = UART(0, baudrate=115200, bits=8, parity=None, stop=1, rxbuf=50, timeout=0, timeout_char=2)
#UART(0, baudrate=9600, bits=8, parity=None, stop=1, rxbuf=15, timeout=0, timeout_char=2)
tim0 = Timer(0)
rtc = RTC()

def load_last():
    import ujson as json
    try:
        with open("/last.json") as f:
            last = json.loads(f.read())
    except (OSError, ValueError):
        print("Couldn't load /last.json")
        save_alarm()
    else:
        LAST.update(last)
        print("Loaded alarm from /last.json")

def save_last():
    import ujson as json
    try:
        with open("/last.json", "w") as f:
コード例 #5
0
#i2c = I2C(-1, Pin(14), Pin(2))
#oled = ssd1306.SSD1306_I2C(128, 64, i2c)
#oled.fill(0)
#oled.show()

#oled.fill(0)
#oled.text("Starting up ...",0,0)
#oled.show()

#rx=34
#tx=13

rx=21
tx=19

uart=UART(2,baudrate=1200,bits=8, parity=None, stop=1,rx=rx,tx=tx)

index = 1

filename='data3.txt'


while True:
    a=uart.readline()
    if a!=None and '\r' in a:
        print(a)
        b=str(a).split(' ')
        print(b)
        ec=int(str(b[0])[-3:])
        print("last three=",str(b[0])[-3:])
        f=[]
コード例 #6
0
ファイル: boot.py プロジェクト: techgeeksid/micropython-Gps
from machine import UART
from micropyGPS import MicropyGPS
import utime, gc, _thread
import time
import urequests
import network
import ujson

uart = UART(1, rx=13, tx=12, baudrate=9600)
s = MicropyGPS()
URL = 'Firebase Url'
num = 0


def intern():
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print('connecting to network...')
        wlan.connect('iPhone', 'nopassword')


intern()

while True:
    time.sleep(3)
    ces = uart.read()
    line = ces.splitlines()
    for x in line:
        line_to_string = str(x)
        formated_line = line_to_string[2:-1]
コード例 #7
0
    def get_uart(self, id=1):
        self._log.debug("Hal: get uart")

        # first time: create uart storage
        if not hasattr(self,'_uart'):
            self._log.debug("Hal: get uart esp32, create uart local storage")
            self._uart = {}
        
        if self._utils.get_platform() == 'linux':
            self._log.debug("Hal: get uart linux")
            return None
        elif self._utils.get_platform() == 'pyboard': 
            self._log.debug("Hal: get uart pyboard")

            from machine import UART
            # check boundaries
            if id > 2:
                self._log.error("Hal: get uart pyboard, id bigger then 2")
                return None

            # Create new or reuse existing
            if id not in self._uart:
                self._log.debug("Hal: get uart pyboard, create uart object with id: "+str(id))
                self._uart[id] = UART(id)
                
            return self._uart[id] 
        elif self._utils.get_platform() == 'esp32':
            self._log.debug("Hal: get uart esp32")

            from machine import UART
            # check boundaries
            if id > 2:
                self._log.error("Hal: get uart esp32, id bigger then 2")
                return None

            # Get SW uart pins
            hardware = db.hardwareTable.getrow()

            # Create new or reuse existing
            if id not in self._uart.keys():
                txpin = int(self.vpin2pin(hardware["tx"]))
                rxpin = int(self.vpin2pin(hardware["rx"]))
                self._log.debug("Hal: get uart esp32, create uart object with id: {}, tx={}, rx={}".format(id,txpin,rxpin))
                try:
                    self._uart[id] = UART(id, tx=txpin, rx=rxpin)
                except ValueError:
                    self._log.error("Hal: get uart esp32, exception valueerror")
                    return None

            return self._uart[id] 
        elif self._utils.get_platform() == 'esp8266':
            self._log.debug("Hal: get uart esp8266")

            from machine import UART
            # check boundaries
            if id > 2:
                self._log.error("Hal: get uart esp8266, id bigger then 2")
                return None

            # Get SW uart pins
            hardware = db.hardwareTable.getrow()
                
            # Create new or reuse existing
            if id not in self._uart:
                self._log.debug("Hal: get uart esp8266, create uart object with id: "+str(id))
                self._uart[id] = UART(tx=self.pin(hardware["tx"]), rx=self.pin(hardware["rx"]))
                
            return self._uart[id] 
        else:
            self._log.error("Hal: get uart failure")
            return None
コード例 #8
0
def uart():
    u = UART(2, baudrate=9600)
    return u
コード例 #9
0
from micropyGPS import MicropyGPS
from machine import UART
from network import LoRa
import socket
import binascii
import struct
import time
import config
import tools

# Initialize GPS
com = UART(1, pins=(config.TX, config.RX), baudrate=9600)
my_gps = MicropyGPS()

# Initialize LoRa in LORAWAN mode.
lora = LoRa(mode=LoRa.LORAWAN)

# create an ABP authentication params
dev_addr = struct.unpack(">l",
                         binascii.unhexlify(config.DEV_ADDR.replace(' ',
                                                                    '')))[0]
nwk_swkey = binascii.unhexlify(config.NWK_SWKEY.replace(' ', ''))
app_swkey = binascii.unhexlify(config.APP_SWKEY.replace(' ', ''))

# join a network using ABP (Activation By Personalization)
lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))

# remove all the non-default channels
for i in range(3, 16):
    lora.remove_channel(i)
コード例 #10
0
from machine import UART
import time
import ssd1306
from machine import I2C
from machine import Pin
import gc
import bme280

baudrate = 1200
#baudrate=57600

y_start = 0

uart = UART(1, baudrate=baudrate, rx=19, tx=21, timeout=10)

index = -1
g = 10  # m/s^2
rho = 997  # kg/m^3

# set up the display
# i2c == (scl,sda)

i2c = I2C(-1, Pin(14), Pin(2))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
bme = bme280.BME280(i2c=i2c)

led = Pin(18, Pin.OUT)

#header_text="-- DEMO @ EPA --"
while True:
コード例 #11
0
ファイル: LPF2_mindstorms.py プロジェクト: sonoisa/cheese
    def initialize(self):
        assert not self.connected

        print("connecting...")

        fm.register(self.tx_pin_num, self.tx_fpioa_gpio, force=True)
        uart_tx = GPIO(self.tx_gpio, GPIO.OUT)

        uart_tx.value(0)
        time.sleep_ms(410)
        uart_tx.value(1)

        fm.register(self.tx_pin_num, self.uart_tx_fpioa_num, force=True)
        fm.register(self.rx_pin_num, self.uart_rx_fpioa_num, force=True)

        self.uart = UART(self.uart_num,
                         115200,
                         bits=8,
                         parity=None,
                         stop=1,
                         timeout=10000,
                         read_buf_len=4096)

        # wait for \x52\x00\xc2\x01\x00\x6e
        self.uart.write(b'\x04')  # ACK?
        time.sleep_ms(10)
        self.uart.write(b'\x40\x3e\x81')  # CMD_TYPE(1), TypeID:0x3e, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x51\x07\x06\x08\x00\xa7'
        )  # CMD_MODES(4), 8 modes for EV3, 7 views for EV3, 9 modes, 0 views, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x52\x00\xc2\x01\x00\x6e'
                        )  # CMD_SPEED(4), speed:115200, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x5f\x00\x00\x00\x10\x00\x00\x00\x10\xa0'
        )  # CMD_VERSION(8), fw-version:1.0.00.0000, hw-version:1.0.00.0000, checksum
        time.sleep_ms(18)

        self.uart.write(
            b'\xa0\x20\x43\x41\x4c\x49\x42\x00\x40\x40\x00\x00\x04\x84\x00\x00\x00\x00\xba'
        )  # INFO_NAME(16) | mode:0+8, "CALIB\0" + flags(0x40, 0x40, 0x00, 0x00, 0x04, 0x84), checksum
        self.uart.write(
            b'\x98\x21\x00\x00\x00\x00\x00\x00\x7f\x43\x7a'
        )  # INFO_RAW(8) | mode:0+8, min:0.0, max:255.0, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x98\x22\x00\x00\x00\x00\x00\x00\xc8\x42\xcf'
        )  # INFO_PCT(8) | mode:0+8, min:0.0, max:100.0, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x98\x23\x00\x00\x00\x00\x00\x00\x7f\x43\x78'
        )  # INFO_SI(8) | mode:0+8, min:0.0, max:255.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x90\x24\x50\x43\x54\x00\x0c'
                        )  # INFO_SYMBOL(4) | mode:0+8, "PCT\0", checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x88\x25\x00\x00\x52'
        )  # INFO_MAPPING(2) | mode:0+8, input:0, output:0, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x90\xa0\x07\x00\x03\x00\xcb'
        )  # INFO_FORMAT(4) | mode:0+8, data-sets:7, format:0, figures:3, decimals:0, checksum
        time.sleep_ms(18)

        self.uart.write(
            b'\xa7\x00\x41\x44\x52\x41\x57\x00\x40\x00\x00\x00\x04\x84\x00\x00\x00\x00\xd9'
        )  # INFO_NAME(16) | mode:7, "ADRAW\0" + flags(0x40, 0x00, 0x00, 0x00, 0x04, 0x84), checksum
        self.uart.write(
            b'\x9f\x01\x00\x00\x00\x00\x00\x00\x80\x44\xa5'
        )  # INFO_RAW(8) | mode:7, min:0.0, max:1024.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x9f\x02\x00\x00\x00\x00\x00\x00\xc8\x42\xe8'
                        )  # INFO_PCT(8) | mode:7, min:0.0, max:100.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x9f\x03\x00\x00\x00\x00\x00\x00\x80\x44\xa7'
                        )  # INFO_SI(8) | mode:7, min:0.0, max:1024.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x97\x04\x50\x43\x54\x00\x2b'
                        )  # INFO_SYMBOL(4) | mode:7, "PCT\0", checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x8f\x05\x90\x00\xe5'
        )  # INFO_MAPPING(2) | mode:7, input:0x90, output:0, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x97\x80\x01\x01\x04\x00\xec'
        )  # INFO_FORMAT(4) | mode:7, data-sets:1, format:1, figures:4, decimals:0, checksum
        time.sleep_ms(18)

        self.uart.write(
            b'\xa6\x00\x50\x49\x4e\x47\x00\x00\x40\x80\x00\x00\x04\x84\x00\x00\x00\x00\x09'
        )  # INFO_NAME(16) | mode:6, "PING\0\0" + flags(0x40, 0x80, 0x00, 0x00, 0x04, 0x84), checksum
        self.uart.write(b'\x9e\x01\x00\x00\x00\x00\x00\x00\x80\x3f\xdf'
                        )  # INFO_RAW(8) | mode:6, min:0.0, max:1.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x9e\x02\x00\x00\x00\x00\x00\x00\xc8\x42\xe9'
                        )  # INFO_PCT(8) | mode:6, min:0.0, max:100.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x9e\x03\x00\x00\x00\x00\x00\x00\x80\x3f\xdd'
                        )  # INFO_SI(8) | mode:6, min:0.0, max:1.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x96\x04\x50\x43\x54\x00\x2a'
                        )  # INFO_SYMBOL(4) | mode:6, "PCT\0", checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x8e\x05\x00\x90\xe4'
        )  # INFO_MAPPING(2) | mode:6, input:0, output:0x90, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x96\x80\x01\x00\x01\x00\xe9'
        )  # INFO_FORMAT(4) | mode:6, data-sets:1, format:0, figures:1, decimals:0, checksum
        time.sleep_ms(18)

        self.uart.write(
            b'\xa5\x00\x4c\x49\x47\x48\x54\x00\x40\x20\x00\x00\x04\x84\x00\x00\x00\x00\xe4'
        )  # INFO_NAME(16) | mode:5, "LIGHT\0" + flags(0x40, 0x20, 0x00, 0x00, 0x04, 0x84), checksum
        self.uart.write(b'\x9d\x01\x00\x00\x00\x00\x00\x00\xc8\x42\xe9'
                        )  # INFO_RAW(8) | mode:5, min:0.0, max:100.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x9d\x02\x00\x00\x00\x00\x00\x00\xc8\x42\xea'
                        )  # INFO_PCT(8) | mode:5, min:0.0, max:100.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x9d\x03\x00\x00\x00\x00\x00\x00\xc8\x42\xeb'
                        )  # INFO_SI(8) | mode:5, min:0.0, max:100.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x95\x04\x50\x43\x54\x00\x29'
                        )  # INFO_SYMBOL(4) | mode:5, "PCT\0", checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x8d\x05\x00\x10\x67'
        )  # INFO_MAPPING(2) | mode:5, input:0, output:0x10, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x95\x80\x04\x00\x03\x00\xed'
        )  # INFO_FORMAT(4) | mode:5, data-sets:4, format:0, figures:3, decimals:0, checksum
        time.sleep_ms(18)

        self.uart.write(
            b'\xa4\x00\x54\x52\x41\x57\x00\x00\x40\x00\x00\x00\x04\x84\x00\x00\x00\x00\x8b'
        )  # INFO_NAME(16) | mode:4, "TRAW\0\0" + flags(0x40, 0x00, 0x00, 0x00, 0x04, 0x84), checksum
        self.uart.write(
            b'\x9c\x01\x00\x00\x00\x00\x00\xc4\x63\x46\x83'
        )  # INFO_RAW(8) | mode:4, min:0.0, max:14577.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x9c\x02\x00\x00\x00\x00\x00\x00\xc8\x42\xeb'
                        )  # INFO_PCT(8) | mode:4, min:0.0, max:100.0, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x9c\x03\x00\x00\x00\x00\x00\xc4\x63\x46\x81'
        )  # INFO_SI(8) | mode:4, min:0.0, max:14577.0, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x8c\x04\x75\x53\x51')  # INFO_SYMBOL(2) | mode:4, "uS", checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x8c\x05\x90\x00\xe6'
        )  # INFO_MAPPING(2) | mode:4, input:0x90, output:0, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x94\x80\x01\x02\x05\x00\xed'
        )  # INFO_FORMAT(4) | mode:4, data-sets:1, format:2, figures:5, decimals:0, checksum
        time.sleep_ms(18)

        self.uart.write(
            b'\xa3\x00\x4c\x49\x53\x54\x4e\x00\x40\x00\x00\x00\x04\x84\x00\x00\x00\x00\xd0'
        )  # INFO_NAME(16) | mode:3, "LISTN\0" + flags(0x40, 0x00, 0x00, 0x00, 0x04, 0x84), checksum
        self.uart.write(b'\x9b\x01\x00\x00\x00\x00\x00\x00\x80\x3f\xda'
                        )  # INFO_RAW(8) | mode:3, min:0.0, max:1.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x9b\x02\x00\x00\x00\x00\x00\x00\xc8\x42\xec'
                        )  # INFO_PCT(8) | mode:3, min:0.0, max:100.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x9b\x03\x00\x00\x00\x00\x00\x00\x80\x3f\xd8'
                        )  # INFO_SI(8) | mode:3, min:0.0, max:1.0, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x8b\x04\x53\x54\x77')  # INFO_SYMBOL(2) | mode:3, "ST", checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x8b\x05\x10\x00\x61'
        )  # INFO_MAPPING(2) | mode:3, input:0x10, output:0, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x93\x80\x01\x00\x01\x00\xec'
        )  # INFO_FORMAT(4) | mode:3, data-sets:1, format:0, figures:1, decimals:0, checksum
        time.sleep_ms(18)

        self.uart.write(
            b'\xa2\x00\x53\x49\x4e\x47\x4c\x00\x40\x00\x00\x00\x04\x84\x00\x00\x00\x00\xc2'
        )  # INFO_NAME(16) | mode:2, "SINGL\0" + flags(0x40, 0x00, 0x00, 0x00, 0x04, 0x84), checksum
        self.uart.write(
            b'\x9a\x01\x00\x00\x00\x00\x00\x40\x1c\x45\x7d'
        )  # INFO_RAW(8) | mode:2, min:0.0, max:2500.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x9a\x02\x00\x00\x00\x00\x00\x00\xc8\x42\xed'
                        )  # INFO_PCT(8) | mode:2, min:0.0, max:100.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x9a\x03\x00\x00\x00\x00\x00\x00\x7a\x43\x5f'
                        )  # INFO_SI(8) | mode:2, min:0.0, max:250.0, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x8a\x04\x43\x4d\x7f')  # INFO_SYMBOL(2) | mode:2, "CM", checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x8a\x05\x90\x00\xe0'
        )  # INFO_MAPPING(2) | mode:2, input:0x00, output:0, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x92\x80\x01\x01\x05\x01\xe9'
        )  # INFO_FORMAT(4) | mode:2, data-sets:1, format:1, figures:5, decimals:1, checksum
        time.sleep_ms(18)

        self.uart.write(
            b'\xa1\x00\x44\x49\x53\x54\x53\x00\x40\x00\x00\x00\x04\x84\x00\x00\x00\x00\xc7'
        )  # INFO_NAME(16) | mode:1, "DISTS\0" + flags(0x40, 0x00, 0x00, 0x00, 0x04, 0x84), checksum
        self.uart.write(b'\x99\x01\x00\x00\x00\x00\x00\x00\xa0\x43\x84'
                        )  # INFO_RAW(8) | mode:1, min:0.0, max:320.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x99\x02\x00\x00\x00\x00\x00\x00\xc8\x42\xee'
                        )  # INFO_PCT(8) | mode:1, min:0.0, max:100.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x99\x03\x00\x00\x00\x00\x00\x00\x00\x42\x27'
                        )  # INFO_SI(8) | mode:1, min:0.0, max:32.0, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x89\x04\x43\x4d\x7c')  # INFO_SYMBOL(2) | mode:1, "CM", checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x89\x05\xf1\x00\x82'
        )  # INFO_MAPPING(2) | mode:1, input:0xf1, output:0, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x91\x80\x01\x01\x04\x01\xeb'
        )  # INFO_FORMAT(4) | mode:1, data-sets:1, format:1, figures:4, decimals:1, checksum
        time.sleep_ms(18)

        self.uart.write(
            b'\xa0\x00\x44\x49\x53\x54\x4c\x00\x40\x00\x00\x00\x04\x84\x00\x00\x00\x00\xd9'
        )  # INFO_NAME(16) | mode:0, "DISTL\0" + flags(0x40, 0x00, 0x00, 0x00, 0x04, 0x84), checksum
        self.uart.write(
            b'\x98\x01\x00\x00\x00\x00\x00\x40\x1c\x45\x7f'
        )  # INFO_RAW(8) | mode:0, min:0.0, max:2500.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x98\x02\x00\x00\x00\x00\x00\x00\xc8\x42\xef'
                        )  # INFO_PCT(8) | mode:0, min:0.0, max:100.0, checksum
        time.sleep_ms(1)
        self.uart.write(b'\x98\x03\x00\x00\x00\x00\x00\x00\x7a\x43\x5d'
                        )  # INFO_SI(8) | mode:0, min:0.0, max:250.0, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x88\x04\x43\x4d\x7d')  # INFO_SYMBOL(2) | mode:0, "CM", checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x88\x05\x91\x00\xe3'
        )  # INFO_MAPPING(2) | mode:0, input:0x91, output:0, checksum
        time.sleep_ms(1)
        self.uart.write(
            b'\x90\x80\x01\x01\x05\x01\xeb'
        )  # INFO_FORMAT(4) | mode:0, data-sets:1, format:1, figures:5, decimals:1, checksum
        time.sleep_ms(18)

        self.uart.write(
            b'\xa0\x08\x00\x2d\x00\x33\x05\x47\x38\x33\x30\x31\x32\x36\x00\x00\x00\x00\x05'
        )
        self.uart.write(b'\x04')

        print("waiting for ACK...")
        self.connected = self._wait_for_value(b'\x04')

        if self.connected:
            print("connected")
            self.set_data(0)
            self.timer = Timer(self.timer_num,
                               self.timer_channel_num,
                               mode=Timer.MODE_PERIODIC,
                               period=200,
                               callback=self._handle_message_callback)
            self.timer.start()
        else:
            print("not connected")

        return self.connected
コード例 #12
0
#hardware platform: FireBeetle-ESP8266

from machine import UART

uart = UART(0)  #create uart object and init
uart.write("dfrobot\r\n")  #write the string "dfrobot"
コード例 #13
0
thro1 = 220
thro2 = 5
roll1 = 120
roll2 = 05
pitch1 = 220
pitch2 = 05
yaw1 = 176
yaw2 = 04
auz = 0
crc = 17

D2 = 4

exit = Pin(D2, Pin.IN, Pin.PULL_UP)

naze = UART(0, 9600)  # use uart2 i.e tx2 and rx2 for commununication
naze.init(9600, bits=8, parity=None, stop=1)

while exit.value() == 1:
    naze.write('$M<')
    naze.write(chr(64))
    print(chr(65))
    #naze.wrire(200)

    #naze.write(str(unichr(size)))
    '''
    naze.write(idd)
  
    naze.write(thro1)
    naze.write(thro2)
    
コード例 #14
0
from network import LTE
from machine import UART
import sys
import binascii
import time
import _thread

lte = LTE()
lte.init()

uart = UART(1,
            baudrate=921600,
            pins=('P5', 'P98', 'P7', 'P99'),
            timeout_chars=1)


def read_rsp(size=None, timeout=-1):
    time.sleep(.25)
    if timeout < 0:
        timeout = 20000
    elif timeout is None:
        timeout = 0

    while not uart.any() and timeout > 0:
        time.sleep_ms(1)
        timeout -= 1

    if size is not None:
        rsp = uart.read(size)
    else:
        rsp = uart.read()
コード例 #15
0
    def __run(self, file_path=None, baudrate=921600, port=None, resume=False, load_ffh=False, mirror=False, switch_ffh=False, bootrom=False, rgbled=0x050505, debug=False, pkgdebug=False, atneg=True, max_try=10, direct=True, atneg_only=False, info_only=False, expected_smod=None, verbose=False, load_fff=False, mtools=False):
        self.__wait_msg = False
        mirror = True if atneg_only else mirror
        recover = True if atneg_only else load_ffh
        resume = True if mirror or recover or atneg_only or info_only else resume
        verbose = True if debug else verbose
        load_fff = False if bootrom and switch_ffh else load_fff
        target_baudrate = baudrate
        baudrate = self.__modem_speed if self.__speed_detected else baudrate
        if debug: print('mirror? {}  recover? {}  resume? {}  direct? {}  atneg_only? {} bootrom? {} load_fff? {}'.format(mirror, recover, resume, direct, atneg_only, bootrom, load_fff))
        if debug: print('baudrate: {} target_baudrate: {}'.format(baudrate, target_baudrate))
        abort = True
        external = False
        self.__serial = None

        if 'FiPy' in self.__sysname or 'GPy' in self.__sysname:

            self.__serial = UART(1, baudrate=115200 if recover and not self.__speed_detected else baudrate, pins=self.__pins, timeout_chars=100)
            self.__serial.read()
        else:
            if port is None:
                raise ValueError('serial port not specified')
            if debug: print('Setting port {}'.format(port))
            external = True
            br = 115200 if recover and not direct else baudrate
            if debug: print('Setting baudrate to {}'.format(br))
            self.__serial = serial.Serial(port, br, bytesize=serial.EIGHTBITS, timeout=1 if info_only else 0.1)
            self.__serial.reset_input_buffer()
            self.__serial.reset_output_buffer()

        if info_only:
            self.__serial.read()
            self.__serial.write(b'AT\r\n')
            self.__serial.write(b'AT\r\n')
            self.__serial.read()
            self.__serial.write(b"AT+CGSN\r\n")
            time.sleep(.5)
            shimei = self.read_rsp(2000)
            if verbose:
                self.__serial.write(b"AT!=\"showver\"\r\n")
            else:
                self.__serial.write(b"ATI1\r\n")
            time.sleep(.5)
            shver = self.read_rsp(2000)
            if shver is not None:
                self.print_pretty_response(shver)
            if shimei is not None:
                self.print_pretty_response(shimei, prefix='\nIMEI:')
            return True

        if debug: print('Initial prepartion complete...')

        if not mirror:
            if bootrom:
                if debug: print('Loading built-in recovery bootrom...')
                try:
                    # try compressed bootrom first
                    from sqnsbrz import bootrom
                except:
                    # fallback to uncompressed
                    from sqnsbr import bootrom
                blob = bootrom()
                blobsize = blob.get_size()
            else:
                if debug: print('Loading {}'.format(file_path))
                blobsize = os.stat(file_path)[6]
                if blobsize < 128:
                    print('Firmware file is too small!')
                    reconnect_uart()
                    sys.exit(1)
                if blobsize > 4194304:
                    if load_fff:
                        print("Firmware file is too big to load via FFF method. Using ON_THE_FLY")
                    load_fff = False
                blob = open(file_path, "rb")

        if not load_ffh:
            if not self.wakeup_modem(baudrate, port, 10, 1, debug):
                return False

        if (not resume) or mtools:

            # bind to AT channel
            self.__serial.write(b"AT+BIND=AT\r\n")
            time.sleep(.5)
            response = self.read_rsp(size=100)
            if debug: print("AT+BIND=AT returned {}".format(response))

            # disable echo
            self.__serial.write(b"ATE0\r\n")
            time.sleep(.5)
            response = self.read_rsp(size=100)
            if debug: print("ATE0 returned {}".format(response))

            self.__serial.read()
            if debug: print('Entering upgrade mode...')

            if verbose: print("Sending AT+SMLOG?")
            self.__serial.write(b'AT+SMLOG?\r\n')
            response = self.read_rsp(size=100)
            if verbose: print("AT+SMLOG? returned {}".format(response))

            self.__serial.write(b"AT+SMOD?\r\n")
            response = self.return_pretty_response(self.read_rsp(size=7))
            if debug: print("AT+SMOD? returned {}".format(response))

            if verbose: print('Sending AT+FSRDFILE="/fs/crashdump"')
            self.__serial.write(b'AT+FSRDFILE="/fs/crashdump"\r\n')
            response = self.read_rsp(size=100)
            if verbose: print('AT+FSRDFILE="/fs/crashdump" returned {}'.format(response))
            self.__serial.read()

            self.__serial.write(b"AT+SQNSUPGRADENTF=\"started\"\r\n")
            response = self.read_rsp(size=100)
            if verbose: print('AT+SQNSUPGRADENTF="started" returned {}'.format(response))
            self.wait_for_modem()

            if verbose: print('Sending AT+SQNWL="sqndcc",2')
            self.__serial.write(b'AT+SQNWL="sqndcc",2\r\n')
            response = self.read_rsp(size=100)
            if verbose: print('AT+SQNWL="sqndcc",2 returned {}'.format(response))
            self.__serial.read(100)

            if verbose: print("Sending AT+CFUN=4")
            self.__serial.write(b'AT+CFUN=4\r\n')
            response = self.read_rsp(size=100)
            if verbose: print("AT+CFUN=4 returned {}".format(response))
            self.__serial.read(100)

            if not (load_fff or mtools):
                self.__serial.write(b"AT+SMSWBOOT=3,1\r\n")
                resp = self.read_rsp(100)
                if debug: print('AT+SMSWBOOT=3,1 returned: {}'.format(resp))
                if b'ERROR' in resp:
                    time.sleep(5)
                    self.__serial.write(b"AT+SMSWBOOT=3,0\r\n")
                    resp = self.read_rsp(100)
                    if debug: print('AT+SMSWBOOT=3,0 returned: {}'.format(resp))
                    if b'OK' in resp:
                        self.__serial.write(b"AT^RESET\r\n")
                        resp = self.read_rsp(100)
                        if debug: print('AT^RESET returned: {}'.format(resp))
                    else:
                        print('Received ERROR from AT+SMSWBOOT=3,1! Aborting!')
                        reconnect_uart()
                        sys.exit(1)
                time.sleep(3)
                resp = self.__serial.read()
                if debug: print("Response after reset: {}".format(resp))
                self.wait_for_modem()
                self.__serial.write(b"AT\r\n")

                if verbose: print("Sending AT+CFUN=4")
                self.__serial.write(b'AT+CFUN=4\r\n')
                response = self.read_rsp(size=100)
                if verbose: print("AT+CFUN=4 returned {}".format(response))

                if verbose: print("Sending AT+SMLOG?")
                self.__serial.write(b'AT+SMLOG?\r\n')
                response = self.read_rsp(size=100)
                if verbose: print("AT+SMLOG? returned {}".format(response))

                if verbose: print('Sending AT+FSRDFILE="/fs/crashdump"')
                self.__serial.write(b'AT+FSRDFILE="/fs/crashdump"\r\n')
                response = self.read_rsp(size=100)
                if verbose: print('AT+FSRDFILE="/fs/crashdump" returned {}'.format(response))
                self.__serial.read()


        else:
            self.__serial.read(100)
            if debug: print('Entering recovery mode')

            self.__serial.write(b"AT+SMOD?\r\n")
            response = self.return_pretty_response(self.read_rsp(size=7))
            self.__serial.read(100)
            if debug: print("AT+SMOD? returned {}".format(response))

        time.sleep(1)
        self.__serial.read()

        if (not recover) and (not direct):
            if mirror:
                time.sleep(.5)
                self.__serial.read(100)
                print('Going into MIRROR mode... please close this terminal to resume the upgrade via UART')
                self.uart_mirror(rgbled)

            elif bootrom:
                if verbose: print('Starting STP')
            else:
                if verbose:
                    if load_fff:
                        print('Starting STP [FFF]')
                    else:
                        print('Starting STP ON_THE_FLY')

            self.__serial.read(100)

            if load_fff:
                if debug: print("Sending AT+SMSTPU")
                self.__serial.write(b'AT+SMSTPU\r\n')
            else:
                if debug: print("Sending AT+SMSTPU=\"ON_THE_FLY\"")
                self.__serial.write(b'AT+SMSTPU=\"ON_THE_FLY\"\r\n')

            response = self.read_rsp(size=4)
            if response != b'OK\r\n' and response != b'\r\nOK' and response != b'\nOK':
                raise OSError("Invalid answer '%s' from the device" % response)
                blob.close()

            self.__serial.read()
        elif recover and (not direct):
            if atneg:
                result = self.at_negotiation(baudrate, port, max_try, mirror, atneg_only, debug, target_baudrate)
                if result:
                    baudrate = target_baudrate
                    self.__modem_speed = target_baudrate
                    self.__speed_detected = True
                    if atneg_only:
                        return True
                    if mirror:
                        time.sleep(.5)
                        self.__serial.read(100)
                        print('Going into MIRROR mode... please close this terminal to resume the upgrade via UART')
                        self.uart_mirror(rgbled)
                    else:
                        self.__serial.write(b"AT+STP\n")
                        response = self.read_rsp(size=6)
                        if not b'OK' in response:
                            print('Failed to start STP mode!')
                            reconnect_uart()
                            sys.exit(1)
                else:
                    print('AT auto-negotiation failed! Exiting.')
                    return False
        else:
            if debug: print('Starting STP mode...')
            self.__serial.write(b"AT+STP\n")
            response = self.read_rsp(size=6)
            if not b'OK' in response:
                print('Failed to start STP mode!')
                reconnect_uart()
                sys.exit(1)

        try:
            if debug:
                if verbose: print('Starting STP code upload')
            if stp.start(blob, blobsize, self.__serial, baudrate, AT=False, debug=debug, pkgdebug=pkgdebug):
                blob.close()
                self.__serial.read()
                if switch_ffh:
                    if verbose: print('Bootrom updated successfully, switching to recovery mode')
                    abort = False
                elif load_ffh:
                    if not self.wakeup_modem(baudrate, port, 100, 1, debug,'Waiting for updater to load...'):
                        return False
                    if verbose: print('Upgrader loaded successfully, modem is in update mode')
                    return True
                else:
                    if verbose: print('Code download done, returning to user mode')
                    abort = recover
            else:
                blob.close()
                print('Code download failed, aborting!')
                return False
        except:
            blob.close()
            print('Code download failed, aborting!')
            abort = True

        time.sleep(1.5)

        if not abort:
            self.__serial.read()
            if switch_ffh:
                self.__serial.write(b"AT+SMSWBOOT=0,1\r\n")
                resp = self.read_rsp(100)
                if debug: print("AT+SMSWBOOT=0,1 returned {}".format(resp))
                if b"ERROR" in resp:
                    time.sleep(5)
                    self.__serial.write(b"AT+SMSWBOOT=0,0\r\n")
                    resp = self.read_rsp(100)
                    if debug: print('AT+SMSWBOOT=0,0 returned: {}'.format(resp))
                    if b'OK' in resp:
                        self.__serial.write(b"AT^RESET\r\n")
                        resp = self.read_rsp(100)
                        if debug: print('AT^RESET returned: {}'.format(resp))
                        return True
                    else:
                        print('Received ERROR from AT+SMSWBOOT=0,0! Aborting!')
                        return False
                return True
            else:
                if load_fff:
                    self.__serial.write(b"AT+SMUPGRADE\r\n")
                if not self.wakeup_modem(baudrate, port, 100, 1, debug, self.__get_wait_msg(load_fff=load_fff)):
                    print("Timeout while waiting for modem to finish updating!")
                    reconnect_uart()
                    sys.exit(1)

                start = time.time()
                while True:
                    self.__serial.read()
                    self.__serial.write(b"AT+SMUPGRADE?\r\n")
                    resp = self.read_rsp(1024)
                    if debug: print("AT+SMUPGRADE? returned {} [timeout: {}]".format(resp, time.time() - start))

                    if resp == b'\x00' or resp == b'':
                        time.sleep(2)

                    if b'No report' in resp or b'on-going' in resp:
                        time.sleep(1)

                    if b'success' in resp or b'fail' in resp:
                        break

                    if time.time() - start >= 300:
                        raise OSError('Timeout waiting for modem to respond!')

                self.__serial.write(b"AT+SMSWBOOT?\r\n")
                resp = self.read_rsp(100)
                if debug: print("AT+SMSWBOOT? returned {}".format(resp))
                start = time.time()
                while (b"RECOVERY" not in resp) and (b"FFH" not in resp) and (b"FFF" not in resp):
                    if debug: print("Timeout: {}".format(time.time() - start))
                    if time.time() - start >= 300:
                        reconnect_uart()
                        raise OSError('Timeout waiting for modem to respond!')
                    time.sleep(2)
                    if not self.wakeup_modem(baudrate, port, 100, 1, debug, self.__get_wait_msg(load_fff=load_fff)):
                        reconnect_uart()
                        raise OSError('Timeout while waiting for modem to finish updating!')
                    self.__serial.read()
                    self.__serial.write(b"AT+SMSWBOOT?\r\n")
                    resp = self.read_rsp(100)
                    if debug: print("AT+SMSWBOOT? returned {}".format(resp))
                self.__serial.read()
                self.__serial.write(b"AT+SMUPGRADE?\r\n")
                resp = self.read_rsp(1024)
                if debug: print("AT+SMUPGRADE? returned {}".format(resp))
                sqnup_result = self.return_upgrade_response(resp)
                if debug: print('This is my result: {}'.format(sqnup_result))
                if 'success' in sqnup_result:
                    if not load_fff:
                        self.special_print('Resetting.', end='', flush=True)
                        self.__serial.write(b"AT+SMSWBOOT=1,1\r\n")
                        if debug: print("AT+SMSWBOOT=1,1 returned {}".format(resp))
                        if b"ERROR" in resp:
                            time.sleep(5)
                            self.__serial.write(b"AT+SMSWBOOT=1,0\r\n")
                            resp = self.read_rsp(100)
                            if debug: print('AT+SMSWBOOT=1,0 returned: {}'.format(resp))
                            if b'OK' in resp:
                                self.__serial.write(b"AT^RESET\r\n")
                                resp = self.read_rsp(100)
                                if debug: print('AT^RESET returned: {}'.format(resp))
                                return True
                            else:
                                print('Received ERROR from AT+SMSWBOOT=1,0! Aborting!')
                                return False
                        self.wait_for_modem(send=False, echo_char='.', expected=b'+SYSSTART')

                elif sqnup_result is not None:
                    print('Upgrade failed with result {}!'.format(sqnup_result))
                    print('Please check your firmware file(s)')
                else:
                    print("Invalid response after upgrade... aborting.")
                    reconnect_uart()
                    sys.exit(1)

                self.__serial.write(b"AT\r\n")
                self.__serial.write(b"AT\r\n")
                time.sleep(0.5)

                if 'success' in sqnup_result:
                    if verbose: print('Sending AT+SQNSUPGRADENTF="success"')
                    self.__serial.write(b"AT+SQNSUPGRADENTF=\"success\"\r\n")
                    resonse = self.read_rsp(100)
                    if verbose: print('AT+SQNSUPGRADENTF="success" returned {}'.format(response))
                    time.sleep(.25)
                    if verbose: print('Sending AT+FSRDFILE="/fs/crashdump"')
                    self.__serial.write(b'AT+FSRDFILE="/fs/crashdump"\r\n')
                    resonse = self.read_rsp(100)
                    if verbose: print('AT+FSRDFILE="/fs/crashdump" returned {}'.format(response))
                    self.__serial.read()
                    return True
                elif sqnup_result is None:
                    print('Modem upgrade was unsucessfull. Please check your firmware file(s)')
        return False
コード例 #16
0
ファイル: A9G_GPS.py プロジェクト: Makerfabs/MakePython-A9G
#for Makepython A9G GPS Tracker V1.1
from machine import UART, Pin, I2C
import machine
import ssd1306
import utime

uart = UART(2, baudrate=115200, rx=21, tx=22, timeout=10)
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)  #Init i2c
lcd = ssd1306.SSD1306_I2C(128, 64, i2c)
lcd.text('Hello, Makerfabs', 0, 0)
lcd.text('waiting...', 0, 8)
lcd.show()

A9G_RESET_PIN = Pin(33, Pin.OUT)
A9G_RESET_PIN.value(0)  #set pin to low

utime.sleep_ms(2000)
A9G_PWR_KEY = Pin(27, Pin.OUT)
A9G_PWR_KEY.value(0)
utime.sleep_ms(2000)
A9G_PWR_KEY.value(1)
utime.sleep_ms(20000)

#Display line wrap
p = 0


def text(string, c=0, r=0):
    global p
    if p > 80:
        p = 0
コード例 #17
0
from machine import UART
import utime as time

import adafruit_gps

# Create a GPS module instance.
#uart = UART(1, baudrate=9600, timeout_chars=3000, pins=('P8','P2'))
#uart = UART(1, baudrate=9600)
# Create a GPS module instance.
uart = UART(1,9600, pins = ('P22','P21'))
uart.init(baudrate=9600, bits=8, parity=None, stop=1, pins=('P22', 'P21'))
print('UART')
print(uart)

gps = adafruit_gps.GPS(uart)
gps.send_command('PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
gps.send_command('PMTK220,1000')
last_print = time.ticks_ms()

while True:
    gps.update()
    current = time.ticks_ms()
    if current - last_print >= 1.0:
        last_print = current
        if not gps.has_fix:
            print('Waiting for fix...')
            continue
        print('=' * 40) # Print a separator line.
        print('Latitude: {0:.6f} degrees'.format(gps.latitude))
        print('Longitude: {0:.6f} degrees'.format(gps.longitude))
コード例 #18
0
irq_pin = Pin(25, mode=Pin.IN)
irq_pin.irq(trigger=Pin.IRQ_RISING, handler=mpu_irq_handler)

# display
display = Display()

# sd cards
spi_sd = SPI(1,
             sck=Pin(23, Pin.OUT),
             mosi=Pin(13, Pin.OUT),
             miso=Pin(12, Pin.IN))
sd = SDCard(spi_sd, Pin(21))
os.mount(sd, '/sd')

# gps
uart = UART(1, rx=34, tx=17)  # init with given baudrate
uart.init(9600, bits=8, parity=None, stop=1)  # init with given parameters
my_gps = MicropyGPS()

# wlan
station = network.WLAN(network.STA_IF)

if (settings['status'] == _booting):
    sensor.enable_irq_mode()
    #machine.freq(80000000)
    #machine.idle()
    settings['status'] = _sleeping

lastUpdateTimes = [0, 0, 0, 0, 0, 0]
NODE_NAME = config_lora.get_nodename()
コード例 #19
0
 def __init__(self, SSID='ywznet', PASS='******'):
     self.wifi_main(SSID, PASS)
     self.s1 = None
     self.uart = UART(2, baudrate=9600, rx=16, tx=17)
コード例 #20
0
def enable_console_on_serial():
    """Enable REPL on USB serial connection"""
    global uart
    uart = UART(0, 115200)
    os.dupterm(uart)
コード例 #21
0
# REPL duplication on UART0 for serial connection
from machine import UART
import os
uart = UART(0, 115200)
os.dupterm(uart)
コード例 #22
0
 def __init__(self, uart=0):
     self.uart = UART(uart)
     self.uart.init(9600, bits=8, parity=None, stop=1, rxbuf=64)
     self.setmode(self.active)
コード例 #23
0
def main():
  global time_last_update   #variable important to OTA time update
  global switch_ap
  time_last_update = 0
  time_tick_send_message = 60
  time_sleep_across_measure = 0.8
  struct_message = '6.60.6.1.1.1' ####"V.I.P.E.F.FP"
  struct_message = Create_struct_message(struct_message,time_tick_send_message)
  url='https://github.com/Yoendric/checkinwattHandleInterruption'   #Github repository project
  o = OTAUpdater(url)
  led = Pin(14, Pin.OUT)
  led.value(1)
  wifi = Pin(4, Pin.OUT)
  pir = Pin(25, Pin.IN)
  pir.irq(trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING, handler=handle_interrupt)
  uart = UART(2, baudrate=9600, tx=26,rx=27)# init with given baudrate
  uart.init(9600, bits=8, parity=None, stop=1) # init with given parameters
  # Azure IoT-hub settings
  hostname = "checkinwattsiothub.azure-devices.net"
  device_id = ubinascii.hexlify(network.WLAN().config('mac'),':').decode()
  device_id = device_id.upper()
  uri = "{hostname}/devices/{device_id}".format(hostname=hostname, device_id=device_id)
  username_fmt = "{}/{}/?api-version=2018-06-30"
  key="XxXK7Pun5XQa/NqUsGBmXBKI4euLUcU/72bjxuPr+jE="
  username = username_fmt.format(hostname, device_id)
  switch_ap = False
  ssid,passw=Get_Client_Wifi_Parameters()
  if pir.value() == 1:
    switch_ap = True
  while True:
    if switch_ap:
      print('Interrupt AP detected!')
      wifi.value(0)
      led.value(1)
      ssid , passw = ap_mode()
      while switch_ap:
        Blinky_LED(wifi)
    else:
      print('Modo cliente')
      wifi.value(1)
      if (ssid and passw):
        Connect_wifi_client(ssid,passw)
        download_and_install_update_if_available(url,ssid,passw)
        Adjustment_Time_RTC(-6)
        password = Sas_token(uri,key)
        while (not switch_ap):
          if check_time_update_github(time_last_update):
            try:
              o.check_for_update_to_install_during_next_reboot()
              time_last_update=time.mktime(time.localtime())
            except:
              print("NO SE PUEDE CONECTAR PARA VER SI HAY ACTUALIZACION")
          f0 = ""
          f1 = f0
          MSG_TXT = '{{"ID": "{version}","F0": "{f0}","F1": "{f1}"}}'
          seg = 1
          while (seg <= time_tick_send_message) and (not switch_ap):
            led.value(seg%2)
            f0=Read_PZEM(uart,f0,seg,struct_message,1) 
            f1=Read_PZEM(uart,f1,seg,struct_message,1)
            sleep(time_sleep_across_measure)   
            seg = seg + 1
          if (not switch_ap):
            msg_txt_formatted = MSG_TXT.format(version=version, f0=f0,f1=f1) 
            print ("Message ready to ship to IoT Hub Azure") 
            print (msg_txt_formatted)
            #iot_hub_mqttsend(device_id, hostname,username,password,msg_txt_formatted)
      else:
        sleep(1)
コード例 #24
0
ファイル: main.py プロジェクト: AbelJimenezR/ProjecteIoT
import time
import socket
import config
import tools

# Inicia bus I2C
i2c = I2C(0, I2C.MASTER, baudrate=100000)

# Inicia bme280
bme = bme280.BME280(i2c=i2c,address=0x76)

# Inicia ssd1306
oled = ssd1306.SSD1306_I2C(128, 64, i2c)

# Inicia GPS
com = UART(1,pins=(config.TX, config.RX),  baudrate=config.BAUDRATE)
my_gps = MicropyGPS()


DEBUG = config.DEBUG



# Initialize LoRa in LORAWAN mode.
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868)

# create an ABP authentication params
dev_addr = config.DEV_ADDR
nwk_swkey = config.NWK_SWKEY
app_swkey = config.APP_SWKEY
コード例 #25
0
ファイル: BT_Test.py プロジェクト: autecla/Control_Module
#****************************************************************************************************************************
#   --------------------------------------------------------------------------------------------------------------------
#   @Autecla: Send data to APP
#   Sketch/program to send data from Control_Module to APP using an external Bluetooth connected on UART(1)
#   Tip: To test this program, you can use Bluetooth terminal on your smartphone to connect to HC-06
#
#   ESP32 <--> BT HC-06
#   Ports:
#      Pin_RX = TX2
#      Pin_TX = RX2
#   --------------------------------------------------------------------------------------------------------------------
#****************************************************************************************************************************
from machine import UART
import time

urt = UART(1, 9600)
urt.init(9600, bits=8, parity=None, stop=1, tx=2, rx=4)
i = 12
while True:
    #This part is to receive data from smartphone
    if (urt.any()):
        dados = urt.readline()
        print('Dado:', dados)
コード例 #26
0
 def detect_modem_state(self, retry=5, initial_delay=1000, hangup=True, debug=False):
     count = 0
     self.__serial = UART(1, baudrate=921600, pins=self.__pins, timeout_chars=1)
     self.__modem_speed = 921600
     self.__serial.read()
     while count < retry:
         count += 1
         delay = initial_delay * count
         if debug: print("The current delay is {}".format(delay))
         self.__serial = UART(1, baudrate=921600, pins=self.__pins, timeout_chars=10)
         self.__modem_speed = 921600
         #if True:
         if hangup and self.__hangup_modem(initial_delay, debug):
             self.__speed_detected = True
             self.__serial.write(b"AT+SMOD?\r\n")
             time.sleep_ms(delay)
             resp = self.__serial.read()
             if debug: print('Response (AT+SMOD?) {}'.format(resp))
             try:
                 return self.return_code(resp, debug)
             except:
                 pass
         else:
             self.__modem_speed = 921600
             self.__serial = UART(1, baudrate=921600, pins=self.__pins, timeout_chars=1)
             self.__serial.read()
             self.__serial.write(b"AT\r\n")
             time.sleep_ms(delay)
             resp = self.__serial.read()
             self.__check_resp(resp)
             if debug: print('Response (AT #3) {}'.format(resp))
             if resp is not None and b'OK' in resp:
                 self.__speed_detected = True
                 self.__serial.write(b"AT+SMOD?\r\n")
                 time.sleep_ms(delay)
                 resp = self.__serial.read()
                 try:
                     if debug: print('Response (AT+SMOD?) {}'.format(resp))
                     return self.return_code(resp, debug)
                 except:
                     pass
             self.__serial.write(b"AT\r\n")
             time.sleep_ms(delay)
             resp = self.__serial.read()
             self.__check_resp(resp)
             if debug: print('Response (AT #4) {}'.format(resp))
             if resp is not None and b'OK' in resp:
                 self.__speed_detected = True
                 self.__serial.write(b"AT+SMOD?\r\n")
                 time.sleep_ms(delay)
                 resp = self.__serial.read()
                 try:
                     return self.return_code(resp, debug)
                     if debug: print('Response (AT+SMOD?) {}'.format(resp))
                 except:
                     pass
             else:
                 if not self.__resp_921600:
                     self.__modem_speed = 115200
                     self.__serial = UART(1, baudrate=115200, pins=self.__pins, timeout_chars=10)
                     self.__serial.write(b"AT\r\n")
                     time.sleep_ms(delay)
                     resp = self.__serial.read()
                     if debug: print('Response (AT #1 @ 115200) {}'.format(resp))
                     if resp is not None and b'OK' in resp:
                         self.__speed_detected = True
                         self.__serial.write(b"AT+SMOD?\r\n")
                         time.sleep_ms(delay)
                         resp = self.__serial.read()
                         try:
                             if debug: print('Response (AT+SMOD?) {}'.format(resp))
                             return self.return_code(resp, debug)
                         except:
                             pass
                     self.__serial.write(b"AT\r\n")
                     time.sleep_ms(delay)
                     resp = self.__serial.read()
                     if debug: print('Response (AT #2 @ 115200) {}'.format(resp))
                     if resp is not None and b'OK' in resp:
                         self.__speed_detected = True
                         self.__serial.write(b"AT+SMOD?\r\n")
                         time.sleep_ms(delay)
                         resp = self.__serial.read()
                         try:
                             if debug: print('Response (AT+SMOD?) {}'.format(resp))
                             return self.return_code(resp, debug)
                         except:
                             pass
     return None
コード例 #27
0
        return int(1023 / 10 * 3)
    elif touchPad_H.read() < 200:
        return int(1023 / 10 * 4)
    elif touchPad_O.read() < 200:
        return int(1023 / 10 * 5)
    elif touchPad_N.read() < 200:
        return int(1023 / 10 * 6)
    else:
        return 0


while scratchMode:
    display.Bitmap(40, 10, scratchlogo, 48, 48, 1)
    display.show()

    uart = UART(1, 38400, rx=3, tx=1)

    # Create and send Scratch data packet
    def convert(a, b):
        sensor = bytearray(2)
        upper = (b & 0x380) >> 7
        sensor[1] = b & 0x7f
        sensor[0] = (1 << 7) | a << 3 | upper
        uart.write(sensor)

    request = bytearray(1)

    while True:

        if uart.readinto(
                request) == 1 and request[0] == 0x01:  #当接收到scratch发来的0x01字节
コード例 #28
0
 def get_imei(self):
     self.__serial = UART(1, baudrate=921600, pins=self.__pins, timeout_chars=10)
     self.__serial.write(b"AT+CGSN\r\n")
     time.sleep(.5)
     imei_val = self.read_rsp(2000)
     return self.return_pretty_response(imei_val)
コード例 #29
0
# Simple GPS module demonstration.
# Will wait for a fix and print a message every second with the current location
# and other details.
from machine import UART
import utime as time

import adafruit_gps

# Create a GPS module instance.
#uart = UART(1, baudrate=9600, timeout_chars=3000, pins=('P8','P2'))
uart = UART(2, baudrate=9600)
uart.init()

# Create a GPS module instance.
gps = adafruit_gps.GPS(uart)

# Initialize the GPS module by changing what data it sends and at what rate.
# These are NMEA extensions for PMTK_314_SET_NMEA_OUTPUT and
# PMTK_220_SET_NMEA_UPDATERATE but you can send anything from here to adjust
# the GPS module behavior:
#   https://cdn-shop.adafruit.com/datasheets/PMTK_A11.pdf

# Turn on the basic GGA and RMC info (what you typically want)
gps.send_command('PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
# Turn on just minimum info (RMC only, location):
#gps.send_command('PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
# Turn off everything:
#gps.send_command('PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
# Tuen on everything (not all of it is parsed!)
#gps.send_command('PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0')
コード例 #30
0
from machine import UART
import time
import uos
u = UART(0, 115200)
u.init(115200, bits=8, parity=None, stop=1)

u.write("\nstart  \n")
dir = uos.listdir()
for str in dir:
    u.write(str)
    u.write('  \n')
    time.sleep(0.2)