TypeError:argument has wrong type

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
alexmerchant
Posts: 3
Joined: Fri Oct 19, 2018 11:46 am

TypeError:argument has wrong type

Post by alexmerchant » Fri Oct 19, 2018 11:48 am

Hi, I am new with Python and currently trying to display values on a LED screen (it is a RiT but I intend to use the SSD1306 one which seems appropriate) using a I2C connection. Thus, I first do a : from machine import I2C. I also connected the SDA, SCL, GND and VCC of the screen to the corresponding ones on my Pycom device. However, when I try to init the I2C bus it does not work because apparently, the arguments of the parameters do not have the right type.

scl=Pin('P10',Pin.IN)
sda=Pin('P9',Pin.IN)
i2c=I2C.init(sda,scl)

This is the block of code which does not work. My question is : why do I get this error message when it is written on the I2C class documentation (which you can find here : https://docs.micropython.org/en/latest/ ... e.I2C.html) that sda and scl should be pin objects, which I did. Furthermore, if I just write : i2c=I2C(sda,scl) I got the following message : TypeError: can't convert Pin to it.
Thank you all for your help

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: TypeError:argument has wrong type

Post by kevinkk525 » Fri Oct 19, 2018 1:02 pm

As the error message suggests, your pin names should be integer, not strings. All Pin names in micropython are the gpio numbers of the corresponding cpu gpio. I don't know if "P10" in your case is pin 10, that depends on your board, as every manufacturer labels his board as he wants but generally P10 could be pin 10. Just look it up in the documentation of your specific product or test is by setting a pin as output and HIGH and connect an LED to the pin and you'll find the one that drives the led.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

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

Re: TypeError:argument has wrong type

Post by Roberthh » Fri Oct 19, 2018 1:10 pm

@alexmerchant You are still in the wrong forum and writing for the wrong Micropython dialect. You are using a SiPy board form Pycom. The forum for these board is at https://forum.pycom.io/. There is also the link to the matching documentation https://docs.pycom.io/

Post Reply