Error with the .mpy file uploaded on the xbee module

I’m using micropython on an XBee3. After testing the program with the Python’s IDLE terminal:

from digi.xbee.devices import XBeeDevice
import time, sys

while True:
time.sleep(1)
print("Start
")

I cross-compile to generate .mpy files:

python -m mpy_cross -mno-unicode -msmall-int-bits=31 main.py

It generates main.mpy, which I then upload with the file manager in XCTU.

When starting on the xbee module, the program generates an error message:

Loading /flash/main.mpy…
Running bytecode…
Traceback (most recent call last):
File “main.py”, line 1, in
ImportError: no module named ‘digi’

It seems that despite the cross-compile, it does not find the import path…

has anyone ever solved the problem ?

Thank you

The cross-compile will only compile that .py file. If you’re using modules outside of the embedded modules on the XBee 3 firmware, you need to upload them as well.

That said, you probably won’t be able to use the XBeeDevice class from digi.xbee.devices. Look at the MicroPython support documentation for the XBee3 or this repository of sample modules and programs:
https://github.com/digidotcom/xbee-micropython

Digi has also released a PyCharm plugin for working with MicroPython on the XBee3 products:
https://www.digi.com/support/productdetail?pid=5674

MicroPython does not contain all the same modules you’re used to in CPython. Your error means there is no digi module.

You can get a list of modules by running (this is in firmware 1008):
>>> help(‘modules’)
main io time uos
array json ubinascii ustruct
binascii machine uerrno utime
builtins micropython uhashlib xbee
errno os uio
gc struct ujson
hashlib sys umachine

You see no “digi” listed but there is “xbee”. You can see what xbee contains using this command:

>>> import xbee
>>> help(xbee)
object is of type module
name – xbee
XBee –
atcmd –
relay –
discover –
receive –
transmit –
ADDR_BROADCAST – b’\x00\x00\x00\x00\x00\x00\xff\xff’
ENDPOINT_DIGI_DATA – 232
CLUSTER_DIGI_SERIAL_DATA – 17
PROFILE_DIGI_XBEE – 49413
ADDR_COORDINATOR – b’\x00\x00\x00\x00\x00\x00\x00\x00’
PIN_WAKE – 1
RTC_WAKE – 2

The MicroPython xbee module is far more limited than the CPython xbee module. You can find documentation by searching the web for “MicroPython programming guide 90002219” then check the “XBee module” section. I recommend reading through a lot of the guide for basic information.

What is the solution for that? how I can use Cpython module with Micropython?
i need to use UART module fro example with xbee3 but I always have this message error “ImportError: no module named ‘UART’”

Compiling on device takes a few minutes, but I’ve found it to be very helpful especially when dealing with buffering/limited memory available on the device.

I would use the uPython terminal through XCTU, and try your code with Ctrl-E, paste your code, then Ctrl-D to run. See if that functions. If it does, use the same process but with CTRL-F to compile on the device.

if you need uart use the machine library as in from machine import UART

Hello, how I can upload new modules to Xbee3 I tried that with the file system of XBee and PyCharm plugin, but I still have errors

Make sure your XBee3 module is updated with the latest firmware. You can try using the File Manager from XCTU to upload files to the module. If you’re still having trouble, can you reply with which XBee3 firmware you’re using, and which version of the PyCharm plugin you have?