I/O expander

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
joehunt588
Posts: 26
Joined: Wed Jul 27, 2016 5:06 am

Re: I/O expander

Post by joehunt588 » Wed Aug 03, 2016 9:59 am

Thank you ,now i know

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

Re: I/O expander

Post by mcauser » Wed Aug 03, 2016 11:24 pm

@joehunt588 both the SCL and SDA pins on the I2C bus need pull-up resistors (connecting each to VCC).
Why? Because when they are missing, the pins are floating (sometimes high, sometimes low).

eg. When the master scans the bus for devices, each devices pulls low to respond "hello, I'm here".
When the pins are floating, they are low at unexpected times, which confuses the master thinking devices are present when they are not.

joehunt588
Posts: 26
Joined: Wed Jul 27, 2016 5:06 am

Re: RE: Re: I/O expander

Post by joehunt588 » Thu Aug 04, 2016 1:24 am

mcauser wrote:@joehunt588 both the SCL and SDA pins on the I2C bus need pull-up resistors (connecting each to VCC).
Why? Because when they are missing, the pins are floating (sometimes high, sometimes low).

eg. When the master scans the bus for devices, each devices pulls low to respond "hello, I'm here".
When the pins are floating, they are low at unexpected times, which confuses the master thinking devices are present when they are not.
That why i saw many address when i doing i2c.scan()
Thank for the great info,it really help me Image Image

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

Re: I/O expander

Post by pythoncoder » Thu Aug 04, 2016 7:41 am

It's a little more complex than that, but the reasons are worth grasping especially on the ESP8266 where the interface is bit-banged and can be assigned to any device pins. On the Pyboard the interfaces are assigned to specific pins which are pulled up on the board. On the ESP8266 the user picks the pins and must supply the pullups.

The reason the pullups are required is that the drivers for the scl and sda lines are (or should be) open drain drivers. This means that the driver can pull the line down, but can't pull it up: the resistor performs that duty. This eliminates any possibility of a bus line being driven high by one device while being driven low by another, which can lead to tears before bedtime. Further, the fact that more than one device can simultaneously drive a line low is used by the interface for at least two purposes.

The first is clock stretching where the master pulls the clock low, and the slave reads its state and holds it low until it is ready. The second is multi-master arbitration. The spec allows for the situation where two masters simultaneously try to use the bus and provides an ingenious method of arbitration.

The drawback is that pulling a line up with a resistor is slower than using a transistor. How much slower depends on the capacitance of the line, which increases with length and with the number of attached devices. I2C is only suitable for use over very short distances - normally between devices on a single PCB.
Peter Hinch
Index to my micropython libraries.

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

Re: I/O expander

Post by deshipu » Thu Aug 04, 2016 8:07 am

pythoncoder wrote:It's a little more complex than that, but the reasons are worth grasping especially on the ESP8266 where the interface is bit-banged and can be assigned to any device pins. On the Pyboard the interfaces are assigned to specific pins which are pulled up on the board. On the ESP8266 the user picks the pins and must supply the pullups.
That's why I like to use gpio0 and gpio2 for i2c, as those need to have built-in pull-ups on development boards, to make sure the esp8266 boots into the correct mode.

joehunt588
Posts: 26
Joined: Wed Jul 27, 2016 5:06 am

Re: I/O expander

Post by joehunt588 » Fri Aug 05, 2016 1:20 am

Hi guy thanks so much helping me ,now i can read i2c n control mcp23017

Rajath Kumar K S
Posts: 1
Joined: Thu Dec 08, 2016 8:36 am

Re: I/O expander

Post by Rajath Kumar K S » Thu Dec 08, 2016 8:42 am

[quote="joehunt588"]Hi guy thanks so much helping me ,now i can read i2c n control mcp23017[/quote]

Hello joehunt588,

Can You Please share the Design of yours, What is the Pull Up Resistor Value that you're using ?

Thank You,

joehunt588
Posts: 26
Joined: Wed Jul 27, 2016 5:06 am

Re: I/O expander

Post by joehunt588 » Sat Dec 10, 2016 8:15 pm

Rajath Kumar K S wrote:
joehunt588 wrote:Hi guy thanks so much helping me ,now i can read i2c n control mcp23017
Hello joehunt588,

Can You Please share the Design of yours, What is the Pull Up Resistor Value that you're using ?

Thank You,
Hello Raj ,sorry for late reply ,i using 10k resistor for pull up,both scl and sda from i2c i install the resistor

joehunt588
Posts: 26
Joined: Wed Jul 27, 2016 5:06 am

Re: I/O expander

Post by joehunt588 » Sat Dec 10, 2016 8:21 pm

Image

Sent from my ASUS_T00J using Tapatalk

cefn
Posts: 230
Joined: Tue Aug 09, 2016 10:58 am

Re: I/O expander

Post by cefn » Mon Jul 10, 2017 5:10 pm

I have put together a library for MCP23017 and MCP23008 running on Micropython.

It has only so far been tested on ESP8266 with MCP23017 as I don't have a 23008, but seems functional.

It's based on the Adafruit library for Raspberry PI, but with everything swapped over for Micropython...

See https://github.com/ShrimpingIt/micropython-mcp230xx

Post Reply