element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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
Community Hub
Community Hub
Member Blogs Testing Sensors using the MCP2221A and Jupyter Notebooks
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Leaderboard
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Community Hub to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ralphjy
  • Date Created: 30 Sep 2020 12:38 AM Date Created
  • Views 2719 views
  • Likes 4 likes
  • Comments 2 comments
  • python
  • i2c
  • sensors
  • mcp2221
  • jupyter notebooks
  • anaconda
Related
Recommended

Testing Sensors using the MCP2221A and Jupyter Notebooks

ralphjy
ralphjy
30 Sep 2020

I've been taking a break from FPGA projects for the last couple of weeks.  We've had hazardous air quality due to the wildfires and even indoors with a HEPA filter I've found it difficult to concentrate.

 

I was browsing the Adafruit store looking for a board to try running TinyML and I stumbled upon a very inexpensive MCP2221A Breakout board ($6.50)  ADAFRUIT MCP2221A Breakout.

 

I know that shabaz  and others have used the MCP2221 as a USB to UART interface on PCBs that they've built but I had never really looked at the part specification.  Turns out that it is very versatile - in addition to the UART it has an I2C interface and 4 GPIO pins.  The GPIO pins can also be used as 3 10 bit ADC inputs or a 5 bit DAC output.  The board has a USB-C connector for the host interface and power and a Stemma-QT (QWIIC) connector to interface an I2C sensor.  The MCP2221 pins are also broken out into a breadboard friendly 0.1" pattern.

 

image

 

Adafruit has a great tutorial on using this board with CircuitPython so that you can test sensors using your host computer (Windows, Mac, Linux) directly without needing to use a microcontroller board.  What really caught my attention was the tutorial that they have on using the MCP2221 with Jupyter Notebooks and CircuitPython libraries: jupyter-on-any-computer-with-circuitpython-libraries-and-mcp2221.   I've been using Jupyter Notebooks with PYNQ on the Zynq FPGA boards and I like the capability to prototype and document your code, so I thought that I'd give this a try.

 

The recommendation is to use Anaconda which installs Python and Jupyter Notebook.  I already have a working installation of Python on my Windows 10 computer but because Anaconda includes and manages a diverse set of tools - I decided to install it as an independent framework that allows me to access the tools it is managing only through the Navigator Panel (basically just don't allow it to change PATH or Registry entries when it installs).  Anaconda is an open source platform (distribution) that includes a number of preinstalled programs targeted at Data Science applications.  It is supposed to handle dependency management better than the PIP package manager.  If it works well I may opt in the future to use it rather than the separately installed programs.

 

Here's a screenshot of the Navigator Panel after installation:

image

 

Jupyter Notebook will launch in a browser window at http://localhost:8888/notebooks - you just pick which browser if you have multiple installed - I tend to use Chrome.  You also need to have set up the MCP2221 with Adafruit Blinka so that it is configured for CiruitPython: circuitpython-libraries-on-any-computer-with-mcp2221/setup.   When you use the MCP2221 you need to set an environment variable BLINKA_MCP2221 = 1 to identify it.

 

Test using BME280 I2C sensor

I decided to try using a BME280 sensor which measures temperature, humidity, and barometric pressure.  The BME280 can communicate via I2C or SPI but this particular board only pins out the I2C.  The sensor board also does not have a QWIIC connector so I did the hookup on a solderless breadboard.

image

 

It's easiest to use a sensor that has a CircuitPython library available.  The first step is to install the appropriate library.  This step is only required the first time that you use a new sensor type.

Here is the output from the Jupyter Notebook.  I could have run this from a terminal but it's useful to have the installation documented.

image

Then set the board environment variable.

image

Print out the sensor readings.  Altitude is computed from barometric pressure so it is somewhat inaccurate.  The altitude at this location should be about 119 meters.

image

                              image

 

Display the temperature data as it's captured.  I perturbed the temperature by putting my finger on the sensor.

image

 

   

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Seems like a very useful setup to play with sensors before I try to use them in specific applications.  It will also allow me to get more experience with Jupyter Notebooks and the price was certainly right for that MCP2221 breakout board image!

  • Sign in to reply

Top Comments

  • fmilburn
    fmilburn over 4 years ago +4
    Thanks Ralph, This seems quite useful. I am about to make an Adafruit order and will get one. Frank
  • shabaz
    shabaz over 4 years ago +4
    Hi Ralph, Nice write-up! It is a cool chip, and handy that it's available in quite a few package sizes, even DIP. I hadn't realized it had ADC/DAC capability, I've only used it for USB-UART so far. It…
Parents
  • shabaz
    shabaz over 4 years ago

    Hi Ralph,

     

    Nice write-up! It is a cool chip, and handy that it's available in quite a few package sizes, even DIP.

    I hadn't realized it had ADC/DAC capability, I've only used it for USB-UART so far. It sounds perfect for a lot of experimentation.

     

    Although that will still be my favourite USB/UART chip, I've recently started looking at the Cypress chips, because there's a feature I miss in the MCP2221, which is hardware flow control pins and sometimes that's needed. Incidentally some of the Cypress chips support built-in I2C too, but don't have the ADC/DAC. The package selection isn't as great either (one is SSOP but all the others are QFN). I'm trying CY7C65213 which is SSOP sized, but doesn't have I2C unfortunately. I hope the drivers etc are good, it's my first attempt at using a Cypress USB-UART chip.

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • shabaz
    shabaz over 4 years ago

    Hi Ralph,

     

    Nice write-up! It is a cool chip, and handy that it's available in quite a few package sizes, even DIP.

    I hadn't realized it had ADC/DAC capability, I've only used it for USB-UART so far. It sounds perfect for a lot of experimentation.

     

    Although that will still be my favourite USB/UART chip, I've recently started looking at the Cypress chips, because there's a feature I miss in the MCP2221, which is hardware flow control pins and sometimes that's needed. Incidentally some of the Cypress chips support built-in I2C too, but don't have the ADC/DAC. The package selection isn't as great either (one is SSOP but all the others are QFN). I'm trying CY7C65213 which is SSOP sized, but doesn't have I2C unfortunately. I hope the drivers etc are good, it's my first attempt at using a Cypress USB-UART chip.

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
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