0

I am running the following blink program on my raspberry pi pico. I am using circuit python.

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 any thing about the machine module, but I have found nothing. If you know why it can't find the machine module that would be greatly appreciated.

Jonas Parsons
  • 3
  • 1
  • 1
  • 3
  • Have you tried to install micropython following the steps on their official GitHub? https://github.com/micropython/micropython – taipei Mar 21 '22 at 07:04
  • I just put the circuit python uf2 file on to the pico. I am using mu editor with circuit python mode. I have not used their github. – Jonas Parsons Mar 21 '22 at 14:26

3 Answers3

1

Your code is for micropython. Circuitpython is different. See here https://learn.adafruit.com/circuitpython-essentials/circuitpython-digital-in-out

from digitalio import DigitalInOut, Direction, Pull
led = DigitalInOut(board.LED)
aMike
  • 852
  • 5
  • 14
1

I was having same issue and a search found this thread. I changed the Interpreter setting in Thonny (under options) from Local Python 3, to MicroPython (Raspberry Pi Pico)

Duncan
  • 11
  • 1
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 06 '23 at 11:17
0

I think you are using the incorrect uf2 file as the official (stable) version is not out as of writing this. In order to check this, type the following in MircoPython's command line:

import sys sys.implementation (name='micropython', version=(1, 19, 1), _machine='Raspberry Pi Pico with RP2040', _mpy=4102)

If the response shows "Pico" and not "Pico W" then copy the latest version from here and copy it onto your Pico W (in USB mode)