GiGA shield analog display updates

Hello :slight_smile:

I have an Arduino GIGA with the GIGA display shield to capture an analog voltage of a capacitor in a bank of capacitors for an electromagnetic accelerator which is working perfectly. The issue I am having is I want the display on my GIGA Display shield to always show the voltage of the capacitor without having to blank out and redisplay the results every 3 seconds as per my delay. I would just like to have the voltage constantly updating in real time on the Giga Display shield for each capacitor bank. I have the code written for just one capacitor to test things out as shown by my provided code. Programming is not my expertise unfortunately.

Also there may be a bug in my code as it is written as after 40 to 50 refreshes of the GIGA dimply shield to show the voltage, the screen goes blank and the LED flashes until I reset the GIGA R1.

Here is my code for you to evaluate :slight_smile:



// 460 Volt measuring program

#include "Arduino_GigaDisplay_GFX.h"
GigaDisplay_GFX display;  // create the object
#define BLUE 0x00ff



const float arduinoVCC = 3.3;  //Your Arduino voltage
unsigned long ValueR1 = 3000;
unsigned long ValueR2 = 449000;
double Voltage_Source = 450;
const int alanogPin = A0;          //the pin connecting the voltage.
const int inputResolution = 1023;  //works with most Arduino boards
const float average_of = 500;      //Average of 500 readings

float voltage;
void setup() {
  Serial.begin(115200);
  display.setRotation(1);  //Set GIGA Display orientation to landscape mode (Values are 0 - 3)
  //delay(500);
}

void loop() {

  readVoltage();


  Serial.print("Voltage of Cap 1: ");
  //Serial.print(voltage);
  //Serial.print("V Avg: ");
  Serial.print(getVoltageAverage());
  Serial.println(" Volts");

  //-------------------------------------------------

  display.begin();  //init library for GIGA Display
  display.fillScreen(BLUE);
  display.setCursor(10, 10);           //x,y
  display.setTextSize(4);              //adjust text size
  display.print("Capacitor 1 is ");    //print
  display.print(getVoltageAverage());  //print
  display.print(" volts");             //print

  //------------------------------------------------

  delay(3000);  // delay for displaying voltage reading to make it easier to read

}  //loop end


void readVoltage() {


  int A0Value = analogRead(alanogPin);
  float voltage_sensed = A0Value * (arduinoVCC / (float)inputResolution);
  //  Serial.print("voltage_sensed:");
  //  Serial.print(voltage_sensed);
  voltage = voltage_sensed * (1 + ((float)ValueR2 / (float)ValueR1));

}  //readVoltage()


float getVoltageAverage() {

  float voltage_temp_average = 0;
  for (int i = 0; i < average_of; i++) {
    readVoltage();
    voltage_temp_average += voltage;
  }

  return voltage_temp_average / average_of;



}  //getVoltageAverage

Hi @adirks

Use the technique that is described here:

https://learn.adafruit.com/adafruit-gfx-graphics-library/minimizing-redraw-flicker#overwriting-text-with-the-built-in-font-3132149

The "Arduino_GigaDisplay_GFX" library you are using is based on the "Adafruit GFX Library" of that tutorial, so the information from that tutorial can be used with the "Arduino_GigaDisplay_GFX" library. Give it a try and if you get stuck or have problems, post your updated code here and we'll take a look.

It is caused by calling display.begin() repeatedly:

Move that line to your setup function so that it is only called once. After that, the sketch should no longer crash the GIGA R1 WiFi board.

1 Like

Sorry, I noticed this posting a day or so ago and meant to respond.

Nice writeup, was going to suggest several of the techniques mentioned in it.

If the format of the screen is with fixed data such as this, you can potentially move a
a lot of the static data to either setup or some function called from setup,
like all of the headers.

Note: anytime you call something like fillScreen and then redraw stuff you are almost
guaranteed to have flashing. Except if you do it all off screen using canvas and simply update the screen from the canvas.

But maybe a quick and dirty way to not see this flashing, is to move these lines out
of loop and into setup and setup to use Opaque text output. That is
where it will fill in the pixels with the background text color,

  display.begin();  //init library for GIGA Display
  display.fillScreen(BLUE);
  display.setTextColor(0xffff, BLUE); // assuming default white(0xff) text?  

Then in loop, you can do the rest... like

  display.setCursor(10, 10);           //x,y
  display.setTextSize(4);              //adjust text size
  display.print("Capacitor 1 is ");    //print
  display.print(getVoltageAverage());  //print
  display.print(" volts    ");             //print

Note: I put in 4 blanks after volts, so if number is shorter than previous, hopefully
it will erase the rest of the data.

There are other tricks as well, like you
could do a fillRect after the end of the displaying of your text to either the end of
the previous text or to the end of the line...

You can also make the text maybe more deterministic in size, for example if you, do
display.print(getVoltageAverage(), 2);
It will print out the floating point with 2 decimal points... like form the Serial.print Arduino reference page:

  • Serial.print(1.23456, 2) gives "1.23"

As I mentioned, there are additional things you can try, but hopefully this helps some.

thank you for your very helpful information. The GIGA display does not crash anymore :slight_smile: Thank you for taking the time to reply to my post as programming is not my strongest skill but it is getting better with your support!

Best Regards

Alex

1 Like

The solution you provided of putting those 3 lines of code in the setup portion of my code worked perfectly the first time out! Now I get a consistent updated GIGA display shield of the capacitor bank voltage without the screen flashing and the voltage updating in real time! I learn something each time you help me with the code for this project and I very much appreciate that you take the time to provide actual code suggestions to help fix my issues. I learn a lot from that!

Best Regards,

Alex

1 Like