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!
Thanks in advanve for your help!
STM32L476: can´t convert int object to str implicitly
-
- Posts: 39
- Joined: Fri Mar 29, 2019 7:08 pm
-
- Posts: 169
- Joined: Fri Aug 19, 2016 11:55 am
Re: STM32L476: can´t convert int object to str implicitly
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.
-
- Posts: 39
- Joined: Fri Mar 29, 2019 7:08 pm
Re: STM32L476: can´t convert int object to str implicitly
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?
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?
Re: STM32L476: can´t convert int object to str implicitly
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.
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.
-
- Posts: 39
- Joined: Fri Mar 29, 2019 7:08 pm
Re: STM32L476: can´t convert int object to str implicitly
Thanks a lot for your support!