Hi.
What is the difference between pyb and machine libraries?
Can I use methods (Pin and RTC, for example) interchangeably?
machine vs. pyb libraries
machine vs. pyb libraries
Last edited by jamonda on Sun Aug 23, 2020 2:13 am, edited 1 time in total.
Re: machine vs. pub libraries
I think I will have to try elsewhere...
Re: machine vs. pub libraries
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
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!
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!
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: machine vs. pub libraries
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.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
- rcolistete
- Posts: 352
- Joined: Thu Dec 31, 2015 3:12 pm
- Location: Brazil
- Contact:
Re: machine vs. pub libraries
(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 :
For example, Pyboard D especific and new features, like 'pyb.MMCard()' supporting the WBUS-EMMC adapter board.
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
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).
Re: machine vs. pub libraries
Taking lessons from another legend: Peter Hinch. Thank you so much!pythoncoder wrote: ↑Sat Aug 22, 2020 6:09 pmBecause 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.