4

when I try to control my esp32 microcontorller with micropython I get the following error:

  File "c:/Users/supre/Documents/Python Programme/micropython/blinktest.py", line 1, in <module>
    from machine import Pin
ModuleNotFoundError: No module named 'machine'

I try to test the basic blinktest code:

from machine import Pin
import time

led = Pin(12, Pin.OUT)
for n in range(1,30):
    led.value(0) #on
    sleep(1)
    led.value(1) #off
    sleep(1)

I can't install this module via pip or anaconda (when I try to install the module via pip the build fails)

Is this error maybe caused because I have installed micropython the wrong way?

So it would be very nice if someone could help me out with this problem.

  • https://docs.micropython.org/en/latest/reference/packages.html suggests to use `upip` - how did you install the machine package? What error did you get? – doctorlove May 17 '21 at 14:26
  • Firsteful thank you very very much for your answer:) I tried to install the package via the normal pip. I think the error is to long to post in the comment section. –  May 17 '21 at 14:47
  • @Scripter1 please check this https://stackoverflow.com/questions/51635347/cannot-import-machine-module-on-micropython, and also you can try to create separate env to install pip packages. – Anup May 17 '21 at 15:27
  • Thanks @Anup I've already fixed it:) –  May 17 '21 at 16:17

1 Answers1

4

It appears you are attempting to run the blinktest.py on your PC , rather than on your ESP32 microcontroller. the giveaway is that the machine module cannot be found which is part of the ESP32 firmware that should be installed on the ESP32.

you would need to :

  • install/flash the MicroPython firmware on your ESP32
  • transfer/copy blinktest.py to your ESp32
  • connect to the ESP32 MicroPython repl
  • then start blinktest.py by executing import blinktest

for a detailed step by step for the ESP32: http://docs.micropython.org/en/latest/esp32/tutorial/intro.html#esp32-intro

Jos Verlinde
  • 1,468
  • 12
  • 25
  • When I use Pycharm with Micropython plugin, i have to be in micropython window instead of Python Console – lojza May 15 '23 at 07:25