What is the difference between: From machine and From pyb

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
Gilbert
Posts: 16
Joined: Sun Sep 09, 2018 11:10 am

What is the difference between: From machine and From pyb

Post by Gilbert » Sun Oct 28, 2018 5:35 pm

Hi,

While trying to understand a program that uses 'I2C' I discovered that there are two I2C functions available: One to import from "machine", the other from "pyb".
One is related to the HARDWARE and the other to the BOARD which seems to me the same thing.
So my question is: What is the difference between FROM MACHINE and FROM PYB, or what is the difference between HARDWARE RELATED and BOARD RELATED?

Regards,
Gilbert

shaoziyang
Posts: 363
Joined: Sun Apr 17, 2016 1:55 pm

Re: What is the difference between: From machine and From pyb

Post by shaoziyang » Mon Oct 29, 2018 1:15 am

pyb is for pyboard (STM32) only, and machine is common hardware library, it fits most of the hardware.

Gilbert
Posts: 16
Joined: Sun Sep 09, 2018 11:10 am

Re: What is the difference between: From machine and From pyb

Post by Gilbert » Mon Oct 29, 2018 7:54 am

OK thanks,

but why maintaining two I2C libraries, and which one is the best?
And it would have been very helpful if the Quick reference guide would have pointed that out. (it took me quite some time to find out there was another I2C library with different commands/methods.)

Regards

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: What is the difference between: From machine and From pyb

Post by pythoncoder » Mon Oct 29, 2018 8:11 am

There isn't a "best" one: both have an intended application. If you want to write portable code, use machine. You may find that machine meets all your needs. It represents a basic hardware abstraction which can be expected to be found on all bare metal MicroPython targets.

If you want to access the extensive hardware features which are available on STM chips, use pyb. The latter opens up a whole world of possibilities and is well worth learning if you have a Pyboard. My personal view is that if you're only ever going to program Pyboards, use pyb. It is much more capable.
Peter Hinch
Index to my micropython libraries.

Gilbert
Posts: 16
Joined: Sun Sep 09, 2018 11:10 am

Re: What is the difference between: From machine and From pyb

Post by Gilbert » Mon Oct 29, 2018 9:10 am

Thanks pythoncoder,

It is very clear to me now.

Thanks,
Gilbert

Post Reply