pyb.SPI vs pyb.machine.SPI?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
kwiley
Posts: 140
Joined: Wed May 16, 2018 5:53 pm
Contact:

pyb.SPI vs pyb.machine.SPI?

Post by kwiley » Wed May 16, 2018 9:04 pm

The documentation has similar, but not identical, APis for SPI communication under the top pyb module and under the secondary pyb.machine module. What's the difference and what criteria determine which module I should use?

Thanks.

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

Re: pyb.SPI vs pyb.machine.SPI?

Post by pythoncoder » Thu May 17, 2018 6:33 am

The pyb library is only available for STM processors (e.g. the Pyboard). So if you're using something else or want to write portable code you need to use machine.

On STM kit it's up to you. I tend to use pyb. It's rock-solid reliable as it's been around for a long time, has some STM specific functionality and is perhaps better documented.
Peter Hinch
Index to my micropython libraries.

kwiley
Posts: 140
Joined: Wed May 16, 2018 5:53 pm
Contact:

Re: pyb.SPI vs pyb.machine.SPI?

Post by kwiley » Thu May 17, 2018 4:17 pm

Thank you. I've have had no luck with SPI communications yet. I don't know if I'm using the PyBoard SPI library incorrectly or if I'm accessing the other devices' SPI APIs incorrectly (probably the latter of course). It's driving me crazy. I2C works fine, but I've had no luck with SPI yet.

User avatar
TravisT
Posts: 72
Joined: Sun Feb 23, 2014 2:31 pm
Location: Portland, OR
Contact:

Re: pyb.SPI vs pyb.machine.SPI?

Post by TravisT » Sun Jun 24, 2018 5:35 pm

Hello,

I know this is a late post, but most of my SPI problems have been because the Mode has not been set right or because the wiring (especially when hacking together a development board) did not support the speeds.

I would double check the mode the device is designed for, and then lower the speed quite low to start, starting at 1Mhz is a good place.

If you did find a resolution, probably not bad to post here for others to learn from it.
_______________
Travis Travelstead

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: pyb.SPI vs pyb.machine.SPI?

Post by mcauser » Sun Jun 24, 2018 11:24 pm

I'd recommend getting a logic analyser. Helps you visualise whats being sent back and forth.

Saleae Logic 8 - $579 AUD
https://www.saleae.com/

If that's way out of your price range, you can get a cheap clone for around $6-10, which also works with the Saleae software.
https://www.aliexpress.com/item/1pcs-Ne ... 00856.html

If you can afford it, support the devs and get a legit board. It's heaps faster, better quality and much more reliable test clips.

Post Reply