element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Experimenting with Current Sense Amplifiers
  • Challenges & Projects
  • Design Challenges
  • Experimenting with Current Sense Amplifiers
  • More
  • Cancel
Experimenting with Current Sense Amplifiers
Challenge Blog Blog #8: Using MAX40080 without writing any code
  • Blog
  • Forum
  • Documents
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: misaz
  • Date Created: 22 May 2022 12:35 PM Date Created
  • Views 1008 views
  • Likes 7 likes
  • Comments 3 comments
  • Current 6 Click
  • MikroE Click Board
  • c
  • raspberry pi
  • csa
  • current sense amplifier
  • cli
  • MAX40080
  • Experimenting with Current Sense Amplifiers
Related
Recommended

Blog #8: Using MAX40080 without writing any code

misaz
misaz
22 May 2022
Blog #8: Using MAX40080 without writing any code

Hello everyone,

I welcome you to my serie of blog posts which I wrote as part of Experimenting with Current Sense Amplifiers Design Challenge. Until now I wrote this and previous 7 blog posts as part of this contest. In my first blog post #1 I described my experiment plans as part of contest. In blogs #2, #3 and #4 I shown basic usage of MAX40080 Current Sense Amplifier sensor. Then I introduced my libraries for simplifying use of MAX40080 CSA sensor in blog posts #5, #6 and #7. This 8th blog post will completely close subsection of my software projects. In this blog I will introduce my software utility which I created for using MXA40080 on Raspberry Pi from command line without need to write any program. I create this utility with help of my C library which I described in blog #6. If you read this blog, you maybe remember that I ported this library to something which I referred as an userspace Linux. Utility which I will show in this blog is based on this port. Utility is used for controlling and collecting data from MAX40080 CSA directly by executing command in terminal.

Installation

Prebuild binaries for 64-bit ARM can be installed using following commands:

wget 'https://github.com/misaz/MAX40080-CLI/releases/download/v1.0/max40080_aarch64'
chmod +x max40080_aarch64
sudo mv max40080_aarch64 /usr/bin/max40080

Enabling power

When used with MikroE Current 6 Click Board you need to enable power for the MAX40080 chip first. When Click Board is fitted to first slot run following commands in terminal:

echo 8 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio8/direction
echo 1 > /sys/class/gpio/gpio8/value
echo 8 > /sys/class/gpio/unexport

In case when you are using Click Board fitted in second slot, then replace 8 with 7 in previous commands.

image

Testing setup

In next section I will show screenshots of output from my utility. When I was making these screenshots, I used the same setup known from my previous blogs. It was simple resistor. So current is static about 30mA and voltage 3.3V. I swapped RS+ and RS- so I got negative current in this case.

image

Usage

After installing you can directly execute max40080 command. By default, it takes one measurement of current and print it.

image

You can change mode of operation and sensor parameters using command line arguments. You can use standard --help command line flag for printing list of all available command line parameters.

image

Except current, utility can also read voltage on VS pin of the MAX40080 chip (referred as VIN on MikroE Current 6 Click Board).

image

You can read both current and voltage at the same time:

image

When reading both current and voltage some restrictions apply because sensor work in this mode differently and alternate between measurements. If you attempt to use invalid configuration, you get error. One of the restrictions is that sample rate is restricted to 0.5 kHz. If you try different sample rate, you get following error:

image

As you have seen in previous screenshot, sample rate is selectable using -s parameter. Value is float in kHz. You can select any sample rate which is supported by sensor. If you enter unsupported sample rate, then you get error with listing permissible sample rates.

Except sample rate, you can also configure digital filter. Digital filter is feature of MAX40080  CSA which cause that sensor averages consecutive samples which reduces noise in measured samples. As a consequence, you get less samples and interval between receiving samples increase.

image

You can also select number of collected samples. By default, utility collects single sample. You can change this by -n parameter.

image

You can set -n param to -1 for collecting samples indefinitely. Then you can stop sampling by pressing Ctrl + C.

image

After receiving samples utility checks for status of FIFO and warns you in case when FIFO overflow happened. So if you configure sample rate too high, then you receive warning message after collecting last sample:

image

You can also receive warning message in the middle of collecting. This happens for example when some I2C error occurs. This happens for example when CRC of transaction received from sensor do not match expected one, but it is hard to simulate these errors under normal operation. Library implements retry logic in main part of collecting samples, so when some error like CRC mismatch occurs, then it prints warning and retry operation again. Utility writes all errors and warnings to stderr, so if you need data for further analysis without these warnings, you can redirect error output to file (recommended) or /dev/null (not recommended).

image

You maybe noticed that you do not need to specify nothing about board containing MAX40080. By default parameters matches MikroE Current 6 Click Board, but if you are using different evaluation board or custom board, you can specify I2C address and value of shunt resistor manually using -a and -r parameters.

Internal details

I programmed this utility in C, so it is distributed as a single lightweight executable. Application is compiled using standard GCC compiler. Sources are available at github. Little bit interesting is that utility is based on my C Library which I described in my 6th blog even it is designed for using with MCUs rather than SBCs. Source code is pretty short. Most code is responsible for parsing command line arguments. After parsing arguments, source code is made of simple library calls, printfs and lot of stuff related to error checking. Library is completely open source. Its sources are available at github, so you can look to sources directly.

Purpose

I originally had not any reason to create this utility, but very soon after starting experimenting with MAX40080 I and other challengers realized that there are no code example or library for using MAX40080 with Raspberry Pi. So I decided to make Python library (which I described in blog 7th blog) and also I got idea to make this utility which allows me to make experiment with sensor without any programming needed (ok, I have to program a lot, but now you do not need at all). Maxim offers GUI utility for their MAX40080EVSYS board, but this tool does not work with Current 6 Click Board, so this CLI utility can be considered as an alternative to this software from some point of view.

Summary and future

In the next blog I will start to make experiments described in my first blog. The first experiment which I will show is Raspberry Pi power consumption self-monitoring. Before showing self-monitoring, I will use simpler setup with analysing power consumption of other USB device – flash drive. Currently I have already completed some other experiments, but writing blog posts is time consuming, so there is small latency between experimenting and publishing summary of experiments as blog posts.

Thank you for your patience and stay tuned.

Next blog: Blog #9: Measuring USB Flash Disk Power Consumption

  • Sign in to reply

Top Comments

  • Gough Lui
    Gough Lui over 3 years ago +1
    Do note that if you follow the instructions to download the binary, you'll also have to chmod +x to allow the file to be executable! Otherwise, you'll get something an error - -bash: /usr/bin/max40080…
  • misaz
    misaz over 3 years ago in reply to Gough Lui

    Thank you for valuable feedback. I for some reason skipped this command when copying from bash history. Now it is fixed and code snippet contains missing command.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Gough Lui
    Gough Lui over 3 years ago

    Do note that if you follow the instructions to download the binary, you'll also have to chmod +x to allow the file to be executable!

    Otherwise, you'll get something an error -

    -bash: /usr/bin/max40080: Permission denied

    - Gough

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • colporteur
    colporteur over 3 years ago

    Great follow-up. I gave some thought to Raspberry Pi power consumption using your python code. Look forward to seeing your results.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube