STM32L476: can´t convert int object to str implicitly

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
cyrano1960
Posts: 7
Joined: Fri Mar 29, 2019 7:08 pm

STM32L476: can´t convert int object to str implicitly

Post by cyrano1960 » Tue May 21, 2019 7:40 pm

Hello,
first of all: thanks so much for this fantastic MicroPython system. It is a really great job. :!:

I have succesfully installed Micropython on an ESP32 board and now I want to do this with an STM32L476. The installation process works without a problem, but after installation I wanted to run a simple test program which runs fine on ESP32 and I got the following error message I can´t understand. But first, this is my code:

from machine import Pin

pin9 = Pin(0, Pin.IN)

while True:
print(pin9.value())
time.sleep(1)

And here is the error message:

>>> Traceback (most recent call last):
File "main.py", line 3, in <module>
TypeError: can't convert 'int' object to str implicitly
MicroPython v1.10 on 2019-01-25; NUCLEO-L476RG with STM32L476RG
Type "help()" for more information.

First I thought my error was in the print-command, but the error message points to line 3 and even if I deleted all code except the first two lines I will get the error message. So it is "pin9 = Pin(0, Pin.IN)" which causes the error. But why! :roll:

Thanks in advanve for your help!

Christian Walther
Posts: 55
Joined: Fri Aug 19, 2016 11:55 am

Re: STM32L476: can´t convert int object to str implicitly

Post by Christian Walther » Tue May 21, 2019 8:54 pm

I’m not totally sure because my experience with them is limited, but it would seem that on STM32 platforms, the pins are named by strings like "A0", not by numbers like on the ESP platforms. See http://docs.micropython.org/en/latest/p ... ckref.html, and pin9 = Pin('B1', Pin.IN) works on my Pyboard D.

cyrano1960
Posts: 7
Joined: Fri Mar 29, 2019 7:08 pm

Re: STM32L476: can´t convert int object to str implicitly

Post by cyrano1960 » Thu May 23, 2019 4:19 pm

Hi Christian,
thanks for your answer, I guess your right. But in the meantime I founded that there ist another Pin Class in module "pyb". I have checked this version and it works with

from pyb import Pin

and

Pin.cpu.AO

Do you know the difference between the two classes?

User avatar
dhylands
Posts: 3212
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: STM32L476: can´t convert int object to str implicitly

Post by dhylands » Thu May 23, 2019 7:08 pm

machine.Pin and pyb.Pin are aliases for each other. They both present the identical API. The reason for them both existing is historical. pyb.Pin existed first and then machine.Pin was created. pyb.Pin was left in for comparability with the older code. New code should use machine.Pin.

Note that you can pass machine.Pin.cpu.A0 or 'A0' and you'll get the same thing. The only time they might differ is if there is a machine.Pin.board.A0 as well as a machine.Pin.cpu.A0 in which case 'A0' will refer to the board pin.

cyrano1960
Posts: 7
Joined: Fri Mar 29, 2019 7:08 pm

Re: STM32L476: can´t convert int object to str implicitly

Post by cyrano1960 » Sun May 26, 2019 2:04 pm

Thanks a lot for your support! ;)

Post Reply