machine.Pin(25, Pin.OUT) instead Pin.(25, Pin.OUT) gives error

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
ht007
Posts: 1
Joined: Mon Nov 29, 2021 12:46 am

machine.Pin(25, Pin.OUT) instead Pin.(25, Pin.OUT) gives error

Post by ht007 » Mon Nov 29, 2021 12:58 am

Hi.

import machine
machine.ACD(0) .... works properly but
machine.Pin(25, Pin.OUT) ... gives error as Pin is not defined
WHY?

but

from machine import Pin
Pin(25, Pin.OUT) .... works

It's confuses me totally.
Do you have an answer why the error emerges?
Thx in advance.

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

Re: machine.Pin(25, Pin.OUT) instead Pin.(25, Pin.OUT) gives error

Post by Roberthh » Mon Nov 29, 2021 6:54 am

The proper use is:

machine.Pin(25, machine.Pin.OUT)

You imported machine, not Pin. Thus you have to use the full specifier. That's the way Python works.

Post Reply