LCD problem.

Hi
Please look at this line on the end of the code.

 lcd.print(Uo);   // Displays "0.00" instead of the same value as U

Can you help me to fix that please ?

[code]// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3

#include "EmonLib.h"             // Include Emon Library
#include <LiquidCrystal.h>
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
EnergyMonitor emon1;
float  cur, acur[50], sumc;
float Uo;

int (clear);
int (Irms);
const int ResetPin = PB12;

int H;
void setup()
{

  pinMode(ResetPin, INPUT_PULLDOWN);
  pinMode(PA7, INPUT);    // I2
  lcd.begin(16, 2);

  Serial.begin(9600);

  emon1.current(PA7, 2.8);  //  2.8 = U calibration

}

void loop()
{

  if (digitalRead(ResetPin) == HIGH)


  {
    //////////////////////////////////////
    Uo = Irms;
    //Uo =  emon1.Irms;
    //Irms = emon1.Irms;

    ////////////////////////////////////
  }
  else
  {

  }

  //emon1.calcVI(20, 2000);
  emon1.calcVI(20, 2);
  emon1.serialprint();

  float Irms = emon1.Irms;

  lcd.setCursor(0, 1);
  lcd.print("U");
  lcd.print(Irms);

  lcd.setCursor(5, 1);
  lcd.print("o");
  lcd.print(Uo);   // Displays "0.00" instead of the same value as U

  delay (500);

}

[/code]

For 1428 posts you seem to have a strange view of C++ syntax.

You have a global Irms and a local Irms. Uo is assigned the value of the global Irms which incidentally is never changed from its BSS value.

David.

For 5,042 you should know the solution. I did myself, thanks.

#include "EmonLib.h"             // Include Emon Library
#include <LiquidCrystal.h>
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
EnergyMonitor emon1;
float  cur, acur[50], sumc;
float Uo;
int LED =  PB15;
int (clear);
int (Irms);
const int ResetPin = PB12;

int H;
void setup()
{

 
}

void loop()
{

  if (digitalRead(ResetPin) == HIGH)


  {
    Uo =  emon1.Irms;
  }
  else
  {

  }

  //emon1.calcVI(20, 2000);
  emon1.calcVI(20, 2);
  emon1.serialprint();

  float Irms = emon1.Irms;

  lcd.setCursor(0, 1);
  lcd.print("U");
  lcd.print(Irms);

  lcd.setCursor(5, 1);
  lcd.print("o");
  lcd.print(Uo);   // Displays "0.00" instead of the same value as U

Seriously, it is unwise (tm) to have a global and a local with the same name.

I don't want to cause offence. As a learner it is well worthwhile to study and review your code.

  1. Choose intuitive names,
  2. choose whether a variable should be global or local.
  3. Remove any extraneous statements.
  4. Be happy with the program logic.

This applies to experienced programmers too. And I bet that you spot hardware problems created by software authors !!

David.

david_prentice:
Seriously, it is unwise (tm) to have a global and a local with the same name.

They are also different types.

int (clear);
int (Irms);

@ted, what makes you think these globals deserve parentheses, and the others don't?
I'm genuinely curious about your thought processes, and concepts of syntax.

Thanks for advice,problem with LCD is solved,I have a new one - LED.
LEDon PC14 is not responding to this command.

 if (PB13 == 1 && PB15 == 1)
 if (PB13 == 1 && PB15 == 1)
  {
    digitalWrite(PC14, HIGH);
    LED = 1;
  }
  else
  {
    digitalWrite(PC14, LOW);
    LED = 0;
  }

@AWOL
Can you make some improvement in code posting,this is how it is look in another forum.

These symbols are not part of Arduino:
PA0, PA1, PA2, PA3, PA4, PA5
PB13, PB15, PC14

Some of them are contained in the i/o header files that come with the avr-gcc package but which ones vary depending on which AVR processor the code is being built for.
But none of them are part of Arduino.

I'm not sure what you think they are but I'm fairly sure that they are not what you think they are.

What do you think those are?

What Arduino board and processor core are you using?

--- bill

This is not a problem with the name of the pins,they are from stm32, is the line mentioned correctly written?
The LEDs on pinss PB13and pb15 are working properly.

I am using arduino IDE.

OK so those symbols are pin names from the stm32 core.
Definitely not portable and not part of Arduino but ok they represent pin numbers when using the stm32 core.

Given that, this line makes no sense:

if (PB13 == 1 && PB15 == 1)

As PB13 and PB15 would be constants and are either 1 or some other number and it is very likely that PB13 and PB15 are not both pin 1, so that expression inside the if would evaluate to false which means that the compiler would through away everything inside the true part of the if statement and would keep the else side of the if statement.

Which means that this:

if (PB13 == 1 && PB15 == 1)
  {
    digitalWrite(PC14, HIGH);
    LED = 1;
  }
  else
  {
    digitalWrite(PC14, LOW);
    LED = 0;
  }

Is the same as if the code were written this way:

    digitalWrite(PC14, LOW);
    LED = 0;

Since the if expression will always evaluate as false and only the else code will be executed.

So again I ask what do you think those symbols are/represent/do?

--- bill

if (digitalRead(PB13) == HIGH  && digitalRead(PB15) == HIGH)

This Is working

bperrybap:
These symbols are not part of Arduino:
PA0, PA1, PA2, PA3, PA4, PA5
PB13, PB15, PC14

The symbols
The firstline = arduino pins names.
The second = stm32 pin names.

ted:
The symbols
The firstline = arduino pins names.
The second = stm32 pin names.

Nope.
The first line of symbol names (PA0 to PA7) are not Arduino pin names.
Arduino uses A0, A1, A2, A3 ....
and in newer IDE releases it also provides PIN_A0, PIN_A1, etc... symbol names.

PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7 are register bit number symbols in AVR processor specific system header files that are part of avr-gcc tools but those names are not part of Arduino.
They are defined to be 0, 1, 2, 3, 4, 5, 6, 7

i.e. they are available when compiling Arduino sketch or library code for AVR processors but they are not part of Arduino.
Just like h/w symbols like DDRA, PORTB, PORTB5, and a slew of many other h/w symbols.
They can be used when building Arduino code for an AVR processor but they are not part of Arduino.

--- bill

Correction, both lines for stm32 are the pins numbers.Any way, the problem was in suspected line,

It is a bit unfortunate that only the stm32 specific pin symbol names are printed on the PCB rather than also showing the Arduino digital pin numbers.
Some boards like Teensy print both. The AVR/teensy specific symbol names on one side and the Arduino pin numbers on the other.

I also went and looked at the stm32 variant files and they are also not declaring the Arduino An symbols for the analog channels.
i.e. A0, A1, A1 etc....

--- bill

Many of the arduino programs are working with stm32, just by renaming the pin names, but set the timers is different.
Can you help me with that ?
This are two codes,one for arduino the second one for stm32.
Please fill the lines with question mark if you can.

 // Set up timer 1.
// Prescaler = 1, phase correct PWM mode, TOP = ICR1A     //phase correct PWM mode 
TCCR1A = (1 << COM1A1) | (1 << WGM11);                      // ?
TCCR1B = (1 << WGM12) | (1 << WGM13) | (1 << CS10);      // CTC mode, prescaler = 1,
                                      
                                                       // What does it mean CTC mode ?
TCCR1C = 0;                                     // Timer/Counter Control Register A,                / 0 = ?
OCR1AH = (TIMER1_TOP / 2 >> 8);       // Output Compare Register A High                 / Output Compare Register A High ?
OCR1AL = (TIMER1_TOP / 2 & 0xFF);     // Output Compare Register A Low                / TOP/2 & 0xFF = ?
ICR1H = (TIMER1_TOP >> 8);              // Output Compare Register B High                / TOP & 0xFF ?
ICR1L = (TIMER1_TOP & 0xFF);           //  Output Compare Register B Low               / TOP & 0xFF ?
TCNT1H = 0;                           // Timer/Counter Register High (The Timer - High)   / 0 = ?
TCNT1L = 0;                           // Timer/Counter Register Low (The Timer - Low)     / 0 = ?
TIFR1 = 0x07;                         // clear any pending interrupt = refresh ?               / 0 = ?
TIMSK1 = (1 << TOIE1);           // = resume ?
STM32F103

HardwareTimer pwmtimer3(3);             //timer #3
void setup() {
  pinMode(PA7, PWM);
  pinMode(PB0, PWM);
  pwmtimer3.pause();
  pwmtimer3.setPrescaleFactor(1);       // Timer input clock Prescaler = 1 
  pwmtimer3.setOverflow(100-1);         // PWM Period width for 720kHz 
  pwmtimer3.setCompare(TIMER_CH3, 50);  //  CH#3 -PWM High Pulse width is 50% duty (1:1)
  pwmtimer3.setCompare(TIMER_CH2, 50);  // PWMCH#2 High Pulse width is 50% duty (1:1)
  pwmtimer3.refresh();
  pwmtimer3.resume();