STM32 Development

A couple of pictures of the prototyping :slight_smile: I was meaning to write up last Friday’s meeting before posting this, as the reason for Glyn and my action on this comes out of your encouragement to do so @pb66, @Robert.Wall @Paul and noting yours and @dBC’s post here . Last time we tried to get the STM32 up and running with Ken Boak’s help we didnt get very far as the toolchain wasn’t quite there yet for Arduino/PlatformIO.

STM32 F401RE and EmonTx Shield:

As well as removing the 5v pin and putting a solder jumper across from 3.3v to 5v I needed to make some minor changes to EmonLib to get it to run the ADC at 12bits rather than 10bits. For some reason analogRead seems to return only 0-1023?, while adc_read_value returns the full 0-4095.
I saw @mel asked a related question here and here.

Provisional EmonLib STM branch: GitHub - openenergymonitor/EmonLib at STM32
Diff comparison: https://github.com/openenergymonitor/EmonLib/compare/STM32

Basic example:

// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3
#include "EmonLib.h"             // Include Emon Library
EnergyMonitor emon1;             // Create an instance

void setup()
{  
  Serial.begin(9600);
  
  emon1.voltage(PA_0, 268.97, 1.7);  // Voltage: input pin, calibration, phase_shift
  emon1.current(PA_1, 60.606);       // Current: input pin, calibration.
}

void loop()
{
  emon1.calcVI(20,2000);         // Calculate all. No.of half wavelengths (crossings), time-out
  emon1.serialprint();           // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
  
  float realPower       = emon1.realPower;        //extract Real Power into variable
  float apparentPower   = emon1.apparentPower;    //extract Apparent Power into variable
  float powerFActor     = emon1.powerFactor;      //extract Power Factor into Variable
  float supplyVoltage   = emon1.Vrms;             //extract Vrms into Variable
  float Irms            = emon1.Irms;             //extract Irms into Variable
}

A quick comparison of resulting real power, apparent power, Vrms, Irms, power factor values from an arduino atmega328 (running at 3.3v) vs the STM32 F401RE (same shield and sensors). Standard deviation results seem quite variable… too early probably to make anything from that data.

STM_AVR.ods (26.6 KB)

2 Likes