Dynamic Positioning

So Iv got a display setup to give me a readout of SWR and PWR. Im very new at this, and Im taking a stab at getting some code running so that I can use this with an other hobby of mine, Amateur Radio.

When SWR goes above 3:1 it tells me that its too high... This works
When PWR goes above 100w it tells me THIS is too high.. This works

What I cant get is that... When the PWR is only 1 or 2 digits in legth, it leave a large gap between the digits and the watt symbol.

Like this : 1 w
15 w

Is there possibly a way to have the w shift over as the numbers expand?

Also, when the words "TOO HIGH" pop up, and the values drop below the upper limit, i still get letters remaining behind. Is there any way I can clear these letters?

Thank you!

There are a billion ways to do what you're doing, so we can't help unless you tell us how you are currently doing it.

Post your relevant information here. Most importantly, your current code (the whole thing, not just parts). Plus devices you're using (display type? LCD? TFT? Model?), possibly a schematic, etc.

I think the answer to your problem is easy, but I can't see your current code from here.

Try squinting...

I tired... It didnt work.

What type of a display are you using? Is it a 16x2 LCD?

Definitely post the code or we can't suggest how to change it...

This - of course - is a really common question.

You are using the printing libraries, and the set cursor command. Are you perchance, using the set cursor command to place the "W" character?

If not, the first problem is that the printing library is printing the number left-justified, but printing a fixed number of characters and filling out with blanks. There are other print commands that will print a number (or other data) in a fixed format, with or without leading zeros. Otherwise, there should be a variant that does not do the padding, and you can do some conditional code that prints one or two spaces first depending on how large the number is. Some research is called for.

The second problem is the "overprint". It's like an old-fashioned(!) video terminal - if you perform only a CR (Carriage Return); in this case, a set cursor, what prints next overwrites the line character by character, but only as far as you print - anything beyond that remains.

The options are either to erase the LCD every time you re-write the line, which tends to cause annoying flicker, or to write sufficient spaces after printing your numbers, to overwrite any alternate text that was there.

Okay so here we go, SLOPPY CODE!

  LiquidCrystal - SWR / PWR Meter
  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Variables

int PwrW;

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
int SwrSensor = analogRead(A0);
int PwrSensor = analogRead(A1);

  // Print SWR Header
  lcd.setCursor(0, 0);
  lcd.print("SWR :");
  // Print PWR Header
  lcd.setCursor(0, 1);
  lcd.print("PWR :");

  // Calculate if SWR is too high.
  // If it is too high, Print TOO HIGH
  // If it is below 3:1 Print SWR
float SwrR = SwrSensor * (3.0 / 1023.0);
int PwrW = PwrSensor * (100.0 / 1023.0);

if ( SwrR >= 3.0)
  // SWR is too high
  lcd.setCursor(7, 0);
  lcd.print("TOO HIGH");
  // SWR is below 3:1 so, show it
  lcd.setCursor(7, 0);
  lcd.setCursor(11, 0);
  lcd.print(":1    ");

  // Calculate if PWR is too high.
  // If it is too high, Print TOO HIGH
  // If it is below 100w Print PWR
if ( PwrW >= 100.0)
  // PWR is too high
  lcd.setCursor(7, 1);
  lcd.print("TOO HIGH");
  lcd.setCursor(8, 1);
  lcd.setCursor(10, 1);
  lcd.print(" w   ");

I'm VERY new at this.. .So any pointers are welcomed.

So your problem is these lines:

  lcd.setCursor(8, 1);
  lcd.setCursor(10, 1);
  lcd.print(" w   ");

You position the cursor to column 8 to print the number, then re-position it to column 10 to print the "(space)w". The "w" is therefore always at column 11, irrespective of the number of digits in the number.

This should work (untested)

  lcd.setCursor(8, 1);
  lcd.print(" w   ");

Can you add Serial.print(); statements to get the range of values during normal operation since , as you
have pointed out, it is not displaying anything between 15W and 100W. Can you just add print statements
for SWR and PWR right after the analog.Read() like this:

 int SwrSensor = analogRead(A0);
        int PwrSensor = analogRead(A1); 
       //   Serial.println(A1);"

After you collect the values for SWR first using serial monitor, copy and paste them into a notepad file and name it
Tlhen cut the comment slashes from in front of the Serial.print(A1); statement and paste them in front of the
Serial.print(A0); statement. Do a test run and collect the values for tha PWR range and copy and paste that into
a notepad file and name it "PWR_range.txt" and upload both files.
Can you do that ?
In order to determine why you are not displaying the midrange values on your LCD we need to isolate these values
from your LCD code.

Can you add Serial.print(); statements to get the range of values during normal operation since , as you
have pointed out, it is not displaying anything between 15W and 100W.

I don't think he ever said that. He just said there was too much space between the numbers and the "w" when there were only 1 or 2 digits in the number.

So he did.
Sorry, My Bad.
Disregard my last post.

Thank you. The variables update quite well. And the modified code does now as well. Thank you. I thought I had to directly place the LCD.print() statements to a specific place on the LCD.

Thank you.

Now to build the directional coupler and figure out the rest of the circuit. :slight_smile: