Import ultrasonic2 causes traceback error


I have the following imports at the top of a MicroPython program:

import cyberpi
import mbot2
import ultrasonic2
import sys

When I upload the program to my mBot2 it immediately displays a traceback error on line 3, the ultrasonic2 import line. When I comment out the line and calls to the sensor, the program runs fine. I need to access the sensor. Is there a bug in the ultrasonic2 library or am I missing something?

Thanks for reading.


The error is ImportError: no module named ‘ultrasonic2’. The full error message is

PYB: fast reboot
MicroPython 6bb454b6-dirty on 2021-03-10; ESP32 module with ESP32
Type "help()" for more information.
>>> free the memory of this function
event: 0 error occured:
Unhandled exception in thread started by <bound_method>
Traceback (most recent call last):
File "events/", line 156, in __event_cb_task
File "events/", line 156, in __event_cb_task
File "events/", line 121, in __event_cb_task
File "", line 130, in default_task
File "<string>", line 1, in <module>
File "", line 3, in <module>
ImportError: no module named 'ultrasonic2'

Not sure why there would be no module named ultrasonic2 as it is present in the documentation and spelled in that manner. Is there a library add step for this module?


What coding application are you using?
Also, include don’t just magically work, so make sure that the include file is downloaded and works with your coding application.
I recommend the mBlock Python editor (include in mBlock 5.4):

Thanks for your time,


Hi, thanks for your response. I am using mBlock v5.4.0. You say to make sure the include file is downloaded and works with your application. How do you do that? I did not have to do anything special with the cyberpi, mbot2, or sys modules and they work.


Is the ultrasonic sensor extension added?
Are you using the Python editor?


Ultrasonic sensor extension added (in the Blocks editor–although it doesn’t persist across mBlock sessions; I have to re-add it when I open mBlock).

Yes, I am using the mBlock Python editor.


@Best_codes, you originally said “include [imports] don’t just magically work.” Well then, as I asked before, what do you have to do to get them to work? As I originally stated, only the ultrasonic2 import fails. The others work. I’ve tried with the most recent versions of mBlock and mLink. I add the Ultrasonic 2 extension in the Blocks editor every time. Still fails. What is the correct module to access the Ultrasonic 2 sensor’s API?


Click the “Libraries” button:
Install the top three libraries:

You can also click the “Help docs for cyberpi” text for more help:
This should appear:

Or, you can click the link below:
(It is slow, though).

Thanks for your time,


Oh, just curious, what spellchecker do you use? Is it LanguageTool?


The makeblock and cyberpi libraries are installed by default. mkcloud is irrelevant.


I just know how to spell.


For anyone who runs in to this problem, I received the solution from Makeblock support. The Ultrasonic 2 API is declared in the mbuild module, so that’s what you need to import:

import mbuild
dist = mbuild.ultrasonic2.get()

This wasn’t clear in the documentation and Worst_codes troll is useless.


Glad you found out how to do it!
And please don’t bully!
Have a nice day!
@Crackel @CommandeR


Please don’t deliberately waste people’s time when you clearly don’t know the answer.


OK, sorry if I wasted your time. Now please stop.


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.