I/O expander
-
- Posts: 26
- Joined: Wed Jul 27, 2016 5:06 am
I/O expander
Hai guy can suggest any working i/o expander for esp8266 that using i2c?
im currently struggle using i2c for mcp23017
[code]
from machine import Pin, I2C
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)
#DEVICE = 0x20 # Device address (A0-A2)
#IODIRA = 0x00 # Pin direction register
#OLATA = 0x14 # Register for outputs
#GPIOA = 0x12 # Register for inputs
#register addr
addr = bytearray([0x00,0x00])
i2c.writeto(0x20, addr) <--- error Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object with buffer protocol required
[/code]
Please help me using mcp23017 on esp8266 (previous using code in rpi) or suggest easy way in using i/o expander
<link>https://cdn-shop.adafruit.com/datasheet ... .pdf</link>
im currently struggle using i2c for mcp23017
[code]
from machine import Pin, I2C
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)
#DEVICE = 0x20 # Device address (A0-A2)
#IODIRA = 0x00 # Pin direction register
#OLATA = 0x14 # Register for outputs
#GPIOA = 0x12 # Register for inputs
#register addr
addr = bytearray([0x00,0x00])
i2c.writeto(0x20, addr) <--- error Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object with buffer protocol required
[/code]
Please help me using mcp23017 on esp8266 (previous using code in rpi) or suggest easy way in using i/o expander
<link>https://cdn-shop.adafruit.com/datasheet ... .pdf</link>
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: I/O expander
I suspect the cause is out of date firmware. That error should not occur. Here I get
which is to be expected as I haven't got the hardware connected. It is accepting the bytearray and trying to write to the nonexistent kit.
Code: Select all
>>> i2c.writeto(0x20, addr)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: I2C bus error
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: I/O expander
I'm using a PCF8574 "backpack" with a 1602 LCD and a WeMos D1 mini.
They are also sold as a regular I/O module, without 16 pin LCD specific header.
http://www.aliexpress.com/item/PCF8574- ... 58823.html
They are also sold as a regular I/O module, without 16 pin LCD specific header.
http://www.aliexpress.com/item/PCF8574- ... 58823.html
Re: I/O expander
Try dropping the I2C frequency and different pull-up resistor values.
I was unable to get an I2C temperature sensor working higher than 50,000 without I2C bus error messages.
I was unable to get an I2C temperature sensor working higher than 50,000 without I2C bus error messages.
-
- Posts: 26
- Joined: Wed Jul 27, 2016 5:06 am
Re: I/O expander
Hi pythoncoder
i using firmware micropython 1.8.2,what version you use?
i using firmware micropython 1.8.2,what version you use?
Last edited by joehunt588 on Tue Aug 02, 2016 10:47 am, edited 1 time in total.
-
- Posts: 26
- Joined: Wed Jul 27, 2016 5:06 am
Re: I/O expander
Hi mcauser,
how can i scan i2c port? when i using i2c.scan() it show result in list [4,8 -> 41],by default it 0x20.
can you share me code for PCF8574A python ,i now order the chip
how can i scan i2c port? when i using i2c.scan() it show result in list [4,8 -> 41],by default it 0x20.
can you share me code for PCF8574A python ,i now order the chip
Re: I/O expander
i2c.scan() returns results in decimal. 0x20 == 32.
If you are seeing a bunch of unrelated scan results, you may be missing pull-up resistors.
I saw that when I was working with a DHT12 sensor. Added pull-ups and scan then returned a single item.
Here is an example of using WeMos D1 mini + PCF8574 I2C expander + 1602 HD44780 character LCD:
https://github.com/dhylands/python_lcd/pull/2
If you are seeing a bunch of unrelated scan results, you may be missing pull-up resistors.
I saw that when I was working with a DHT12 sensor. Added pull-ups and scan then returned a single item.
Here is an example of using WeMos D1 mini + PCF8574 I2C expander + 1602 HD44780 character LCD:
https://github.com/dhylands/python_lcd/pull/2
-
- Posts: 26
- Joined: Wed Jul 27, 2016 5:06 am
Re: I/O expander
Hi mcauser
thank you for the code appreciate .
may i know where do i need put resistor?do i need to put resistor for SDA and SCL line?Sorry for my noob question do you have schematic where i can follow to put the pull out resistor?
thank you for the code appreciate .
may i know where do i need put resistor?do i need to put resistor for SDA and SCL line?Sorry for my noob question do you have schematic where i can follow to put the pull out resistor?
Re: I/O expander
Yes, on both.joehunt588 wrote:Hi mcauser
thank you for the code appreciate .
may i know where do i need put resistor?do i need to put resistor for SDA and SCL line?Sorry for my noob question do you have schematic where i can follow to put the pull out resistor?
The optimal value for the resistors depends on clock speed and cable type.
If you intend to have any I2C sensors further than a few tens of cm away from the ESP, you may need to reduce the clock speed. In my tests with BMP280s, reducing the clock speed to 10kHz introduces only a slight delay.
There are a couple of helpful links about I2C resistances here:
http://dsscircuits.com/articles/effects ... -resistors
and
https://rheingoldheavy.com/i2c-pull-resistors/