Cover image
Try Now
2023-05-15

MCP342X(MCP3421,MCP3422,MCP3423,MCP3424)ADC 18位1-4频道Arduino图书馆

3 years

Works with Finder

5

Github Watches

6

Github Forks

17

Github Stars

MCP342x Library for Arduino

Repository : https://github.com/battosai30/MCP3424

Author: B@tto

Contact: batto@hotmail.fr

Current version

1.9.4

History

  • 1.9.4 15/05/2023 : fix bad units in examples (microvolt instead of nanovolt)
  • 1.9.3 25/01/2023 : revert back about typedef enum etc ... Caused issues on ESP32
  • 1.92 06/04/2022 : add some constrain in setConfiguration() to avoid out of index crashes, and add a getAddress() function to get i2c computed real address
  • 1.9 27/08/2021 : changed CHANNELS to byte type in setConfiguration()
  • 1.8 26/02/2019 : correction for 16-bit platform (bad bit shifting during 18-bits acquisition)
  • 1.7 25/07/2019 : support on MCP3421 confirmed, changed to MCP342x. Update examples
  • 1.6 19/04/2019 : Bug correction
  • 1.3 26/01/2017 : Multichannel example had a bug (out of index error on Voltage[]) and code was rewritten
  • 1.1 06/12/2012 : issues with detection of a finished conversion has been resolved
  • 1.0 15/07/2012 : initial release

Description

MCP342x (3421/22/23/24) is a I2C 1/2/3/4 channels, 18 bits resolution ADC controlled over I2C.

It has an internal reference of 2.048V and an on-board programmable gain amplifier (PGA).

Supply : 2.7V to 5V

Resolution is programmable (12, 14, 16 or 18 bits).

Download, install and import

  • Download zip
  • Put the MCP3424 folder in "hardware\libraries".
  • In the Arduino IDE, create a new sketch (or open one) and
  • Select from the menubar "Sketch->Import Library->MCP342x".
  • Once the library is imported, an "#include <MCP342x.h>" line will appear at the top of your sketch.

Creation

MCP3424(int address) -> Create instance of MCP342x.Address is A2A1A0 (refer to datasheet). For example, if pins Adr0 and Adr1 are high, the instanciation would be "MCP342x MCP(6)" because A2=1 A1=1 A0=0 so in binary 110 and 6 in decimal.

Methods

void setConfiguration(byte channel,RESOLUTION resolution,MEASURE_MODE mode,PGA pga) -> send the configuration byte to the MCP3424.

Available MEASURE_MODE :

  • ONE_SHOT_MODE
  • CONTINUOUS_MODE

Available RESOLUTION :

  • RESOLUTION_12_BITS
  • RESOLUTION_14_BITS
  • RESOLUTION_16_BITS
  • RESOLUTION_18_BITS

Available CHANNELS :

  • CH1
  • CH2
  • CH3
  • CH4

Available PGA :

  • PGA_X1
  • PGA_X2
  • PGA_X4
  • PGA_X8

getConfiguration() -> return the rax value of the configuration register.

getRawDatas(uint8_t buffer[4]) -> fill the array passed as argument with raw result (means without conversion to mv). Mainly intended for debug.

long measure() -> Return the result of the lastest conversion in nanoVolt. Note that the library waits for a complete conversion.

void newConversion() -> in one-shot mode, initiate a new conversion

int isConversionFinished() -> Returns 1 if conversion is not finished, 0 if it's completed

Examples

One-Shot conversion -> the conversion is initiated by the user

Multichannel -> classic use scanning all the channels

FAQ

How can I use multiple MCP342x object ?

MCP342x is a class, like any class you can drive any numbers of chip you want with only 2 single pin (Adr0 and Adr1) but by setting different address for each.

I can't measure voltage over 2.048V, why ?

Because the internal reference is 2.048V, but if you use it in differential mode, you can use it from -2.048V to +2.048V. Another solution is to use a voltage divider (2 x 1k resistors or example).

I'm not measuring voltage over 2.048V but my MCP342x seems to be saturated, why ?

Maybe you are using the programmable amplifier (PGA). In fact, the limit of 2.O48V is effective after it, so if your voltage multipliates by the PGA is superior to 2.048V, the ADC is saturated.

I get compilation errors, why ?

Check where you get the library : a (very) old version of mine is still given by some chinese manufacturers, and leads to errors. Simply get the last version on github.

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • Lists Tailwind CSS classes in monospaced font

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • https://appia.in
  • Siri Shortcut Finder – your go-to place for discovering amazing Siri Shortcuts with ease

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • tomoyoshi hirata
  • Sony α7IIIマニュアルアシスタント

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

  • WangRongsheng
  • 🧑‍🚀 llm 资料总结(数据处理、模型训练、模型部署、 o1 模型、mcp 、小语言模型、视觉语言模型)|摘要世界上最好的LLM资源。

  • appcypher
  • 很棒的MCP服务器 - 模型上下文协议服务器的策划列表

    Reviews

    5 (1)
    Avatar
    user_1Gf6eXHx
    2025-04-17

    The MCP3424 is a fantastic high-resolution ADC that has been a game-changer for my projects. Easy to use and integrate, it offers precise measurements that are crucial for data accuracy. The support and documentation provided by battosai30 are excellent, and the GitHub repository is well-maintained and helpful. Highly recommended for anyone needing reliable and accurate ADC solutions!