How to set auto current range mode with upper/lower limit on JS220 by Python

Hello,

I am using JS220 for IoT product power consumption measurements, and its performance exceeds expectations. In the next step, I plan to code some Python scripts to control JS220.

There is only one question that I would like to ask (I have searched the Q&A but haven’t found the answer; please let me know if this question has been asked before):

I have referred to the Joulescope examples, and I have understood how the current range is set as follows:"

device = joulescope.scan_require_one(config='auto')
device.parameter_set('i_range', js_curr_range) 
# js_curr_range (JS220) = 'auto','off', '10 A', '180 mA','18 mA','1.8 mA','180 µA','18 µA'

However, JS220 has added the ability to limit the upper and lower limits of the current range used during the “auto” current range as follows. How should I use Python to set it? Thanks

image

(For example, I would like to set “auto mode within 180 µA - 18 mA”)

Hi @JackK and welcome to the Joulescope forum!

Great to hear that the JS220 is working well for you. Congratulations on taking the next step to automate things using Python!

Unfortunately, you are not missing anything. The joulescope package only has full support for the parameters used by both the JS110 and the JS220. The JS220-specific parameters are currently only supported through the lower level pyjoulescope_driver package. Figuring out how to expose the device-specific parameters through the joulescope package is still on our list of things to do.

{edit} We do have a way using the publish method and joulescope package. See next post for details. If you would rather use the pyjoulescope_driver package directly, keep reading.

As of today, the easiest approach is likely to use the pyjoulescope_driver package directly. The joulescope package v1 backend simply wraps the pyjoulescope_driver package as you can see here.

Here are some resources for using the pyjoulescope_driver package:

Looking at the detector example, you would insert the following lines before line 93:

               d.publish(f'{device}/s/i/range/max', '180 µA')
               d.publish(f'{device}/s/i/range/min', '18 mA')

Does this get you want you want?

If not, I am happy to help put together something closer to what you need. What actions are you looking to perform with your JS220 through the Python script?

I took a closer look, and we do have a way with the joulescope package. You can simply call the publish method directly, like this:

device.publish('s/i/range/max', '180 µA')
device.publish('s/i/range/min', '18 mA')

Note that this only works with the default v1 backend which supports the JS220 and JS110. The publish method does not exist for the legacy v0 backend which only supports the JS110.

Hello @mliberty,

Thanks for getting back to me so quickly.
I am interested in the second method using the joulescope package.
I attempted to call the publish method in my code, but it seems that the publish method can not be found.
image

Additionally, when I tested the detector.py, it looked like something was lost:

Is this related to the “v1 backend” you mentioned?

Thanks,
JackK

The version information I used is as follows:

joulescope 1.1.11
joulescope_ui 1.0.48
pyjoulescope-driver 1.4.6

Can you share your full code and the error message? For example, this script runs for me without any errors:

from joulescope import scan
import sys
import time

def run():
    devices = scan(config='off')
    if len(devices) != 1:
        print(f'Found {len(devices)} Joulescopes')
        return 1
    device = devices[0]
    device.open()
    try:
        device.parameter_set('i_range', 'auto')
        device.parameter_set('v_range', '15V')
        device.publish('s/i/range/max', '180 µA')
        device.publish('s/i/range/min', '18 mA')
        time.sleep(10)  # replace with your code
    finally:
        device.close()


if __name__ == '__main__':
    sys.exit(run())

pip freeze shows:

joulescope==1.1.11
pyjls==0.9.1
pyjoulescope-driver==1.4.6

You can always force an update with:

pip install -U --upgrade-strategy eager joulescope pyjoulescope_driver pyjls

This example requires the entire pyjoulescope_example repo. It uses the detectors found in the joulescope_examples.detectors package