MicroPython's I2C and SPI support

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
User avatar
liudr
Posts: 211
Joined: Tue Oct 17, 2017 5:18 am

MicroPython's I2C and SPI support

Post by liudr » Wed Oct 18, 2017 4:17 pm

I am new to ESP8266 and MicroPython but I see potential in both. I wonder how much support exists in I2C devices. I can write my library or code if necessary to drive a particular I2C device so I am interested in knowing how easy to access I2C bus.

For SPI I am only looking at SD card for the moment. I know I can save files on ESP8266's flash, which is very nice but I can't remove the flash and read its files on a computer so data should go on an sd card. How easy is it to access sd card? Any recommended reading?


User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: MicroPython's I2C and SPI support

Post by deshipu » Wed Oct 18, 2017 5:25 pm


User avatar
liudr
Posts: 211
Joined: Tue Oct 17, 2017 5:18 am

Re: MicroPython's I2C and SPI support

Post by liudr » Wed Oct 18, 2017 9:18 pm

deshipu wrote:
Wed Oct 18, 2017 5:25 pm
For SD card try:
https://github.com/micropython/micropyt ... /sdcard.py
Thanks. I glanced at the code. It's a snippet at best. So with the code I can write blocks, right? There is no file system support like arduino would on the sd card, is there?

User avatar
liudr
Posts: 211
Joined: Tue Oct 17, 2017 5:18 am

Re: MicroPython's I2C and SPI support

Post by liudr » Wed Oct 18, 2017 9:36 pm

Looking good! Electrically speaking, if I have an I2C module made for arduino, i.e. with bus pullup resistors pulling to 5V, I need to disconnect them, correct? Do I also have to connect pullups to 3.3V or are they typically included on these WeMos or NODEMCU etc. boards?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: MicroPython's I2C and SPI support

Post by Roberthh » Thu Oct 19, 2017 6:46 am

There is no file system support like arduino would on the sd card, is there?
The file system is built into Micropython. The file system requires a block driver to access a specific hardware, the sdcard.py is that interface. if you look at the docstring at the top of the file, you see examples how it is to be used. Once the fevice is mounted using this driver, you can use the standard python file system instructions.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: MicroPython's I2C and SPI support

Post by Roberthh » Thu Oct 19, 2017 6:50 am

Do I also have to connect pullups to 3.3V or are they typically included on these WeMos or NODEMCU etc. boards?
Yes, you have to use pull-up resistors, and no, the are not such ones on the Wemos or NODEMCU devices, simply because GPIOs are general purpose. You may be able to run your external device at 3.3 V. Check that first.

User avatar
liudr
Posts: 211
Joined: Tue Oct 17, 2017 5:18 am

Re: MicroPython's I2C and SPI support

Post by liudr » Thu Oct 19, 2017 3:17 pm

Roberthh wrote:
Thu Oct 19, 2017 6:50 am
Do I also have to connect pullups to 3.3V or are they typically included on these WeMos or NODEMCU etc. boards?
Yes, you have to use pull-up resistors, and no, the are not such ones on the Wemos or NODEMCU devices, simply because GPIOs are general purpose. You may be able to run your external device at 3.3 V. Check that first.
Thanks Roberthh. I figured out from more internet research that there is no native I2C interface on ESP8266 so the support is bitbanging. I also read from another post that the pins are 5V tolerant so I can just use an ebay I2C module such as RTC that already have pullups on the breakout board.

User avatar
liudr
Posts: 211
Joined: Tue Oct 17, 2017 5:18 am

Re: MicroPython's I2C and SPI support

Post by liudr » Thu Oct 19, 2017 3:18 pm

Roberthh wrote:
Thu Oct 19, 2017 6:46 am
There is no file system support like arduino would on the sd card, is there?
The file system is built into Micropython. The file system requires a block driver to access a specific hardware, the sdcard.py is that interface. if you look at the docstring at the top of the file, you see examples how it is to be used. Once the fevice is mounted using this driver, you can use the standard python file system instructions.
Thanks Roberthh. I'll spend more time with my reading. It's good to know that there is a file system. I saw some nice and cheap wemos mini sd card shields for around $1. Will try them.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: MicroPython's I2C and SPI support, 5V Tolerant or not

Post by Roberthh » Thu Oct 19, 2017 3:33 pm

This is a link to the related question on the espressif web site:

http://bbs.espressif.com/viewtopic.php? ... rant#p4100

It clearly states (in 2015) that the device is NOT 5V tolerant.
If you limit the current into the input, e.g. by a sufficient large resistor, the ESD clamping diodes may survive the stress. So people may come to the impression that the device is 5V tolerant. With a pullup resistor of 10k the inrush current if 14 µA, which may not kill the input.

Update: Another clarification is here, at page 27
https://espressif.com/sites/default/fil ... faq_en.pdf

Post Reply