Page 1 of 1

What is the difference between: From machine and From pyb

Posted: Sun Oct 28, 2018 5:35 pm
by Gilbert
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

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

Posted: Mon Oct 29, 2018 1:15 am
by shaoziyang
pyb is for pyboard (STM32) only, and machine is common hardware library, it fits most of the hardware.

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

Posted: Mon Oct 29, 2018 7:54 am
by Gilbert
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

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

Posted: Mon Oct 29, 2018 8:11 am
by pythoncoder
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.

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

Posted: Mon Oct 29, 2018 9:10 am
by Gilbert
Thanks pythoncoder,

It is very clear to me now.

Thanks,
Gilbert