| | 9 | |
| | 10 | == Tiny 2040 の動作ログ |
| | 11 | |
| | 12 | {{{ |
| | 13 | >>> import sys |
| | 14 | >>> sys.implementation |
| | 15 | (name='micropython', version=(1, 19, 0), _machine='Pimoroni Tiny 2040 with RP2040', _mpy=4102) |
| | 16 | >>> help() |
| | 17 | Welcome to MicroPython! |
| | 18 | |
| | 19 | For online help please visit https://micropython.org/help/. |
| | 20 | |
| | 21 | For access to the hardware use the 'machine' module. RP2 specific commands |
| | 22 | are in the 'rp2' module. |
| | 23 | |
| | 24 | Quick overview of some objects: |
| | 25 | machine.Pin(pin) -- get a pin, eg machine.Pin(0) |
| | 26 | machine.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p |
| | 27 | methods: init(..), value([v]), high(), low(), irq(handler) |
| | 28 | machine.ADC(pin) -- make an analog object from a pin |
| | 29 | methods: read_u16() |
| | 30 | machine.PWM(pin) -- make a PWM object from a pin |
| | 31 | methods: deinit(), freq([f]), duty_u16([d]), duty_ns([d]) |
| | 32 | machine.I2C(id) -- create an I2C object (id=0,1) |
| | 33 | methods: readfrom(addr, buf, stop=True), writeto(addr, buf, stop=True) |
| | 34 | readfrom_mem(addr, memaddr, arg), writeto_mem(addr, memaddr, arg) |
| | 35 | machine.SPI(id, baudrate=1000000) -- create an SPI object (id=0,1) |
| | 36 | methods: read(nbytes, write=0x00), write(buf), write_readinto(wr_buf, rd_buf) |
| | 37 | machine.Timer(freq, callback) -- create a software timer object |
| | 38 | eg: machine.Timer(freq=1, callback=lambda t:print(t)) |
| | 39 | |
| | 40 | Pins are numbered 0-29, and 26-29 have ADC capabilities |
| | 41 | Pin IO modes are: Pin.IN, Pin.OUT, Pin.ALT |
| | 42 | Pin pull modes are: Pin.PULL_UP, Pin.PULL_DOWN |
| | 43 | |
| | 44 | Useful control commands: |
| | 45 | CTRL-C -- interrupt a running program |
| | 46 | CTRL-D -- on a blank line, do a soft reset of the board |
| | 47 | CTRL-E -- on a blank line, enter paste mode |
| | 48 | |
| | 49 | For further help on a specific object, type help(obj) |
| | 50 | For a list of available modules, type help('modules') |
| | 51 | >>> |
| | 52 | >>> from machine import Pin |
| | 53 | >>> r = Pin(18, Pin.OUT) |
| | 54 | >>> g = Pin(19, Pin.OUT) |
| | 55 | >>> b = Pin(20, Pin.OUT) |
| | 56 | >>> r,g,b |
| | 57 | (Pin(18, mode=OUT), Pin(19, mode=OUT), Pin(20, mode=OUT)) |
| | 58 | >>> r.on() |
| | 59 | >>> g.on() |
| | 60 | >>> b.on() |
| | 61 | >>> r.off() |
| | 62 | >>> g.off() |
| | 63 | >>> b.off() |
| | 64 | >>> |
| | 65 | >>> r.value() |
| | 66 | 0 |
| | 67 | >>> g.value() |
| | 68 | 0 |
| | 69 | >>> b.value() |
| | 70 | 0 |
| | 71 | >>> |
| | 72 | }}} |
| | 73 | |
| | 74 | [KhoPyboard PyBoard一覧に戻る] |