Esempio n. 1
0
def main():
    pkt_tx_queue = []

    def audio_frame_ready(data):
        pkt_tx_queue.append(data)

    lora_ctl = lora.LoRaController()
    spk = speaker.Speaker(DAC('P22'))
    adc = ADC()
    apin = adc.channel(pin='P13', attn=ADC.ATTN_11DB)
    uphone = microphone.Microphone(apin, audio_frame_ready)
    tlk_btn = talk_button.TalkButton(uphone)

    print('Started ...')
    flash(0x007f00)  # green

    while True:
        Timer.sleep_us(1000)

        # Handle the RX packets
        # TODO: refactor to use callback mechanism.
        while True:
            data = lora_ctl.recv()
            if data:
                spk.enque(data)
            else:
                break

        # Handle the TX queue
        # TODO: refactor to use Python synchronized Queue.
        while pkt_tx_queue:
            data = pkt_tx_queue.pop(0)
            print('.')
            lora_ctl.send(data)
Esempio n. 2
0
def flash(color, delay_us=100000):
    """Generate a 100ms of flash on RGB LED.

  Args:
    color: int
  """
    pycom.heartbeat(False)
    pycom.rgbled(color)
    Timer.sleep_us(delay_us)
    pycom.rgbled(0x000000)  # off
Esempio n. 3
0
def MonitorFlow():  # 1Litre = 596 pulses
    TotalDelay = 0
    TickCounter = 0
    PulseLogic = _FlowMeter()
    while (TotalDelay < 1000000):  # 1 second delay
        Reading = _FlowMeter()
        if ((Reading > PulseLogic)):  # rising edge
            TickCounter += 1
        PulseLogic = Reading
        TotalDelay += 50
        Timer.sleep_us(50)
    LitresPerMinute = round((TickCounter / 10), 2)
    return LitresPerMinute  # Litres/Min
Esempio n. 4
0
def audio_loopback():
    def handle_audio(data):
        spk.enque(data)

    int_mode = False
    spk = speaker.Speaker(DAC('P22'), int_mode=int_mode, debug=False)
    adc = ADC()
    apin = adc.channel(pin='P13', attn=ADC.ATTN_11DB)
    uphone = microphone.Microphone(apin, handle_audio, int_mode=int_mode)
    tlk_btn = talk_button.TalkButton(uphone)

    print('Audio playpack ...')
    flash(0x000010)  # Dark blue

    while True:
        if int_mode:
            Timer.sleep_us(1000000)
        else:
            uphone.loop()
            spk.loop()
Esempio n. 5
0
 def ClockIn(self, RS_State):  # RS_State is either 1 or 0
     RS_State = RS_State << 1  # RS is on bit 1
     ClkOff = 0x00  # clock is on bit 0
     ClkOn = 0x01
     self.MCP23S17Ref.WritePortB(ClkOff | RS_State)
     Timer.sleep_us(1)
     self.MCP23S17Ref.WritePortB(ClkOn | RS_State)
     Timer.sleep_us(1)
     self.MCP23S17Ref.WritePortB(ClkOff | RS_State)
     Timer.sleep_us(100)
Esempio n. 6
0
 def __init__(self, LCD_SPI_Object, LCD_SPI_CS):
     self.MCP23S17Ref = MCP23S17Backend(LCD_SPI_Object, LCD_SPI_CS)
     Timer.sleep_us(50000)
     self.InitFunctionSet()
     Timer.sleep_us(4500)
     self.InitFunctionSet()
     Timer.sleep_us(200)
     self.InitFunctionSet()
     # now set the properties you want
     self.FunctionSet()
     self.DisplayOnOff()
     self.ClearScreen()
     self.EntryModeSet()
Esempio n. 7
0
 def ClearScreen(self):  # D7 -> 00000001 <- D0 (0x01)
     self.MCP23S17Ref.WritePortA(0x01)
     self.ClockIn(0)
     Timer.sleep_us(2000)
Esempio n. 8
0
 def tx_waveform(self, high_pulse, low_pulse):
     self.tx_pin.value(1)
     Timer.sleep_us(high_pulse)
     self.tx_pin.value(0)
     Timer.sleep_us(low_pulse)
Esempio n. 9
0
from machine import Timer

start = 0
end = 0

p_light = Pin('P20', mode=Pin.OUT)
p_light.value(1)

p_trig = Pin("G30", mode=Pin.OUT)  # Trig = 30
p_echo = Pin("G31", mode=Pin.IN)  # Echo = 31

chrono = Timer.Chrono()
chrono.reset()

p_trig.value(1)
Timer.sleep_us(10)
p_trig.value(0)

while (p_echo.value() == 0):
    start = chrono.read_us()
    print(start)

while (p_echo.value() == 1):
    end = chrono.read_us()
    print(end)

chrono.stop()

print(start, end)
'''
while(True):
Esempio n. 10
0
        else:
            Irrigation_Delay_Count = Irrigation_Delay_Count - 1
    else:
        if (Irrigation_Delay_Count == 0):
            Solenoid_Status = False
            Irrigation_Delay_Count = Irrigation_Delay_Sec_Off
        else:
            Irrigation_Delay_Count = Irrigation_Delay_Count - 1

    # Status Control
    LCD_Status_String = ""
    if (Solenoid_Status == False):  # off status
        pycom.rgbled(0xff0000)  # red
        _Solenoid(True)  # hardware buffer inverts logic
        LCD_Status_String = "(off)"
    else:
        pycom.rgbled(0x00ff00)  # green
        _Solenoid(False)  # hardware buffer inverts logic
        LCD_Status_String = "(on)"

    # LCD Updater
    Delay_Count_Hours, Remain = divmod(Irrigation_Delay_Count,
                                       3600)  # divide seconds into hours 60*60
    Delay_Count_Mins, Remain = divmod(
        Remain, 60)  # devide remaining seconds into minutes
    UpdateLCD(
        TimeStampString() + " " + LCD_Status_String,
        "Count: " + str(Delay_Count_Hours) + ":" + str(Delay_Count_Mins) +
        ":" + str(Remain))
    Timer.sleep_us(1000000)  # One Second Delay