Search code examples
pythonraspberry-pi-picoadafruit-circuitpython

Raspberry Pi Pico and error message "ImportError: no module named 'machine'"


I am running the following blink program on my Raspberry Pi Pico. I am using CircuitPython.

from machine import Pin
import time

led = Pin(13, Pin.OUT)
while True:
    led(1)
    time.sleep(1)
    led(0)
    time.sleep(1)

When I run it though, it gives this error:

Traceback (most recent call last):
  File "code.py", line 1, in <module>
ImportError: no module named 'machine'

I have tried to find if I need to download a library file or anything about the machine module, but I haven't found anything. Why can't it find the machine module?


Solution

  • Your code is for MicroPython. CircuitPython is different. See CircuitPython Digital In & Out.

    from digitalio import DigitalInOut, Direction, Pull
    
    led = DigitalInOut(board.LED)