Zerynth implementation with Pycharm

Hi everyone!
I had develop an app in java to take advantages of Zerynth Toolchain commands.
So you just need to point to the shell command on your Pycharm configurations
and write the arguments for compile, uplink or open console like this:
java -jar /home/david/.java/zerynth_tool.jar "$@"

The app let you choose a device previously virtualized in Zerynth Studio and creates a .json for device info for uplink and compile the code. To deal with the stdlibs and official modules I just add them to interpreter paths.

Everything works fine like any pycharm project, I test the app in pycharm with a NodeMCU3 device and a PSoC 6, which work fine for modules.

The only thing I need to solve its to find a way to import the PIN definition (D#), HIGH,LOW and digitaRead definitions too, and functions like sleep or random aren’t able to found. I have looked up in every document of the zerynth files but nothing.
As you can see in the next image, modules like stream, wireless and mqtt has no problem, the thing is with the ones metioned above:

The app has no problem on compiling and uplinking the code which have sense because it depends on the device target, and can be used with Pycharm included jbr with no previuos java installation.
I hope you guys can help my to import that missing modules, that would really make the experience really comfortable!

If you like to download the jar file to try it here is the link:

Hello David,

Very cool app :slight_smile:
The definitions you miss are, let’s say, defined in a non-conventional mode to be parsed inside the Zerynth Compiler.

For example, the pin definitions (D#) are inside the related device folder in a file named port.def
(you can find it in this path ~/.zerynth2/dist/r2.3.3/devices/psoc6wifibt_pioneerkit/port/port.def); port.def is a raw text file that is parsed by the Zerynth Compiler.

The HIGH, LOW, etc. definitions are inside the __builtins__.py file of the stdlib (path ~/.zerynth2/dist/r2.3.3/stdlib/__builtins__.py) defined in this way:

__define(HIGH,1) # line 503

always to be parsed by the Zerynth Compiler.

If you have analyzed a little bit of the zerynth toolchain, you can pick all those definitions from the Zerynth Compiler.

Try to insert a print at line 501 of this file ~/.zerynth2/dist/r2.3.3/ztc/compiler/compiler.py in this way:

    print("ALL DEFINES --> ",self.astp.allnames)

In self.astp.allnames at that line (because the Zerynth Compiler already searches for you all defines needed) there is everything you are missing.

For example, you can return this value or parse this dictionary if you enable a new flag in the click compiler command (modifying the Zerynth Toolchain) so you can use it in your app; then you can fork our official repository (https://github.com/zerynth/core-zerynth-toolchain) and when all work you can send us a pull request to merge your changes in our next official release.

Hope this can help you
Let me know if you have any other doubts


Thanks for the help @Matteo_Cipriani !

As you say the key was to parse data from the compiler.
I solve the problem by modifiying the toolchain and adding a new class called PreCompiler which only pase all the nessesary stuff for the definition with the command:
ztc definiton ${TARGET} ${CLASSNAME}
And then exported in a module called __builtins_ztc__.pyi on a folder named ztool.

I added a new configuration option on Pycharm implemetation with de java app called device selector, which just import the definitions right for the selected device with the command -d.

And after a few hard work finally have the expected result:

As you can see the file for uplink main.vbo, __builtins_ztc__.pyi and device.json are grouped on a folder called ztool. On the console you would see that i use ztool command which is simple a file for globally execution located on /bin/bash with code java -jar ~/.java/zerynth_tool.jar "$@".

And finally for this to work as this way there is a an important step to do. Besides of set the stdlib,zerynth,and official folders to the interpreter path as I mention before, you need to open the file builtins.pyi file by pressing ctrl+b on any python standart library like print, str, etc…, then it will open the file builtins.py and you should press the astrisk and the right side of the function definition and will open the builtins.pyi. After this go to the top botton of the file and add the following:

    from ztool.__builtins_ztc__ import *
except ImportError:

I use try because this is the file used by pycharm to find the python functions. So if this not work if you are doing some other stuff but not zerynth programming, it would not affect to your projects.

I had updated the drive link for the .jar tool for this new functionality, in the link of the post above and will try to work on import the config files in a template or something, so you don’t need to write it every time you open a new project to zerynth programming.

Hope this could be useful for the ones who prefer to use Itellij IDE’s for efficiency and productivity!

1 Like

This is an screenshot for the buitins.pyi modifcation:


hi @David_Fernando_Torre
You’re plugin works perfectly on linux, Have got a chance to test it on windows?
I am having some errors if I send the compile argument -c or uplink argument -u:

Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 189
at java.lang.String.substring(Unknown Source)
at com.tbiomed.Main.deviceSelector(Main.java:89)
at com.tbiomed.Main.main(Main.java:30)

hi @David_Fernando_Torre,
We’ll be starting our Zerynth Live Support session on YouTube today , where we will answer your question (and a couple of others). @karimhamdy1 will be holding the session.

If you would like to join us on our YouTube channel, the live session starts at 4 pm (CET). And of course, if you have any other questions you can either ask in the comment section on the video.

Here’s the link to the Zerynth YT channel in case you’re interested in joining us: http://www.youtube.com/c/Zerynth