添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
纯真的红酒  ·  Autorun MicroPython ...·  9 小时前    · 
英俊的野马  ·  Installing ...·  9 小时前    · 
成熟的西瓜  ·  Arduino Lab for ...·  9 小时前    · 
谦虚好学的柚子  ·  Arduino Lab Tutorial: ...·  9 小时前    · 
年轻有为的双杠  ·  sql ...·  8 月前    · 
飘逸的茄子  ·  hyperf 使用模型写 union ...·  8 月前    · 

I just bought a Nano 33 Sense Rev2 and have been playing around with MicroPython. No problems installing it and getting python to run using Arduino Lab and also OpenMV. However, the python code will only execute when I press 'play' on these IDEs. I'm making a humidity sensor device and need the code to execute when it powers on (like normal binaries do with Arduino), rather than waiting for an external input.

Does anyone know how to do this? I'm surprised this doesn't happen automatically - its an embedded device after all... typically not connected to a laptop/PC.

Maybe I'm missing something obvious?

Thanks

Update:

After some more digging I found a half-solution to this problem! If you manage to load a main.py file directly onto the Nano 33 Sense, it will indeed run that script when it powers on. I achieved this by following this guide, using screen and ampy: MicroPython Basics: Load Files & Run Code

Now the Nano 33 immediately starts executing my LED-blinking code when it resets or powers off/on... nice.

Except now, I can no longer access the serial port to update it, or do anything for that matter!! No 'ampy' command works. I can still start it in bootloader mode (by double-tapping the button), and then the serial port becomes available again at least... But ampy, or Arduino Lab, cannot communicate with it as its in its dedicated Bootloader mode. So yeah. Aside from doing a complete bootloader/soft device update every time you want to update the MicroPython (gross) this does not work.

Hope this extra info helped. Any additional help appreciated!

Thanks for the response @MrMark - unfortunately I can't access the Nano 33 Sense at all when it's in this 'autorun' state... It seems like the serial port is not available. I've tried with the following:

  • Arduino Lab
  • OpenMV IDE
  • Screen (to initiate a serial connection)

    It seems that with your ESPs, you do not have this problem...?

    @andytheengineerguy What you are experiencing is not unusual and is in fact mentioned in the datasheet https://docs.arduino.cc/resources/datasheets/ABX00069-datasheet.pdf section 3.6, it happens with other types of mcu's running micro python also. This should not prevent your Nano from communicating with other software or hardware as a normal part of a running Python program. It may be possible that this "lock up" can be avoided at times by some simple code modification but overall it's not really a big deal.

    Welcome to the Arduino forum.

    Hi @sumguy , thanks a lot for that! + the link to the datasheet :slight_smile:

    I have an update - this self-locking behavior only happened when I had the OpenMV Firmware installed and then manually loaded the main.py via ampy. I just retried the same thing with the Arduino MicroPython Firmware and am not experiencing the same issue; i.e, the serial port is still accessible during autorun code execution :muscle:

    So now, I am able to update main.py with the same workflow that you'd update a C++ Arduino binary. Finally.

    For the sake of closing out this topic, here is the solution that worked for me:

    1. Update your Nano 33 Sense's bootloader and flash the Arduino MicroPython Firmware (guide from Arduino here )
    2. Make sure you can access its serial REPL . There are multiple ways to do this; for me I used screen on MacOS to ensure I could communicate with the Nano's serial port
    3. Download ampy from adafruit to manipulate the Nanos internal folder structure (for me this was 'pip3 install adafruit-ampy'). For context, this is the part I couldn't figure out with Arduino Labs IDE. For the code to auto-run you need to load it into the main.py file. We are gonna use ampy to do that.
    4. Use ampy to load your script as a main.py file onto the Nano. For me, this was 'ampy --port /dev/tty.usbmodem0000000000001 put test_green.py main.py'
    5. Restart your nano. Be happy.

    To update the python code, simply re-run ampys put command with your updated script to main.py. For my case, I changed the blink script to stay on the green LED for longer, to confirm that it worked. It's still not as nice as using an IDE, and I do hope this becomes a feature of the IDE in the near future as this is an important feature for embedded devices.... But for now, it works.

    For more info see this digikey post

    @andytheengineerguy just like MrMark my micropython ventures have been with the ESP32, once you have the firmware then Thonny is a great and compact starter IDE link here:- https://thonny.org/

    Thonny will show your mcu file system, allow you to create and upload the python files you need including the main.py or boot.py and give you full access to REPL, at this moment in time it has a slight edge over Arduino Lab