---
title: "Simple Power Meter with W5100S-EVB-PICO"
url: "https://maker.wiznet.io/ronpang/projects/simple-power-meter-with-w5100s-evb-pico/"
markdown_url: "https://maker.wiznet.io/ronpang/projects/simple-power-meter-with-w5100s-evb-pico/md"
type: "WCC: WIZnet Created Content"
author: "ronpang"
author_url: "https://maker.wiznet.io/ronpang/"
original_author: "Ron Pang"
license: "Apache License 2.0 (Apache-2.0)"
published: "2023-07-21"
language: "en"
hardware: ["WIZnet W5100S-EVB-Pico"]
likes: 2
views: 410
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Simple Power Meter with W5100S-EVB-PICO

> Simple Power Meter with W5100S-EVB-PICO

Original author: Ron Pang

## Components

- **WIZnet W5100S-EVB-Pico** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5100S/w5100s-evb-pico))

## Documents and links

- [W5100S-EVB-PICO + MAX471](https://github.com/wiznetmaker/W5100S-EVB-PICO-MAX471-CPY/tree/main) (code)

## Article

## **Story**

It has been a while since I make my last application [WizFi Chip counter](https://www.hackster.io/ron-pang/wizfi-chip-counter-device-4ef97c) .

This time I will start from the basic to develop some application related to power metering.

For this project, I used a MAX471 module that I found from the internet that has been used on most of the arduino application.

As I know, this kind of solution is not that accurate. However, this will be a great starting point for me to learn how to calibrate these sensors and learn how to create a simple metering with this module.

My application will use circuitpython for my environment to use W5100S-EVB-PICO to upload information collected from MAX471 to Adafruit IO

First of all, let's see how I make this happen.

`**Structure**`

![Connection Diagram for W5100S-EVB-PICO + MAX471 + Adafruit IO](https://hackster.imgix.net/uploads/attachments/1613269/image_X2d2ZWgqnl.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Connection Diagram for W5100S-EVB-PICO + MAX471 + Adafruit IO

From the image above, you could see the module MAX471 is a module that could measure Voltage and current readings from the circuit.

In a simple way to explain this application is mainly used MAX471 and related circuit inside the module to collect data from the electrical circuit.

From the data of MAX471, I will take an average values from the readings and uploaded to adafruit IO using MQTT protocol.

### **Step 1: Test the accuracy and calibration of the module.**

I had made a simple library based on MAX471's reading.

The programming method is getting values from the ADC pins and convert it those ADC values back to voltage and current.

Since RP2040 and circuitpython has set this board could convert into 16bit ADC resolution, this means the range will be from 0 - 65535

Also, Pico board is a 3.3V board. The voltage range is 3 - 16.5V and current range is 0 - 3A

Thus, I had made some simple test code as follow.

```plaintext
voltage = analogio.AnalogIn(board.A0)
current = analogio.AnalogIn(board.A1)
v_result = voltage.value * 16.5 / 65535 #in V
c_result = current.value * 3000 /65535 #in mA
print(("{:.2f} V").format(v_result))
print(("{:.2f} mA").format(c_result))
```

From the readings, I found that the accuracy are not stable. So I took a average to get a stable result.

After the values became a bit stable, I found that the current value is a bit higher than the values that get from the multimeter.

Thus, I need had go some digging on how to calibrate the module from the internet and ChatGPT.

From the help on internet and ChatGPT, I made a calibration table as follow.

![Calibration on Current and Voltage](https://hackster.imgix.net/uploads/attachments/1613272/image_ihiX2RDU1W.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Calibration on Current and Voltage

X is the readings from multimeter and Y is readings from MAX471

By having these values, I had used the formula provided by Excel to calibrate my module to be more accurate.

The following link is the method that I had used to find the formula from Excel:

[YouTube of Calibration](https://youtu.be/8efZRBCFpRg)

Finally, I had made it into class format and the work for MAX471 has been done.

```plaintext
class MAX471:
    
    def __init__ (
        self, voltage_pin: pin, current_pin: pin
        ) -> None:
        self.voltage = analogio.AnalogIn(voltage_pin)
        self.current = analogio.AnalogIn(current_pin)
    
    def Voltage(self):
        """ Voltage measure  (calibrated) """
        n_result = 0
        for i in range(20):
            n_result += self.voltage.value
            time.sleep(0.1) 
        result =(((n_result * 0.825) / 65535) * 1.0213) - 0.141
        display = ("{:.2f}").format(result)
        self.v_result = result
        return display
    
    def Current(self):
        """ Currrent measure (calibrated)"""
        n_result = 0
        for i in range(20):
            n_result += self.current.value
            time.sleep(0.1) 
        result = (((n_result * 150) / 65535) * 1.0789) - 8.0218
        display = ("{:.2f}").format(result)
        self.c_result = result
        return display
```

### **Step 2: Calculate the Power usage**

From the above data collection, I could easily calculate the Power usage of the resistors.

The following is the electrical formula of Power

Power (mW) = Current (mA) * Voltage (V)

Codes:

```plaintext
def Power(self):
        """Power = Current * Voltage"""
        result = self.c_result * self.v_result
        display = ("{:.2f}").format(result)
        return display
```

### **Step 3: Upload to Adafruit IO for display**

Since I got all the information, I could easily upload those data to IOT platform.

From my experience of my previous projects and the help of WIZnet's [RP2040 circuitpython library](https://github.com/Wiznet/RP2040-HAT-CircuitPython).

Based on the sample code provided by WIZnet, I could create a communication between Adafruit IO using W5100S-EVB-PICO.

For details, please refer to [my full code](https://github.com/wiznetmaker/W5100S-EVB-PICO-MAX471-CPY/blob/main/MAX471_aio.py).

`Results:`

![Reuslt from adafruit IO and Thonny](https://hackster.imgix.net/uploads/attachments/1613584/result_image_msTdBD9pHU.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Reuslt from adafruit IO and Thonny

`YouTube:`

[Embedded media](https://www.youtube.com/embed/jwoHVAOM6ug?rel=0)

*YouTube Demo*

### **Next Plan:**

I will try to develop an power metering to measure the solar pannel. Hope it will work.

---

Source: https://maker.wiznet.io/ronpang/projects/simple-power-meter-with-w5100s-evb-pico/
