Пример #1
0
    def scan_as(q):        
        base = 0x00
        max_a = 16*16*16
        ass = range(0, max_a)
        q.lcd_a = None
        q.ass = []

        print('Scanning {} addresses'.format(len(ass)))
        for offset in ass:
            a = base + offset
            #print('0x{:02X}'.format(a))
            try:
                q.i2c.send(0, addr=a)
                q.i2c.send(0, addr=a)
                print('Address without error: 0x{:02X}'.format(a))
                q.ass.append(a)
            except Exception as ex:
                #print('Some error occured! \n{}'.format(str(ex)))
                pass
            
        if len(q.ass) > 0:
            print('Responsive addresses < {}:\n{}'.format(max_a, 
                ['0x{:02X}'.format(a) for a in q.ass]))
            q.lcd_a = q.ass[0]

            #print(os.listdir())
            with open(q.file_as, 'w') as f:
                f.write(q.lcd_a)
                print('Responsive address 0x{0:02X} = {0} dec, saved to file {1}.'.format(q.lcd_a, q.file_as))

            #print(os.listdir())
#            gc.collect()
            pyb.sync()
        else:
            print('No responsive address found!')
Пример #2
0
    def scan_br(q):
        q.brs = []   
        br_num = 1
        brs = [50, 100, 200, 250, 400,500,800]
        brs = [br*1000 for br in brs]
        brs = range(115200, 9600, -100)
#            brs = range(9600, 115200, 400)    

        print('Scanning {} baudrates'.format(len(brs)))
        for br in brs:
#                br = br
            print(br)
            q.i2c.init(I2C.MASTER,  addr=q.addr, baudrate=br)
            scan = q.i2c.scan()
    #        print(scan)
            if len(scan) > 0:
                print('New functional baudrate {}'.format(br))
                q.brs.append(br)
                if len(q.brs) >= br_num:
                    break
        print('{} functional baudrates < than 115201:\n{}'.format(
            br_num, q.brs))
        q.br = q.brs[-1]
        
        with open(q.file_br, 'w') as f:
            f.write(str(q.br))
            print('Functional baudrate {}, saved to file {}.'.format(
                    q.br, q.file_br))
        pyb.sync()
Пример #3
0
def DistIRloop(msdelay=20):
    red_led = pyb.LED(1)
    green_led = pyb.LED(2)
    orange_led = pyb.LED(3)
    blue_led = pyb.LED(4)
    orange_led.on()
    userswitch = pyb.Switch()
    while not userswitch():
        pyb.delay(100)
    orange_led.off()
    green_led.on()
    pyb.delay(1000)
    datalogfilename = '/sd/distirlog.csv'
    log = open(datalogfilename, 'a')
    log.write("t (s), d (cm)\n")
    green_led.off()
    blue_led.on()
    initialtimems = pyb.millis()
    while not userswitch():
        adcint = pyb.ADC(pyb.Pin('X4')).read()
        times = ((pyb.millis()) - initialtimems) / 1000
        adcv = (adcint * 3.3 / 4095)
        dcm = (9.89703 / (adcv - 0.0189332))**(1 / 0.734319
                                               )  # (A/(v-v0))^(1/B)
        print("%f s, %f cm" % (times, dcm))
        log.write("%f, %f\n" % (times, dcm))
        pyb.delay(msdelay)
    log.close()
    pyb.sync()
    blue_led.off()
    red_led.on()
Пример #4
0
def DistIRloop(msdelay=20):
    red_led = pyb.LED(1)
    green_led = pyb.LED(2)
    orange_led = pyb.LED(3)
    blue_led = pyb.LED(4)
    orange_led.on()
    fbuf.fill(0)
    fbuf.text('Tecle USR', 25, 20, lcd.rgb(255, 255, 0))
    lcd.show_framebuf(fbuf)
    userswitch = pyb.Switch()
    while not userswitch():
        pyb.delay(100)
    orange_led.off()
    green_led.on()
    fbuf.text('Preparando...', 10, 50, lcd.rgb(0, 255, 0))
    lcd.show_framebuf(fbuf)
    pyb.delay(1000)
    datalogfilename = '/sd/distirlog.csv'
    log = open(datalogfilename, 'a')
    log.write("t (s), d (cm)\n")
    green_led.off()
    blue_led.on()
    fbuf.text('Medindo...', 15, 80, lcd.rgb(0, 255, 255))
    lcd.show_framebuf(fbuf)
    #    pyb.delay(3000)
    gc.collect()
    initialtimems = pyb.millis()
    while not userswitch():
        adcint = pyb.ADC(pyb.Pin('X4')).read()
        times = ((pyb.millis()) - initialtimems) / 1000
        adcv = (adcint * 3.3 / 4095)
        dcm = (9.89703 / (adcv - 0.0189332))**(1 / 0.734319
                                               )  # (A/(v-v0))^(1/B)
        #print("%f s, %f cm" % (times, dcm))
        log.write("%f, %f\n" % (times, dcm))
        pyb.delay(msdelay)
    log.close()
    pyb.sync()
    blue_led.off()
    red_led.on()
    fbuf.text('Fim !', 35, 110, lcd.rgb(255, 0, 0))
    lcd.show_framebuf(fbuf)
Пример #5
0
def writeLog(rtc, temp, hum):
    """Append a line with the current timestamp to the log file"""
    datetime=rtc.datetime()
    timestamp = ("%04d-%02d-%02d %02d:%02d:%02d" % (datetime[0],
    datetime[1], datetime[2], datetime[4], datetime[5], datetime[6]))
    logline = ("%s %s %s" % (timestamp, temp, hum))
    #print(logline)
    try:
        with open("logdata.txt", "a") as f:
            f.write("%s\n" % logline)
            f.close()
            pyb.sync()
    except:
        pass
    try:
        with open("/flash/logdata.txt", "a") as f:
            f.write("%s\n" % logline)
            f.close()
            pyb.sync()

    except OSError as error:
        print("Error: can not write to SD card. %s" % error)
Пример #6
0
def rec():
    h = MAX30100(sample_rate=SAMPLE_RATE[100], pulse_width=PULSE_WIDTH[1600])

    with open("/sd/pulse_max30100.csv", "w") as f:
        first = True

        g = h.generator(delay=8)  # 10ms <> 100sps
        # med = median_filter(g,15)
        bw = butterworth_filter(g)

        norm = norm_filter(bw, size=100)
        diff = diff_filter(norm, size=20)
        th = thresh_filter(diff, threshold=-.33, greater_than=False)
        # th = hysteresis_filter(bw,size=100,th_high=.7,th_low=.3)

        bpm = bpm_filter(th, size=3)

        for s, v, h in bpm:
            if first:
                col_names = ",".join(h.keys())
                f.write("%s\n" % col_names)
                first = False

            print(h)
            s = ','.join([str(v) for v in h.values()])
            f.write("%s\n" % s)

            if h['thresh']:
                pyb.LED(1).on()
            else:
                pyb.LED(1).off()
            # lcd.clear()
            # lcd.write(str(h))
            # if keys.read() is not 'none':
            #     break
        f.close()
        pyb.sync()
Пример #7
0
    try:
        with open("/sd/sd_check.vars",  "r") as vars_file:
            vars = vars_file.read().split()
    except:
        pass
    hard_reset_count = int(vars[0])
    soft_reset_count = int(vars[1])
    print("### hard_reset_count = %d, soft_reset_count = %d ###" % (hard_reset_count, soft_reset_count))
    hard_reset = 0
    if soft_reset_count % 40 == 0:
        hard_reset = 1
    soft_reset_count += 1
    hard_reset_count += hard_reset
    with open("/sd/sd_check.vars",  "w") as vars_file:
        vars_file.write('%d %d ' % (hard_reset_count, soft_reset_count))
    pyb.sync()
    vcp = pyb.USB_VCP()
    if vcp.any():
        print("Key press detected on USB - stopping")
    else:
        uart = pyb.UART(6, 115200)
        if uart.any():
            print("Key press detected on USB - stopping")
        else:
            pyb.delay(100)
            if hard_reset:
                pyb.hard_reset()
            pyb.soft_reset()
else:
    print('##############################################################')
    print('##############################################################')
Пример #8
0
print((pyb.millis() - start) // 5) # should print 3

# test udelay

pyb.udelay(-1)
pyb.udelay(0)
pyb.udelay(1)

start = pyb.millis()
pyb.udelay(17000)
print((pyb.millis() - start) // 5) # should print 3

# other

pyb.disable_irq()
pyb.enable_irq()

print(pyb.freq())

print(pyb.have_cdc())

pyb.hid((0, 0, 0, 0)) # won't do anything

pyb.rng()

pyb.sync()

print(len(pyb.unique_id()))

pyb.wfi()
Пример #9
0
def reset():
    pyb.sync()
    machine.soft_reset()