Project photovoltaic hybrid

Good personal'm developing a project where I use 3 current sensors to make reading a photovoltaic system where one is used at the output of the other panels in batteries and another to the inverter output and am sending the values ​​to a 20x4 LCD that intragir my idea is to see how these three sensors produce a day and so spared. . Now I am 2 am new to programming problems.
I put a button to change the LCD screen because the values ​​do not all fit in a single, managed to make the button change but the lcd screen is always flashing to change the values​​. And I wanted to change the values ​​without having to flash the lcd. as had previously without swich
  The other problem is that I wanted compute power per hour and current hour and two of my sensors operating at 12Volts (batteries and panels) and the other to 230Volts (inverter) would appreciate the help if you need anything tell.

greetings

Robert Wall's picture

Re: Project photovoltaic hybrid

To solve your problem with the GLCD screen flashing, look at the sketch for the emonGLCD here.  You write the new numbers to the display like this

    char str[50]; //variable to store conversion
    glcd.setFont(font_clR6x8);
    strcpy(str,powerstr);
    strcat(str," NOW:");
    glcd.drawString(0,0,str);

then when all the strings have been drawn, refresh the display:

    glcd.refresh();

If your problem is making the switch work, look at this sketch. You must remember the state of each switch and only change the display once each time you press the switch:

    last_switch_state = switch_state;
    switch_state = digitalRead(switch1);
    if (!last_switch_state && switch_state)
    {            // change to next page each time the switch is pressed
        page += 1;
        if (page>4)
            page = 1;
    }

    if (page==1)
    {

      // Do page 1

    }
    else if (page==2)
    {

      // Do page 2

    }

I do not know what you mean: "Power per hour". Power is the rate at which energy flows. Power = Energy / time.

You can use a current transformer to measure the alternating current out of your inverter. You must use a current shunt or a Hall effect sensor to measure the d.c. current from your batteries or P.V. panels.

When you measure battery current, you can calculate the battery charge = current × time.

wilssman's picture

Re: Project photovoltaic hybrid

My code is this function used the case and I have to do a refresh then the LCD will blink every second I enter the LCD below and would be grateful if someone could tell me how to use the tool if instead of the case so the LCD does not flicker or do is refresh.

Robert Wall's picture

Re: Project photovoltaic hybrid

I do not have a display like the one that I think you have, but I think I see what your problem is.

First you clear the display with lcd.clear();  then you do the function that writes the display one character at a time.  That means that the display becomes cleared and the first character is written immediately, but the last character is written a long time later. You do this every 1 second. That is why the display is flashing.

Instead, I think you should only clear the display when you change from one page to the next. When you print a number that might change, for example corrente45, you do exactly the correct thing. You erase the old number by writing spaces, then you write the new number:

lcd.setCursor(9, 2);                                            // Local no LCD onde se vi iniciar o resultado da corrente de AC
lcd.print("    ");                                              // Limpeza do LCD dos resultados anteriores
lcd.setCursor(9, 2);                                            // Local onde se vai iniciar no LCD o resultado da corrente em AC
lcd.print(corrente45);                                          // Apresentação da corrente de AC no LCD

You have no need to clear the display every 1 second.

Here you remove these lines:

switch(var_menus%NUM_MENUS) {

case 0:
  lcd.clear();
  vinstantaneo();
  break;

case 1:
  lcd.clear();
  vhora();
  break;
}

And in loop( ) you clear the display:

if (digitalRead(SWITCH) == HIGH && encrava == 0)
{
  var_menus++;
  lcd.clear();
  trata_lcd();
  encrava = 1;
}

 

wilssman's picture

Re: Project photovoltaic hybrid

Thank you was tired of looking like they did and could not is optimal.
I wonder if you know how to calculate the cumulative value of each of the sensors and also the hourly rate of each mean to tell me if I make one for the other can not see how it's done.
Again thank you

greetings

Robert Wall's picture

Re: Project photovoltaic hybrid

For "cumulative value" you will be calculating battery charge in ampere-hours (Ah) or energy in watt-hours (Wh).

You are updating the display every second, but you only read the values when you display them. You must move the code that reads the values into trata_lcd() but outside switch( )  so that it is executed every second no matter which screen is showing. Also there you must have an accumulator that adds on the quantity every second. Remember that you will have ampere-seconds or watt-seconds so to display the value in ampere-hours or watt-hours, you must divide by 3600. Be careful that you choose the type of variable (long) that is big enough to hold the largest number.

For the average over an hour, you must store the cumulative value and the time , then one hour (3600,000 milliseconds)  later, you read the value now and calculate the average, then store the cumulative value again ready for the next hour. You might have enough memory free to be able to store the value every 10 minutes in an array working as a circular buffer, then every 10 minutes you could see the average over the last hour.

wilssman's picture

Re: Project photovoltaic hybrid

(You are updating the screen every second, but you only read the values ​​Them When You display. You must move the code that reads the values ​​in trata_lcd () but the key off () so that it runs every second, matter what the screen is showing.) I do not understand this because I am newbie and am trying to learn the much as I can. I have to have a routine always read in the void loop () right on the screen is correct or not.

How do programming to calculate ampere hour and watt hour, my big problem is to move everything to the schedule. In relation to the Accumulated value I have a button that will reset the function and the idea is that every time I touch this button to start the Accumulated value of 0 my problem this whole idea is to insert the code already built.

greetings

Robert Wall's picture

Re: Project photovoltaic hybrid

but you only read the values ​​Them When You display.

No, I am sorry, I was wrong there. When I looked very carefully at your sketch, you are reading the analogue inputs in both screens.

But that is not the best way. You should try not to do the same thing twice in different places - it will lead to mistakes. I will change your sketch to show you. I need a day to do that.

Robert Wall's picture

Re: Project photovoltaic hybrid

Here is your sketch. First, Mr Google would like to apologise for my Portuguese.

I am not certain that I have understood what you want with the accumulator. It is probably wrong, but it will help you.
I have also changed the 1 second timer because yours will fail after 49 days. "refresh" is now the time when the next refresh will happen, not when the last one happened.
I have also separated the unchanging parts of the display from the parts that might change every second, and the unchanging part is now written only when the page changes.
The analogue inputs are read in one place only, every 1 second - it does not matter which page is on the LCD.

I do not have your LCD display, therefore I cannot test this sketch. You must make some changes before it will work.

  1. You must specify the switch to reset the accumulator
  2. You must change the function that writes the accumulator to the LCD

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.