Beispiel #1
0
    def __init__(self, rx, tx):
        self._uart = UART(baudrate=9600, rx=rx, tx=tx)

        # Perform self check
        if not self._check():
            ...  # TODO replace this with a buzz or something

        self._report()
Beispiel #2
0
class UARTSource(Observable):
    def __init__(self):
        super().__init__()
        self.uart = UART(board.TX, board.RX, baudrate=9600)

    def tick(self):
        self.emit(self.uart.read(self.uart.in_waiting))
Beispiel #3
0
class sms:
    def __init__(self, rx, tx):
        self._uart = UART(baudrate=9600, rx=rx, tx=tx)

        # Perform self check
        if not self._check():
            ...  # TODO replace this with a buzz or something

        self._report()

        # TODO indicate sim setup complete

    def _send(self, cmd: str) -> str:
        self._uart.write(bytes((cmd+"\r\n").encode("ascii")))
        sleep_ms(SEND_DELAY_MS)
        resp = self._uart.read()
        if resp is None:
            return ""
        return resp.decode("ascii")

    def _check(self) -> bool:
        if "ok" not in self._send("at"):
            return False
        if "error" in self._send("at+ccid"):
            return False
        if "error" in self._send("at+creg?"):
            return False
        return True

    # Report will send commands to the sim800l and collect the responses.
    # Then the responses will be sent via sms to the "owner"
    def _report(self):
        rep = ""
        rep += self._send("at+csq")  # signal strength
        rep += self._send("AT+COPS?")  # connected network
        rep += self._send("AT+CBC")  # lipo state
        self.send_msg(rep)

    def send_msg(self, msg: str):
        self._send("AT+CMGF=1")  # Text message mode
        self._send(f"AT+CMGS=\"{OWNER_NUMBER}\"")
        self._send(msg)
        self._uart.write(bytes(chr(26)))

    def recv_msg(self) -> str:
        self._send("AT+CMGF=1")  # Text message mode
        self._send("AT+CNMI=1,2,0,0,0")  # Send text message over uart
        resp = ""
        while resp == "" or "+CMT" not in resp:
            resp = self._uart.read()
            if resp == None:
                resp = ""
        
        msg = resp.decode("ascii")
        words = msg.split("\r\n")
        return words[2]
Beispiel #4
0
import errno

BATTERY_CUTOFF_LIPO = 3.2

#import pcf8563
#if RTC_present:
#    rtc = pcf8563.PCF8563(i2c)
# print("RTC = ", rtc.now())
#else:
#    if supervisor.runtime.serial_connected:
#      print("No RTC")

if GNSS_present:
    from adafruit_gps import GPS
    uart_gps = UART(SOC_GPIO_PIN_SWSER_TX,
                    SOC_GPIO_PIN_SWSER_RX,
                    baudrate=9600,
                    timeout=30)
    gps = GPS(uart_gps, debug=False)
    # RMC + GGA
    gps.send_command(b"PGKC242,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0")
    sleep(0.2)
    gps.send_command(b"PGKC115,1,1,0,0")  # GPS + GLONASS
    # gps.send_command(b"PGKC115,1,0,1,0")   # GPS + BEIDOU

import adafruit_bme280
if BME_present:
    bme = adafruit_bme280.Adafruit_BME280_I2C(i2c)
else:
    if supervisor.runtime.serial_connected:
        print("No BMx280 sensor")
Beispiel #5
0
        state = struct.unpack(NVM_STATE_FORMAT, microcontroller.nvm[0:NVM_STATE_LENGTH])
        print("state: {}".format(state))
        return state
    except Exception as ex:
        print("Unable to load controller state. {}.".format(ex))
        return 0, 0


def save_controller_state(state):
    try:
        microcontroller.nvm[0:NVM_STATE_LENGTH] = struct.pack(NVM_STATE_FORMAT, state[0], state[1])
    except Exception as ex:
        print("Unable to save controller state. {}.".format(ex))


with I2C(SCL, SDA, frequency=100000) as i2c, UART(TX, RX, baudrate=115200) as uart:
    try:
        # Initialise random
        random.seed(time.monotonic_ns())

        # Setup the rotary encoders
        enc_left = Encoder(i2c, 0x78)
        enc_right = Encoder(i2c, 0x70)

        # Set the encoder LEDs to amber whilst we set-up
        enc_left.led_color(Encoder.LED_AMBER)
        enc_right.led_color(Encoder.LED_AMBER)

        # Setup the valves
        valve_left = Valve(D2)
        valve_right = Valve(D3)
Beispiel #6
0
import board
from busio import UART
import utime

FONA_BAUD = 4800

uart = UART(board.D0, board.D2,
            baudrate=FONA_BAUD)  # for UART2 on esp32 dev board, RX:16, TX:17
uart.init(FONA_BAUD)

# clear the buffer
for i in range(3):
    uart.readline()

# check replies
for i in range(10):
    message = "AT"
    uart.write(message + '\r\n')  # \r and \n seem necessary
    print(">>\n" + message)
    utime.sleep(.1)
    response = uart.read().decode('ascii')
    print("<<")
    print(response.split())
    utime.sleep(.1)