Giter Club home page Giter Club logo

emapp's Introduction

Energy Meter APP

Welcome to Energy Meter application. This project implements an APP which measures the AC Energy Consumption. The system uses a Nucleo64 board which runs RIOT-OS and a current transformer as probe.

csv

The picture shows one of 3 data buffer which contain last samples of current

Requirements

  1. This project runs with RIOT:

RIOT powers the Internet of Things like Linux powers the Internet. RIOT is a free, open source operating system developed by a grassroots community gathering companies, academia, and hobbyists, distributed all around the world.

RIOT supports most low-power IoT devices and microcontroller architectures (32-bit, 16-bit, 8-bit). RIOT aims to implement all relevant open standards supporting an Internet of Things that is connected, secure, durable & privacy-friendly.

  1. RIOT has a lot of tutorials and course. There is not need any board because you can use a virtual machine.

  2. Energy meter application can runs on each application supported by riot.

Instructions

  1. Setup your system. I'm using fedora so the command that you find are based on my distro.

    $ sudo dnf update
    $ sudo dnf install arm-none-eabi-binutils-cs arm-none-eabi-newlib arm-none-eabi-gcc-cs arm-none-eabi-gcc-cs-c++
    $ sudo dnf install git-core make stlink make patch vim
    
  2. Checkout of the source code:

    $ mkdir app
    $ cd app
    $ git clone https://github.com/RIOT-OS/RIOT.git
    $ git clone https://github.com/Ciusss89/_riot-os_app.git
    

    The app directory should be contain two RIOT and _riot-os_app directory, setup the code:

    cd RIOT/
    git checkout <LATEST_RELEASE>
    cd ../_riot-os_app
    git checkout <LATEST_RELEASE>
    

    Where LATEST_RELEASE is last stable tag

Compile the app and Run

  1. Compile and write the application on the nucleo board:

    make clean all flash
    
  2. The Nucleo board has debug chip on-board. It connectes its virtual COM /dev/ttyACM0 to the SUART2 of the mcu. Connect to Nucleo64 board can run the command make term communication:

    make term
    

    Otherwise you can also use putty or picocom:

    sudo picocom -b 115200 /dev/ttyACM0 --imap lfcrlf
    

Project Overview

  1. Hardware:

I tested the project with a STM Nucleo64 board and it works obviously with others boards supported by Riot. Regarding the current probe I used a cheap current transformer (CT) which converts the induced current into a tension using burden resistor as transconductance amplifier.

  1. Option setup:

All relevant parameter are configurable by Makefile throught CFLAGS. The supported CT are: YHDC TA1020, YHDC SCT013-000.

  1. Algorithms:

The ADC samples a signal plus the DC bias. It collects continuously 12 samples for each 20ms and remove the DC bias offset. The data is filtered through moving average algorithm. There are four thread, the first take care of ADC conversion, the others store the realtime measure into two array (current, voltage). Each array collects 240 samples of last 60 seconds, last 10minutes, last 60minutes. Each array has been implemented as circular buffer.

  1. Implementation:

    system system

Examples:

Set debug mode 3 which prints the contents of buffer array, then you have to export the printed values into csv file.

Check the directory tests where there are saved measure.

You can take a look at this Google sheet which reports data and graphics

Eample of usage:

> reboot
�ain(): This is RIOT! (Version: 2021.04-devel-931-gbf93d)
RIOT on a nucleo-l476rg board, MCU stm32
[###] DEBUG LEVEL=3
Starting EnergMeter service...
[*] CT sensor setup:
	 RMS MAX current: 15A
	 Max primary peak current: 21.213203A
	 Max secondary peak current: 0.010607A
	 Burden resistor: 141.421356Ω
[*] ADC setup:
	 ADC bits: 8
	 ADC bias offset: 128
	 ADC scale factor: 0.011765
	 ADC sampling frequency: 600HZ
	 ADC gets [12] sample each 1666 usec
[*] ADC Calibration: Target=[128], Mesured=[126], Bias=[1.62422V]
[*] Energy Measuring: sampling has started
[*] Energy Measuring: collect_1m has started
[*] Energy Measuring: collect_10m has started
[*] Energy Measuring: collect_60m has started
> help
Command              Description
---------------------------------------
em                   em - energy meter application
reboot               Reboot the node
version              Prints current RIOT_VERSION
pm                   interact with layered PM subsystem
ps                   Prints information about running threads.
> em
Last 60s samples:
 id;Current;Voltage
  0; 0.24; 230.00
  1; 0.24; 230.00
  2; 0.29; 230.00
.
..
...
237; 0.73; 230.00
239; 0.53; 230.00
Last 10m samples:
 id;Current;Voltage
  0; 0.73; 230.00
  1; 0.53; 230.00
  2; 0.47; 230.00
.
..
...
238; 0.53; 230.00
239; 0.53; 230.00
Last 60m samples:
 id;Current;Voltage
  0; 0.73; 230.00
  1; 0.53; 230.00
  2; 0.47; 230.00
.
..
...
236; 0.53; 230.00
237; 0.55; 230.00
238; 2.33; 230.00
239; 2.53; 230.00
Current 0.407541A
Voltage 230V
last 60 seconds current average 0.39A
last 60 seconds voltage average 230.00V
last 10 minutes current average 0.41A
last 10 minute voltage average 230.00V
last 60 minutes current average 0.50A
last 60 minutes voltage average 230.00V

The final doc release is available here (only ita) Release documentation

Note: Documentation was written for tag v1.0. Documentation has been developed for the project of CYBER PHYSICAL SYSTEMS.

emapp's People

Contributors

ciusss89 avatar

Watchers

 avatar  avatar

emapp's Issues

Build Voltage probe

▸       /* save the rms measure of voltage and current */
▸       em->rms_c = ((rms_in_c * CT_RATIO) / bur_resistor);
▸       em->rms_v = 230; /* I don't have the voltage probe yet */
▸       (void)rms_in_v;  /* workaround to silent the -Werror=unused-but-set-variable*/

▸       return 0;

As shown before the acquisition loop is ready to compute the voltage measure.
Take a look here 1 2 3

bug: dynamic bit count selection doesn't work

  1. file energy_meter/core.h
  2. When the ADC_RES is equal to ADC_RES_10BIT the first entry is always true. Thas is wrong.
#define ADC_RES         ADC_RES_12BIT   /* ADC resolution */
#if ADC_RES == ADC_RES_12BIT
#define ADC_BIT         12U
#elif ADC_RES == ADC_RES_10BIT
#define ADC_BIT        10U
#endif

Memory usage optimization

  1. files energy_meter/main.c and energy_meter/core.h
  2. In order to optimize the system resource, we have to reduce the memory required by tread sampling and logging.
char em_sampling_stack[THREAD_STACKSIZE_SMALL];
char em_logging_stack[THREAD_STACKSIZE_LARGE];
  1. Instead, to use a type double for the struct we can use two uint8_t to store the decimal and the unit part
/* @em_realtime contains all notable datas:
 * -rms_c/v▸     : real time values, they're update each sec
 * -rms_*_1m▸    : last minute average, they're update each 60 sec
 * -log_1m_ready : true when last minute average is ready
 */
struct em_realtime {
▸       double rms_c, rms_v;
▸       double rms_c_1m, rms_v_1m;
▸       bool log_1m_ready;
};

/* @em_loggin contains all temporary datas
 */
struct em_loggin {
▸       double c[60], v[60];
};

When there's no load, the current value is not null due to the noise.

  1. file energy_meter/measure.c
  2. When there's no load, the current value is not null due to the noise. As a consequence when we compute the square in the function get_measure the amount error continue growing.
▸       /* !TODO: Remove dc bias, find better solution */                                                                                                                
▸       if(bias_rem)
▸       ▸       val -= BIAS_OFFSET;

#if VERBOSE >= 4
▸       /* WARNING: printf is much time expensive */
▸       printf("adc_measure: val=%d\n", val);
#endif

▸       return val;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.