Conversion code from pyboard



  • Hi,
    I use the following code on my pyboard:

    import array
    import pyb
    import utime
    import time

    time.sleep(2)

    adc1=pyb.ADC(pyb.Pin.board.Y12)
    buf1=array.array('H',bytearray(40000))
    tim=pyb.Timer(6, freq=2000)
    adc1.read_timed(buf1,tim)

    with open('chanel1.dash','w') as f:
    for val in buf1:
    s1 = str(val)
    f.write(s1+'\n')

    And I want to adapt it and apply it on my wipy.
    I wrote this:

    import array
    import time
    import os
    from machine import SD
    sd=SD()
    os.mount(sd,'/sd')

    time.sleep(2)

    from machine import ADC
    adc=ADC()
    adc1=adc.channel(pin='P13')

    buf1=array.array('H',bytearray(5000))

    from machine import Timer
    tim=Timer(6, mode=Timer.PERIODIC, width=32)
    tim.channel(Timer.A, freq=1000, polarity=Timer.POSITIVE)
    adc1.read_timed(buf1,tim)

    with open('/sd/chanel1.dash','w') as f:
    for val in buf1:
    s1 = str(val)
    f.write(s1+'\n')

    But it's not working... it tells me "cannot create Timer instance"(line 15)
    One of you may be know how to solve this ?
    And someone know what is the limit size that I can put for the buffer ? It seems like there is some problem of allocation as well.
    Also, I think that the 'read_timed' command doesn't exist for the Wipy..or at least I havn't seen it in the documentation

    Thank you




Log in to reply
 

Pycom on Twitter