Force Gauge Result to round Display

Hello,
I am working on a force gauge. It is a strain gauge connected to a Nano, and then I would like to display the result on a round LCD display.
I have the strain gauge running a providing results on the serial monitor. I was able to get the result showing in both Newtons and pounds on a 16x2 display.
Now I would like to get a bit more fancy and display results on a 1.28” round waveshare display, in a style like the attached gif.
Strain-Gauge-LDC

The display is functioning thanks to the test sketch provided by wareshare, which displays a static clock.
I can see all the elements of the clock in the setup, which I commented out leaving only a white background.
I added the gauge sketch to the display test sketch, and works fine.
I then created a simple circle draw in the loop.
Paint_DrawCircle(120, 120, 25, BLUE ,DOT_PIXEL_2X2,DRAW_FILL_EMPTY);
This is basically a 25 pixel radius circle at centre position.
I am trying to test changing the radius with the value of the gauge read. So at zero force the circle will be 25r, and increase as the force goes up, thus:
Paint_DrawCircle(120, 120, (scale.read()+25), BLUE ,DOT_PIXEL_2X2,DRAW_FILL_EMPTY);
However no dice, the circle does not display when I change the radius to this input driven function.
Any ideas or theories are greatly appreciated.

Use code tags to format code for the forum

Welcome to the forum

Please post your full sketch, using code tags when you do. This prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

The logic of what you are trying to do seems correct but there are details that you have not provided such as how and where you update the screen display

Hello UKHeliBob
thank you for the insight, I think the refresh rate might be my issue.
Since posting I managed to get the circle to grow with the force value,
but updating is slow, and all the pervious value circles remain on the screen. here is the full code:

#include <SPI.h>
#include "LCD_Driver.h"
#include "GUI_Paint.h"
#include "image.h"
#include <Arduino.h>
#include "HX711.h"

// Strain Gauge pin assignments
const int STRAIN_DT_PIN = 2;
const int STRAIN_SCK_PIN = 3;

HX711 scale;

void setup()
{
  {
 Config_Init(); //Display
 LCD_Init();    //Display
 LCD_SetBacklight(1000); //Display
 Paint_NewImage(LCD_WIDTH, LCD_HEIGHT, 0, WHITE); // display background fill colour
 Paint_Clear(WHITE); //Display Background fill
  
}
{
  Serial.begin(9600);

  scale.begin(STRAIN_DT_PIN, STRAIN_SCK_PIN);

  Serial.println("Initializing Gauge:");
  Serial.print("Raw Value:  ");
  Serial.println(scale.read());                  // print raw value from Gauge

  scale.set_scale(-4045);                      // calibrating factor strain gauge -4045
  scale.tare();                                 // reset gauge to 0

  Serial.println("Calibrating");
  
  Serial.print("Start value: \t\t");
  Serial.println(scale.get_units(8), 1);        // print the average of 8 readings from the Gauge minus tare weight, divided

  Serial.println("Force in Newtons:");
}

}


void loop()
{
{
  Serial.print("Force:\t" );
  Serial.print(scale.get_units(), 0);
  Serial.print("\t\t");
  Serial.println();

  delay(2000);
}
{
Paint_DrawCircle(120, 120, (scale.get_units()+25), BLUE ,DOT_PIXEL_4X4,DRAW_FILL_EMPTY);
}
}

Drawing a new circle will not erase the previous one. Either clear the screen before drawing the new one (nasty !) or write over the previous one in the background colour before drawing the new one

It's not as simple as overwriting a new image to delete the old one.

Before drawing the new image, you must estimate the pixels that will not change their RGB combination and those that would change their RGB pattern. With a comparator, only those pixels that changed will be drawn, leaving those that did not change intact. This involves creating two arrays: the current one and the previous one.

If these calculations are complicated for a GPU, imagine what it will be like for a Nano

Another option is to use an image overlay technique, this is having an image equivalent to the percentage to be displayed on the screen, here a microSD must be considered for image management.

Once again, the speed of reading the microSD and drawing the images on the TFT plays a relevant role.

Sprite drawing techniques have been implemented on boards such as the ESP32-S3 that allow very fluid images to be displayed on TFT screens.

Sprites on TFT

Thanks, that did it, I rewrite the screen white again and works

Thanks, this video is quite helpful. I tried some overwrite of the pervious circle, but found to write the whole screen worked better.
but as you suggest it is rather slow on a Nano.
There is another guy on Youtube that is using a series of gifs to animate his gauges.

As I am unsure how to code the arch and colour change with force increase, I was thinking to try this gif idea. But I think that will require connecting to some flash memory to store the gifs.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.