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

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
Hitman1O1
Posts: 10
Joined: Sat Apr 25, 2020 3:23 pm

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

Post by Hitman1O1 » Sat Apr 25, 2020 4:37 pm

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?

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

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

Post by kevinkk525 » Sat Apr 25, 2020 5:16 pm

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.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
jimmo
Posts: 2015
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

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

Post by jimmo » Sun Apr 26, 2020 3:14 am

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

Hitman1O1
Posts: 10
Joined: Sat Apr 25, 2020 3:23 pm

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

Post by Hitman1O1 » Sun Apr 26, 2020 5:22 pm

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?

User avatar
jimmo
Posts: 2015
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

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

Post by jimmo » Tue Apr 28, 2020 3:04 am

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?

Hitman1O1
Posts: 10
Joined: Sat Apr 25, 2020 3:23 pm

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

Post by Hitman1O1 » Fri Sep 04, 2020 6:53 am

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

Post Reply