Page 1 of 1

[Windows / Linux] Error: 'module' object has no attribute 'Pin'

Posted: Sat Apr 25, 2020 4:37 pm
by Hitman1O1
I want to develop Micro-Python for my microcontroller and figured it could be useful to be able to run it locally (i.e. on my PC) too.
So I built Micro-Python for Windows (https://github.com/micropython/micropyt ... ts/windows) using Microsoft Visual Studio 2019, which was successful. I can run `.\micropython` and use the Micro-Python interpreter. I can also `import machine` without any problems.
But when I try to use any machine module, e.g. `pin = machine.Pin(0, PIN.IN)` I get errors like this:
'module' object has no attribute 'Pin'
It seems like the machine module is entirely empty.

I tried building and using it on my Ubuntu laptop too, with exactly the same result.

Is something broken on my installs? Or are the Windows/Linux Micro-Python builds not supposed to be able to do much?

Re: [Windows / Linux] Error: 'module' object has no attribute 'Pin'

Posted: Sat Apr 25, 2020 5:16 pm
by kevinkk525
The Unix port of micropython does not have that because it has no hardware pins.
If you want to use the Unix build for debugging, you will have to provide a "fake" machine module implementation.

Re: [Windows / Linux] Error: 'module' object has no attribute 'Pin'

Posted: Sun Apr 26, 2020 3:14 am
by jimmo
Hitman1O1 wrote:
Sat Apr 25, 2020 4:37 pm
Is something broken on my installs? Or are the Windows/Linux Micro-Python builds not supposed to be able to do much?
Yeah, like Kevin says, there's no Pin class because what would it mean for a Windows / Linux computer to control a pin?

Here is an example Python implementation though that provides access to hardware GPIO (e.g. on Linux running on Raspberry Pi). https://github.com/micropython/micropyt ... ine/pin.py

Re: [Windows / Linux] Error: 'module' object has no attribute 'Pin'

Posted: Sun Apr 26, 2020 5:22 pm
by Hitman1O1
Thank you for your replies.
I figured al the in-out related functions were already faked. I guess there is only the 'plain' Micro-Python executable then.

No such 'dry' implementations exist already?

Re: [Windows / Linux] Error: 'module' object has no attribute 'Pin'

Posted: Tue Apr 28, 2020 3:04 am
by jimmo
Hitman1O1 wrote:
Sun Apr 26, 2020 5:22 pm
No such 'dry' implementations exist already?
What does "dry" mean here?

Is https://github.com/micropython/micropyt ... ine/pin.py not what you're looking for?

Re: [Windows / Linux] Error: 'module' object has no attribute 'Pin'

Posted: Fri Sep 04, 2020 6:53 am
by Hitman1O1
Sorry for reviving this thread, I somehow completely missed the last reply.

With a 'dry implementation' I mean just class stubs, so empty definitions that don't do anything, but at least allow the code to run.

But yes, something like that link would be good. Only how do I compile that class into my micropython executable?

EDIT: New thread about this: viewtopic.php?f=12&t=8995