Skip to main content

## Python Library for Upbeat Labs Dr. Wattson board (and MCP39F521)

Python library to use with Dr. Wattson Energy Monitoring Board or other MCP39F521 based boards with a Raspberry Pi (or Beaglebone Black).

Specifically designed for use with Dr. Wattson Energy Monitoring Board –> [https://www.protostax.com/products/dr-wattson-energy-monitoring-board-v2/](https://www.protostax.com/products/dr-wattson-energy-monitoring-board-v2/)

Dr. Wattson is an Energy Monitoring Breakout Board for Arduino and other Maker-Friendly Microcontrollers. Easily integrate quality AC energy measurements into your next project!

Based on the MCP39F521, a single-phase power monitoring chip from Microchip, the board is designed to be tolerant of a wide range of voltages, which means that it can also be used with the Raspberry Pi or any other 3.3v MCUs just as easily.

The unit comes pre-calibrated, enabling you to start taking quality measurements from 90-240v, at either 50 or 60 Hz, and for currents up to 15A. You don’t need any additional CT/VT or other components. With the libraries here, you can start taking measurements on the get-go with just a couple of simple commands.

If you are a more advanced user, you have a wide range of functionality available from the rich library, as well as the ability to tweak the hardware to suit your needs and recalibrate using the library.

![Dr. Wattson Energy Monitoring Board](https://cdn.shopify.com/s/files/1/0082/6248/4004/products/DrWattsonV2_title.jpg?v=1661905914)

[Learn more and get it here!](https://www.protostax.com/products/dr-wattson-energy-monitoring-board-v2/)

## Prerequisites

Enable I2C on the Raspberry Pi

Refer to [Dr. Wattson User Manual](https://github.com/upbeatlabs/drwattson/blob/master/DrWattsonUserManual.pdf) to set up Dr. Wattson

Tested and works with Python 2.7 and Python 3.x on Raspberry Pi (use pip3 or python3 for Python 3 install)

## Installing

` sudo python -m pip install --upgrade setuptools wheel sudo pip install UpbeatLabs_MCP39F521 --upgrade ` Or alternatively:

` sudo python -m pip install --upgrade setuptools wheel git clone https://github.com/upbeatlabs/drwattson.git cd drwattson/Python sudo python setup.py install `

## Usage

### Connect Dr. Wattson

See Dr. Wattson User Manual for more details.

![RPI & Dr. Wattson Wiring](RPI_DrWattson_wiring.png)

Here is the wiring, from left to right

  • SCL to RPI (physical) pin 5 (SCL)

  • SDA to RPI (physical) pin 3 (SDA)

  • ZCD pin (optional) - RPI (physical) pin 16 (GPIO23) (or any available GPIO pin)

  • Event pin (optional) - RPI (physical) pin 18 (GPIO24) (or any available GPIO pin)

  • GND to RPI (physical) pin 14 (GND)

  • Vin to RPI (physical) pin 1 (3.3v)

  • 3.3v to RPI (physical) pin 17 (3.3v)

  • GND to RPI (physical) pin 9 (GND)

Optionally, * connect LED Anode to RPI (physical) pin 12 (GPIO18) (or any available GPIO pin) via 220 ohm resistor * connect LED Cathode to RPI (physical) pin 6 (GND)

### Test I2C connection You’ll need to configure the solder jumpers on the Dr. Wattson board to set the I2C address you’d like to use. See Dr. Wattson User Manual for more details.

Use i2cdetect -y 1 to test the connection.

[Note: you can configure the addressing using two solder jumpers on the board, for a total of 4 possible combinations (that correspond to addresses of 0x74, 0x75, 0x76 or 0x77). This means that you can connect up to 4 Dr. Wattson boards using a single MCU]

` pi@raspberrypi:~ $ i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- 74 -- -- -- `

### Run Examples

See example code under the examples/ directory See comments in each example for more details on setup

` cd examples python getEnergyData.py `

## License

A lot of time and effort has gone into providing this open source library. Please support Upbeat Labs by purchasing products from Upbeat Labs!

Written by Sridhar Rajagopal for Upbeat Labs. BSD license, all text above must be included in any redistribution

Release files for UpbeatLabs-MCP39F521 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for UpbeatLabs-MCP39F521 2.0.0
File Size Uploaded
UpbeatLabs_MCP39F521-2.0.0.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for UpbeatLabs-MCP39F521 2.0.0
File Interpreter ABI Platform
UpbeatLabs_MCP39F521-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.3 kB

Release files / UpbeatLabs_MCP39F521-2.0.0.tar.gz

Download URL UpbeatLabs_MCP39F521-2.0.0.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
93fb4eaa3ce691c388c4b0980e12c96e0641a821f96f219c6660041973be31f7
BLAKE2b-256 checksum
How to use checksums
4750bdc78e6e7737d252d31d2696ad185378c93ac7527beaba71df022bdee5d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.6

Release files / UpbeatLabs_MCP39F521-2.0.0-py3-none-any.whl

Download URL UpbeatLabs_MCP39F521-2.0.0-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
41e0886023a9c66a11763f9dd79d92fde7b07e5f0aeaae8f9cc17fe92ddcc55e
BLAKE2b-256 checksum
How to use checksums
c0d7ed58d6718468896ae3237fe384b96b6eb3746f4255bd3132585997688c9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.6

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.1

1 release file

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page