Page 1 of 1
machine vs. pyb libraries
Posted: Mon Aug 17, 2020 6:25 pm
by jamonda
Hi.
What is the difference between pyb and machine libraries?
Can I use methods (Pin and RTC, for example) interchangeably?
Re: machine vs. pub libraries
Posted: Sat Aug 22, 2020 2:26 am
by jamonda
I think I will have to try elsewhere...
Re: machine vs. pub libraries
Posted: Sat Aug 22, 2020 5:33 am
by Roberthh
the pyb module exists only on pyboards. The machine module is present on almost all ports. You can use either on one the pyboard. But for code consistency it may be better to use the machine module whenever possible. But that is moe a choice of personal flavor than a must.
Re: machine vs. pub libraries
Posted: Sat Aug 22, 2020 11:11 am
by jamonda
Hi, RobertHH.
It's an honor to talk to you (I see your name everywhere when I look for micropython on the Internet).
I understand what you say about code consistency. I didn't know we had the machine library on Pyboards until I started to learn how to deal with my new Pyboard D. I always had scripts for my Pyboard v1.1 and slightly different ones for my Esp32 board.
Thank you for your help and for being patient with a newbie like me!
Re: machine vs. pub libraries
Posted: Sat Aug 22, 2020 6:09 pm
by pythoncoder
Because machine is portable it lacks some hardware-specific features. My approach is to use machine where possible, but be aware that there are some very nice features of the STM boards accessible only via pyb.
Re: machine vs. pub libraries
Posted: Sat Aug 22, 2020 8:47 pm
by rcolistete
(Sorry, I haven't seen pythoncoder's message)
Yes, the recommendation is to use 'machine' module when it has the equivalent functionality of 'pyb' module, so the code is more portable between MicroPython boards.
But no all functionality of 'pyb' module is available on 'machine' module :
Code: Select all
MicroPython v1.12 on 2019-12-20; PYBD-SF2W with STM32F722IEK
Type "help()" for more information.
>>> import pyb
>>> pyb.
__class__ __name__ main stop
ADC DAC RTC ADCAll
CAN ExtInt Flash I2C
LED MMCard Pin SD
SDCard SPI Servo Switch
Timer UART USB_HID USB_VCP
bootloader country delay dht_readinto
disable_irq elapsed_micros elapsed_millis enable_irq
fault_debug freq hard_reset have_cdc
hid hid_keyboard hid_mouse info
micros millis mount pwm
repl_info repl_uart rng servo
standby sync udelay unique_id
usb_mode wfi
>>> import machine
>>> machine.
__class__ __name__ ADC RTC
DEEPSLEEP_RESET HARD_RESET I2C
PWRON_RESET Pin SOFT_RESET SPI
Signal Timer UART WDT
WDT_RESET bootloader deepsleep disable_irq
enable_irq freq idle info
lightsleep mem16 mem32 mem8
reset reset_cause rng sleep
soft_reset time_pulse_us unique_id
For example, Pyboard D especific and new features, like 'pyb.MMCard()' supporting the
WBUS-EMMC adapter board.
Re: machine vs. pub libraries
Posted: Sun Aug 23, 2020 2:12 am
by jamonda
pythoncoder wrote: ↑Sat Aug 22, 2020 6:09 pm
Because
machine is portable it lacks some hardware-specific features. My approach is to use
machine where possible, but be aware that there are some very nice features of the STM boards accessible only via
pyb.
Taking lessons from another legend: Peter Hinch. Thank you so much!