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 #5: My Python and C Libraries are available now
  • 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: 25 Apr 2022 3:13 PM Date Created
  • Views 1300 views
  • Likes 8 likes
  • Comments 5 comments
  • Current 6 Click
  • MikroE Click Board
  • raspberry pi
  • csa
  • current sense amplifier
  • MAX40080
  • Experimenting with Current Sense Amplifiers
Related
Recommended

Blog #5: My Python and C Libraries are available now

misaz
misaz
25 Apr 2022

Hello everyone. I welcome you to my 5th blog post as part of Experimenting with Current Sense Amplifiers Design Challenge. This blog is very short because I am very busy at the time of writing this blog post and I have no time to write proper blog.

Last weekend I published first version of both my Libraries targeting MAX40080 CSA sensor which we use as part of design challenge. Both Libraries are at available online the Github.

Python library for Raspberry Pi is at: https://github.com/misaz/MAX40080-PythonLibrary

C library for microcontrollers is at: https://github.com/misaz/MAX40080-Library

Both Libraries were partially tested, and at least basic features should work.

C Library

C Library contains implemented 4 examples that are linked at main page of library:

image

If you click at description link, you will get redirected to the details page of corresponding example. All examples are currently implemented for MAX32625 MCU. For now, if you use different MCU then you will need to port the library yourself. Later I plan to add support for some other platforms. Every example description page contains description of example, example code, detailed description of every part of code and MAX32625 port specific details.

Python Library

I originally want to develop only C library but based on multiple requests I created Python library also. It is simple and support only basic features of sensor for now. You can install it by executing following command in terminal:

pip3 install git+https://github.com/misaz/MAX40080-PythonLibrary

Then, you can create very simple Python file max40080_test.py with following content:

from max40080 import MAX40080

max = MAX40080()
max.configure()
print(max.read_current())

And then you can execute your python script:

python3 max40080_test.py

You should see one current measurement on the screen.

Library provides 7 functions to you. They are mentioned (with optional parameters) at main page in Github repo:

image

Feedback

Both libraries are available to everyone. Everyone can freely use them. Even I tested them, they may still be some bugs. Kindle report them below in comments or at GitHub.

Last words

For now, it is all. Thank you for reading this blog. Soon I will post more detailed blogs about my libraries. Because I am very busy this week I will complete and post these blogs at the end of the week or most probably at the weekend.

Next blog: Blog #6: MAX40080 C Library

  • Sign in to reply
  • misaz
    misaz over 3 years ago in reply to misaz

    Update 2022-05-02: I am very busy at this time so I was unable to port library to Mbed this weekend, so I will try next weekend.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • misaz
    misaz over 3 years ago in reply to guillengap

    Thank you for feedback.

    1) Yes it is but I dont have MAX32620FTHR, so I cant test it. But I have different Mbed OS enabled board, so I will provide port maybe this weekend.

    2) Python library returns value in Amperes, so you can multiple it by 1000000 for getting uA, but note that conversion to uA does not make sense very much because resolution of sensor with 10mOhm shunt resistor is 1.22 mA. For conversion to mA instead of uA just multiple value by 1000.

    If you are adavenced user and want to reduce floating point computation error, you can update directly source code of the library (https://github.com/misaz/MAX40080-PythonLibrary/blob/main/max40080/max40080.py). Change constant 1.25 to 1250 in functions read_current and read_current_and_voltage functions. You can download library source code directly to your project folder or you can edit file on your disk. By default pip3 installed it to the ~/.local/lib/python3.9/site-packages/max40080/max40080.py file. You need to replace python version in the path.

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

    Hi misaz  Thanks for sharing your libraries, just two small things: 1) Is it possible to use your C++ library on a MAX32620FTHR board in Mbed OS?; and 2) Is it possible to measure microamps with your python library? ... good luck

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • misaz
    misaz over 3 years ago in reply to colporteur

    This behaviour is not a bug. It is a feature :). Wrong readings are correct readings, but they are delayed by FIFO. Sensor has 64 cell deep FIFO. When you configure() sensor it immediately start filling FIFO with samples (by default it takes 15000 samples every second) and when FIFO become full, it stops filling it. When you read your sample you get measurement, which frees one cell and FIFO and allows sensor to collect one new sample. Later after 5 sec you read another sample from FIFO, but FIFO provided you 5 second old sample! Later after another 5 seconds you get third sample which is 10 seconds old now. So efficiently after 64 * 5sec interval you get sample providing you information that voltage changed. Because of very slow reading old samples are extremely delayed (delay is 5 minutes and 20 seconds) in your case.

    Possible solutions are:

    1. read them faster, this will not eliminate but will reduce the delay
    2. at every cycle read 64 samples and discard first 63
    3. use different than active mode (this is not supported by the library yet), for example single mode should works better in your use case
    4. manually flush FIFO (this is not supported by the library yet)
    5. use rollover feature of MAX40080 FIFO (this is not supported by the library yet)

    And lastly

    6) use configure() before reading. This workaround works because configure() function internally flushes FIFO. But of course, it is not efficient to reconfigure sensor every time.

    Thank you for this feedback. I did not realize this behaviour when programming it and I will consider changing mode of sensor for reducing delay when calling read function infrequently.

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

    An anomaly in readings I noticed during preliminary testing.

    I have the sensor reading the voltage of the locomotive motor sitting on the bench. I was holding off testing with the train on the track until I had some confidence in my methodology.

    I used your python library to read current and voltage at 5 sec intervals. At the elipse in the screen shot I changed the supply voltage from 5VDC to 3VDC, to simulate the locomotive speed being reduced. The readings after the voltage shift do not reflect the change.

    image

    To correct the issue I moved the max.configure method to the loop routine I use to make the measurement.

    image

    My reasoning is since the reference voltage has changed it is necessary to establish the configuration to obtain accurate readings. Is my train of thought correct or is there something else I need to consider?.

    • 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