diff --git a/content/firmwareapi/pycom/machine/pin.md b/content/firmwareapi/pycom/machine/pin.md index 9202859..7287781 100644 --- a/content/firmwareapi/pycom/machine/pin.md +++ b/content/firmwareapi/pycom/machine/pin.md @@ -28,7 +28,7 @@ p_in() # get value, 0 or 1 ## Constructors -#### class machine.Pin(id, ...) +### class machine.Pin(id, [mode=Pin.OUT, pull=None, alt]) Create a new Pin object associated with the string `id`. If additional arguments are given, they are used to initialise the pin. [See pin.init()](../pin#pin-init-mode-pull-alt) @@ -40,7 +40,7 @@ p = Pin('P10', mode=Pin.OUT, pull=None, alt=-1) ## Methods -#### pin.init(mode, pull, \* , alt) +### pin.init(mode, pull, * , alt) Initialise the pin: @@ -58,18 +58,19 @@ Initialise the pin: Returns: `None`. -#### pin.id() +### pin.id() Get the pin id. -#### pin.value(\[value\]) +### pin.value([value]) -Get or set the digital logic level of the pin: +Get or set the digital logic level of the pin. This only works in `Pin.OUT` mode. Values can be: +* `True` or 1: High +* `False`or 0: Low -* With no argument, return 0 or 1 depending on the logic level of the pin. -* With value given, set the logic level of the pin. value can be anything that converts to a boolean. If it converts to True, the pin is set high, otherwise it is set low. -#### pin(\[value\]) + +### pin([value]) Pin objects are callable. The call method provides a (fast) shortcut to set and get the value of the pin. @@ -84,25 +85,31 @@ pin() # fast method to get the value See `pin.value()` for more details. -#### pin.toggle() +### pin.toggle() Toggle the value of the pin. -#### pin.mode(\[mode\]) +### pin.mode([mode]) -Get or set the pin mode. +Get or set the pin mode. Modes can be: +* `Pin.IN` or 1 +* `Pin.OUT` or 2 +* `Pin.OPEN_DRAIN` or 7 -#### pin.pull(\[pull\]) +### pin.pull([pull]) -Get or set the pin pull. +Get or set the pin pull. Pull can be: +* `Pin.PULL_UP` +* `Pin.PULL_DOWN` +* None -#### pin.hold(\[hold\]) +### pin.hold([hold]) Get or set the pin hold. You can apply a hold to a pin by passing `True` (or clear it by passing `False`). When a pin is held, its value cannot be changed by using `Pin.value()` or `Pin.toggle()` until the hold is released. This Can be used to retain the pin state through a core reset and system reset triggered by watchdog time-out or Deep-sleep events. Only pins in the RTC power domain can retain their value through deep sleep or reset. These are: `P2, P3, P4, P6, P8, P9, P10, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22, P23` -#### pin.callback(trigger, handler=None, arg=None) +### pin.callback(trigger, [handler=None, arg=None]) Set a callback to be triggered when the input level at the pin changes. @@ -130,13 +137,12 @@ p_in = Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP) p_in.callback(Pin.IRQ_FALLING | Pin.IRQ_RISING, pin_handler) ``` -{{% hint style="info" %}} -For more information on how Pycom's products handle interrupts, see [here](/firmwareapi/notes#interrupt-handling). -{{% /hint %}} +>For more information on how Pycom's products handle interrupts, see [here](/firmwareapi/notes#interrupt-handling). + ## Attributes -#### class pin.exp\_board +### class pin.exp_board Contains all Pin objects supported by the expansion board. Examples: @@ -147,7 +153,7 @@ led = Pin(Pin.exp_board.G16, mode=Pin.OUT) Pin.exp_board.G16.id() ``` -#### class pin.module +### class pin.module Contains all `Pin` objects supported by the module. Examples: diff --git a/content/firmwareapi/pycom/machine/pwm.md b/content/firmwareapi/pycom/machine/pwm.md index fb3148e..a6c13b9 100644 --- a/content/firmwareapi/pycom/machine/pwm.md +++ b/content/firmwareapi/pycom/machine/pwm.md @@ -6,9 +6,7 @@ aliases: - chapter/firmwareapi/pycom/machine/pwm --- -## class PWM – Pulse Width Modulation - -### Quick Usage Example +## Quick Usage Example ```python @@ -19,23 +17,20 @@ pwm_c = pwm.channel(0, pin='P12', duty_cycle=0.5) pwm_c.duty_cycle(0.3) # change the duty cycle to 30% ``` -### Constructors +## Constructors -#### class machine.PWM(timer, frequency) +### class machine.PWM(timer, frequency) -Create a PWM object. This sets up the `timer` to oscillate at the specified `frequency`. `timer` is an integer from 0 to 3. `frequency` is an integer from 1 Hz to 78 KHz (this values can change in future upgrades). +Create a PWM object. This sets up the `timer` to oscillate at the specified `frequency`. `timer` is an integer from 0 to 3. `frequency` is an integer from 1 Hz to 78 KHz. -### Methods +## Methods -#### pwm.channel(id, pin \* , duty\_cycle=0.5) +### pwm.channel(id, pin, [duty_cycle=0.5]) Connect a PWM channel to a pin, setting the initial duty cycle. `id` is an integer from 0 to 7. `pin` is a string argument. `duty_cycle` is a keyword-only float argument, with values between 0 and 1. Returns an instance of `PWMChannel`. -## class PWMChannel — PWM channel -### Methods - -#### pwmchannel.duty\_cycle(value) +### pwmchannel.duty_cycle(value) Set the duty cycle for a PWM channel. `value` is a float argument, with values between 0 and 1. diff --git a/content/firmwareapi/pycom/machine/rtc.md b/content/firmwareapi/pycom/machine/rtc.md index d2c8b73..a131f38 100644 --- a/content/firmwareapi/pycom/machine/rtc.md +++ b/content/firmwareapi/pycom/machine/rtc.md @@ -21,7 +21,7 @@ print(rtc.now()) ## Constructors -#### class machine.RTC(id=0, ...) +### class machine.RTC([id=0, ...]) Create an RTC object. See init for parameters of initialisation. @@ -33,7 +33,7 @@ rtc = RTC(id=0) ## Methods -#### rtc.init(datetime=None, source=RTC.INTERNAL\_RC) +### rtc.init(datetime=None, [source=RTC.INTERNAL_RC]) Initialise the RTC. The arguments are: @@ -48,23 +48,11 @@ For example: rtc.init((2017, 2, 28, 10, 30, 0, 0, 0)) ``` -{{% hint style="info" %}} -`tzinfo` is ignored by this method. Use `time.timezone` to achieve similar results. -{{% /hint %}} +>`tzinfo` is ignored by this method. Use `time.timezone` to achieve similar results. -#### rtc.now() +### rtc.ntp_sync(server, [update_period=3600]) -Get get the current `datetime` tuple: - -```python - -# returns datetime tuple -rtc.now() -``` - -#### rtc.ntp\_sync(server, \* , update\_period=3600) - -Set up automatic fetch and update the time using NTP (SNTP). +Inits the RTC and sets up up automatic fetch and update the time using NTP (SNTP). * `server` is the URL of the NTP server. Can be set to `None` to disable the periodic updates. * `update_period` is the number of seconds between updates. Shortest period is 15 seconds. @@ -76,7 +64,18 @@ Can be used like: rtc.ntp_sync("pool.ntp.org") # this is an example. You can select a more specific server according to your geographical location ``` -#### rtc.synced() + +### rtc.now() + +Get get the current `datetime` tuple: + +```python + +# returns datetime tuple +rtc.now() +``` + +### rtc.synced() Returns `True` if the last `ntp_sync` has been completed, `False` otherwise: @@ -85,7 +84,7 @@ Returns `True` if the last `ntp_sync` has been completed, `False` otherwise: rtc.synced() ``` -#### rtc.memory(\[data\]) +### rtc.memory([data]) Reads RTC memory contents or write data in passed Buffer in to RTC memory diff --git a/content/firmwareapi/pycom/machine/sd.md b/content/firmwareapi/pycom/machine/sd.md index 434f72a..bc756a3 100644 --- a/content/firmwareapi/pycom/machine/sd.md +++ b/content/firmwareapi/pycom/machine/sd.md @@ -10,11 +10,10 @@ The SD card class allows to configure and enable the memory card module of your `P8: DAT0`, `P23: SCLK` and `P4: CMD` (no external pull-up resistors are needed) -If you have one of the Pycom expansion boards, then simply insert the card into the micro SD socket and run your script. +If you have one of the Pycom expansion boards, then simply insert the card into the micro SD socket and run your script. + +> Make sure your SD card is formatted either as FAT16 or FAT32. -{{% hint style="info" %}} -Make sure your SD card is formatted either as FAT16 or FAT32. -{{% /hint %}} ## Quick Example Usage: @@ -40,20 +39,19 @@ f.close() ## Constructors -#### class machine.SD(id, ...) +### class machine.SD(id, ...) -Create a SD card object. See [`sd.init()`](../sd#sd-init-id-0) for parameters if initialisation. +Create a SD card object. See `sd.init()` for parameters. ## Methods -#### sd.init(id=0) +### sd.init([id=0]) Enable the SD card. -#### sd.deinit() +### sd.deinit() Disable the SD card. -{{% hint style="info" %}} -Please note that the SD card library currently supports FAT16/32 formatted SD cards up to 32 GB. Future firmware updates will increase compatibility with additional formats and sizes. -{{% /hint %}} +> Please note that the SD card library currently supports FAT16/32 formatted SD cards up to 32 GB. Future firmware updates will increase compatibility with additional formats and sizes. + diff --git a/content/firmwareapi/pycom/machine/spi.md b/content/firmwareapi/pycom/machine/spi.md index 6576c34..65ff055 100644 --- a/content/firmwareapi/pycom/machine/spi.md +++ b/content/firmwareapi/pycom/machine/spi.md @@ -50,13 +50,13 @@ spi.write_readinto(bytes([0x01, 0x02, 0x03, 0x04, 0x05]), rbuf) # send a receive ## Constructors -#### class machine.SPI(id, ...) +### class machine.SPI(id, ...) Construct an SPI object on the given bus. `id` can be only 0. With no additional parameters, the SPI object is created but not initialised (it has the settings from the last initialisation of the bus, if any). If extra arguments are given, the bus is initialised. See init for parameters of initialisation. ## Methods -#### spi.init(mode, baudrate=1000000, \* , polarity=0, phase=0, bits=8, firstbit=SPI.MSB, pins=(CLK, MOSI, MISO)) +### spi.init(mode, [baudrate=1000000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB, pins=(CLK, MOSI, MISO)]) Initialise the SPI bus with the given parameters: @@ -68,23 +68,23 @@ Initialise the SPI bus with the given parameters: * `firstbit` can be SPI.MSB or SPI.LSB. * `pins` is an optional tuple with the pins to assign to the SPI bus. If the pins argument is not given the default pins will be selected (`P10` as CLK,`P11` as MOSI and `P14` as MISO). If pins is passed as None then no pin assignment will be made. -#### spi.deinit() +### spi.deinit() Turn off the SPI bus. -#### spi.write(buf) +### spi.write(buf) Write the data contained in `buf`. Returns the number of bytes written. -#### spi.read(nbytes, \* , write=0x00) +### spi.read(nbytes , [write=0x00]) Read the `nbytes` while writing the data specified by `write`. Returns the bytes read. -#### spi.readinto(buf, \* , write=0x00) +### spi.readinto(buf, [write=0x00]) Read into the buffer specified by `buf` while writing the data specified by `write`. Return the number of bytes read. -#### spi.write\_readinto(write\_buf, read\_buf) +### spi.write_readinto(write_buf, read_buf) Write from `write_buf` and read into `read_buf`. Both buffers must have the same length. Returns the number of bytes written diff --git a/content/firmwareapi/pycom/machine/timer.md b/content/firmwareapi/pycom/machine/timer.md index bb3fcd6..37b5c1f 100644 --- a/content/firmwareapi/pycom/machine/timer.md +++ b/content/firmwareapi/pycom/machine/timer.md @@ -18,13 +18,13 @@ These two concepts are grouped into two different subclasses: You can create as many of these objects as needed. {{% /hint %}} -### Constructors +## Constructors -#### class Timer.Chrono() +### class Timer.Chrono() Create a chronometer object. -#### class Timer.Alarm(handler=None, s, \* , ms, us, arg=None, periodic=False) +### class Timer.Alarm([handler=None, {s, ms, us}, arg=None, periodic=False]) Create an Alarm object. @@ -35,7 +35,7 @@ Create an Alarm object. ### Methods -#### Timer.sleep\_us() +### Timer.sleep_us() Delay for a given number of microseconds, should be positive or 0 (for speed, the condition is not enforced). Internally it uses the same timer as the other elements of the `Timer` class. It compensates for the calling overhead, so for example, 100us should be really close to 100us. For times bigger than 10,000us it releases the GIL to let other threads run, so exactitude is not guaranteed for delays longer than that. @@ -43,29 +43,29 @@ Delay for a given number of microseconds, should be positive or 0 (for speed, th Can be used to measure time spans. -### Methods +## Methods -#### chrono.start() +### chrono.start() Start the chronometer. -#### chrono.stop() +### chrono.stop() Stop the chronometer. -#### chrono.reset() +### chrono.reset() Reset the time count to 0. -#### chrono.read() +### chrono.read() Get the elapsed time in seconds. -#### chrono.read\_ms() +### chrono.read_ms() Get the elapsed time in milliseconds. -#### chrono.read\_us() +### chrono.read_us() Get the elapsed time in microseconds. @@ -95,15 +95,15 @@ class Alarm – get interrupted after a specific interval Used to get interrupted after a specific interval. -### Methods +## Methods -#### alarm.callback(handler, \* , arg=None) +### alarm.callback(handler, * , arg=None) Specify a callback handler for the alarm. If set to `None`, the alarm will be disabled. An optional argument `arg` can be passed to the callback handler function. If `None` is specified, the function will receive the object that triggered the alarm. -#### alarm.cancel() +### alarm.cancel() Disables the alarm. @@ -127,6 +127,4 @@ class Clock: clock = Clock() ``` -{{% hint style="info" %}} -For more information on how Pycom's products handle interrupts, see [notes](/firmwareapi/notes#interrupt-handling). -{{% /hint %}} +> For more information on how Pycom's products handle interrupts, see [notes](/firmwareapi/notes#interrupt-handling). diff --git a/content/firmwareapi/pycom/machine/uart.md b/content/firmwareapi/pycom/machine/uart.md index f611bf9..ce7bc79 100644 --- a/content/firmwareapi/pycom/machine/uart.md +++ b/content/firmwareapi/pycom/machine/uart.md @@ -73,7 +73,7 @@ uart.read(5) # read up to 5 bytes ## Constructors -#### class machine.UART(bus, ...) +### class machine.UART(bus, ...) Construct a UART object on the given `bus`. `bus` can be `0, 1 or 2`. If the `bus` is not given, the default one will be selected (`0`) or the selection will be made based on the given pins. @@ -83,7 +83,7 @@ On the GPy/FiPy UART2 is unavailable because it is used to communicate with the ## Methods -#### uart.init(baudrate=9600, bits=8, parity=None, stop=1, \* , timeout\_chars=2, pins=(TXD, RXD, RTS, CTS), rx\_buffer\_size=512) +### uart.init(baudrate=9600, bits=8, parity=None, stop=1, \* , timeout_chars=2, pins=(TXD, RXD, RTS, CTS), rx_buffer_size=512) Initialise the UART bus with the given parameters: @@ -95,49 +95,49 @@ Initialise the UART bus with the given parameters: * `pins` is a 4 or 2 item list indicating the TXD, RXD, RTS and CTS pins (in that order). Any of the pins can be `None` if one wants the UART to operate with limited functionality. If the RTS pin is given the the RX pin must be given as well. The same applies to CTS. When no pins are given, then the default set of TXD (P1) and RXD (P0) pins is taken, and hardware flow control will be disabled. If `pins=None`, no pin assignment will be made. * `rx_buffer_size` is the size of the buffer used for storing the RX packets. By default is is 512 bytes. -#### uart.deinit() +### uart.deinit() Turn off the UART bus. -#### uart.any() +### uart.any() Return the number of characters available for reading. -#### uart.read(\[nbytes\]) +### uart.read([nbytes]) Read characters. If `nbytes` is specified then read at most that many bytes. Return value: a bytes object containing the bytes read in. Returns `None` on timeout. -#### uart.readall() +### uart.readall() Read as much data as possible. Return value: a bytes object or `None` on timeout. -#### uart.readinto(buf\[, nbytes\]) +### uart.readinto(buf, [nbytes]) Read bytes into the `buf`. If `nbytes` is specified then read at most that many bytes. Otherwise, read at most `len(buf)` bytes. Return value: number of bytes read and stored into `buf` or `None` on timeout. -#### uart.readline() +### uart.readline() Read a line, ending in a newline character. If such a line exists, return is immediate. If the timeout elapses, all available data is returned regardless of whether a newline exists. Return value: the line read or `None` on timeout if no data is available. -#### uart.write(buf) +### uart.write(buf) Write the buffer of bytes to the bus. Return value: number of bytes written or None on timeout. -#### uart.sendbreak() +### uart.sendbreak() Send a break condition on the bus. This drives the bus low for a duration of 13 bits. Return value: `None`. -#### uart.wait\_tx\_done(timeout\_ms) +### uart.wait_tx_done(timeout_ms) Waits at most `timeout_ms` for the last Tx transaction to complete. Returns `True` if all data has been sent and the TX buffer has no data in it, otherwise returns `False`. diff --git a/content/firmwareapi/pycom/machine/wdt.md b/content/firmwareapi/pycom/machine/wdt.md index a87ea39..b1df91f 100644 --- a/content/firmwareapi/pycom/machine/wdt.md +++ b/content/firmwareapi/pycom/machine/wdt.md @@ -19,17 +19,17 @@ wdt.feed() ## Constructors -#### class machine.WDT(id=0, timeout) +### class machine.WDT(id=0, timeout) Create a WDT object and start it. The `id` can only be `0`. See the init method for the parameters of initialisation. ## Methods -#### wdt.init(timeout) +### wdt.init(timeout) Initialises the watchdog timer. The timeout must be given in milliseconds. Once it is running the WDT cannot be stopped but the timeout can be re-configured at any point in time. -#### wdt.feed() +### wdt.feed() Feed the WDT to prevent it from resetting the system. The application should place this call in a sensible place ensuring that the WDT is only fed after verifying that everything is functioning correctly.