开云体育

Custom Graphics help for S-Meter


 

I am tapping an AGC voltage into an analog input of the Raduino for an S-Meter, and it is working well to display "S9+5", for example, on line 2 of my BitX40. Now I am trying to add a bar-graphic to go with that using the custom graphics of the LCD, but not having success. Instead of graphics, I seem to be displaying each line of the defined graphic, like "11111" or something, and the formatting is off. I could use some help, since the bulk of my programming experience dates to BASIC on a TRS-80.

Here are snippits of what I am doing:

? char c[17], b[10], smeterstring[7], printBuff[2][17]; ? ?? //added smeterstring for printing AGC value
? int sbar = 0;?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //define a marker for graphic smeter
// Define smeter characters for graphics
? byte S3[8] = {
??? B00000,
??? B00000,
??? B00000,
??? B00000,
??? B00000,
??? B00000,
??? B10000,
? };
? byte S4[8] = {
??? B00000,
??? B00000,
??? B00000,
??? B00000,
??? B00000,
??? B00100,
??? B10100,
? };
... etc., etc....

void setup() {
...
? lcd.begin(16, 2);
? // load special smeter characters to be used in smeter graphic
? lcd.createChar(0, S3);
? lcd.createChar(1, S4);
? lcd.createChar(2, S5);
...etc. etc....

void loop() {
...
????? // start getting some AGC S-Meter stuff
????? smeter = analogRead(A6); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? // get smeter AGC value
?????????? // Figure an S-meter value to display
??????????? if (smeter<4) {
????????????? strcpy(smeterstring , "S3??? ");
????????????? sbar = 0;
????????????? }
??????????? if (smeter>=4 && smeter<5) {
????????????? strcpy(smeterstring , "S4??? ");
????????????? sbar = 1;
??????????? }
??????????? if (smeter>=5 && smeter<6) {
????????????? strcpy(smeterstring , "S5??? ");
????????????? sbar = 2;
etc. etc...

lcd.setCursor(0,1);
??????????? lcd.print(1, smeterstring);
??????????? switch (sbar) {??????????????????????? //print graphics for smeter after numerical value
????????????? case 0:
????????????? lcd.write(byte(0));
????????????? lcd.print(1,"? ");
????????????? break;
?????????????
????????????? case 1:
????????????? lcd.write(byte(1));
????????????? lcd.print(1,"? ");
????????????? break;
?????????????
????????????? case 2:
????????????? lcd.write(byte(2));
????????????? lcd.print(1,"? ");
????????????? break;
...etc. etc...
}

So, the basic problem seems to be that my defined characters are not being defined. What am I doing wrong, here?

=VIc=





Jack Purdum
 

Vic:

The analogRead() function returns a value between 0 and 1023, so the small values you're checking are not displayed. You may want to map the analog values to S meter values using the map() function. The examples and the online docs will show you how to use that function.

Jack, W8TEE

On Thursday, March 22, 2018, 4:16:23 PM EDT, Vic WA4THR via Groups.Io <vhklein@...> wrote:


I am tapping an AGC voltage into an analog input of the Raduino for an S-Meter, and it is working well to display "S9+5", for example, on line 2 of my BitX40. Now I am trying to add a bar-graphic to go with that using the custom graphics of the LCD, but not having success. Instead of graphics, I seem to be displaying each line of the defined graphic, like "11111" or something, and the formatting is off. I could use some help, since the bulk of my programming experience dates to BASIC on a TRS-80.

Here are snippits of what I am doing:

? char c[17], b[10], smeterstring[7], printBuff[2][17]; ? ?? //added smeterstring for printing AGC value
? int sbar = 0;?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //define a marker for graphic smeter
// Define smeter characters for graphics
? byte S3[8] = {
??? B00000,
??? B00000,
??? B00000,
??? B00000,
??? B00000,
??? B00000,
??? B10000,
? };
? byte S4[8] = {
??? B00000,
??? B00000,
??? B00000,
??? B00000,
??? B00000,
??? B00100,
??? B10100,
? };
... etc., etc....

void setup() {
...
? lcd.begin(16, 2);
? // load special smeter characters to be used in smeter graphic
? lcd.createChar(0, S3);
? lcd.createChar(1, S4);
? lcd.createChar(2, S5);
...etc. etc....

void loop() {
...
????? // start getting some AGC S-Meter stuff
????? smeter = analogRead(A6); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? // get smeter AGC value
?????????? // Figure an S-meter value to display
??????????? if (smeter<4) {
????????????? strcpy(smeterstring , "S3??? ");
????????????? sbar = 0;
????????????? }
??????????? if (smeter>=4 && smeter<5) {
????????????? strcpy(smeterstring , "S4??? ");
????????????? sbar = 1;
??????????? }
??????????? if (smeter>=5 && smeter<6) {
????????????? strcpy(smeterstring , "S5??? ");
????????????? sbar = 2;
etc. etc...

lcd.setCursor(0,1);
??????????? lcd.print(1, smeterstring);
??????????? switch (sbar) {??????????????????????? //print graphics for smeter after numerical value
????????????? case 0:
????????????? lcd.write(byte(0));
????????????? lcd.print(1,"? ");
????????????? break;
?????????????
????????????? case 1:
????????????? lcd.write(byte(1));
????????????? lcd.print(1,"? ");
????????????? break;
?????????????
????????????? case 2:
????????????? lcd.write(byte(2));
????????????? lcd.print(1,"? ");
????????????? break;
...etc. etc...
}

So, the basic problem seems to be that my defined characters are not being defined. What am I doing wrong, here?

=VIc=





John P
 

I totally screwed this post up trying to do it on my phone, so let me try again!

Vic, you might want to look at the SWR meter code in my software for the antenna analyzer over on the SoftwareControlledHamRadio group.

John - WA2FZW


 

I am having no trouble displaying the raw input data from the AGV voltage, which ranges from very low values that you observe to over 200. I also have no problem using that value in a decision tree to convert it into pseudo-S readings and displaying that information. It works very nicely. The problem is when I try to display custom graphics to make a graphical display like this.

=Vic=


John
 

Hello Vic,

It could be a casting issue. Just in case see the definitions below of the special characters arrays in the uBitx software. The S meter bars using re-defined characters work fine on my display.?

Also I assume you use the standard display which comes with the kit. Some display units may not have the eight user defined custom characters.?

73, John (VK2ETA)

?
//Lock (frequency) custom character
const PROGMEM uint8_t lock_bitmap[8] = {
? 0b01110,
? 0b10001,
? 0b10001,
? 0b11111,
? 0b11011,
? 0b11011,
? 0b11111,
? 0b00000
};
PGM_P plock_bitmap = reinterpret_cast<PGM_P>(lock_bitmap);



John
 

Vic,

I forgot to mention also that I had to use memcpy instead of strcpy to copy the S-meter character array into the LCD buffer string for the characters to be displayed. See extracts of the code below.

73, John

Note: this is a "fat" meter with one bar per character, but it can be changed for a "thin" two bars per character like on your picture.

//VK2ETA meter for S.Meter, power and SWR
//'S' or 'P' pr 'R' then 0 to 6 growing bars, then '+' or '++' if over S9/Max Power/SWR of 10
//needle valid range 0-8
void drawMeter(int needle) {
?
? //Fill buffer with growing set of bars, up to needle value
? for (int i = 0; i < 6; i++) {
? ? if (needle > i)
? ? ? lcdMeter[i] = byte(i + 1); //Custom characters above
? ? else
? ? ? lcdMeter[i] = 0x20; //blank
? }
?
? if (needle > 7) {
? ? lcdMeter[6] = byte(7); //Custom character "++"
? } else if (needle > 6) {
? ? lcdMeter[6] = 0x2B; //"+"
? } else lcdMeter[6] = 0x20;
}


//meterType : 0 = S.Meter, 1 = Forward Power Meter, 2 = SWR Meter
void DisplayMeter(byte meterType, byte meterValue, char drawPosition)
{
?
? drawMeter(meterValue);?
? //Always line 2
? char sym = 'S';
? if (meterType == 1) sym = 'P';
? else if (meterType == 2) sym = 'R';
? line2Buffer[drawPosition] = sym;
? memcpy(&(line2Buffer[drawPosition + 1]), lcdMeter, 7);
}
?


John
 

Vic,

One last thing, I am not sure which lcd library you are using, but the Arduino supplied one has the following definition for the lcd.print method:

lcd.print(data, BASE) with:?
?
data: the data to print (char, byte, int, long, or string)
?
BASE (optional): the base in which to print numbers: BIN for binary (base 2), DEC for decimal (base 10), OCT for octal (base 8), HEX for hexadecimal (base 16).

So your statements "lcd.print(1,"? ") don't make sense in that context. Maybe you are using another library.

Also, you need to increment the cursor's position, through a loop for example, as you print the larger bars of the meter, otherwise they all print in the same spot.

73, John (VK2ETA)


 

Thanks, John! That last hint was the problem. I had been switching between printLine, where the line number being printed is needed, and print, which prints starting at the last cursor position, so "lcd.pnt(1," ") was the problem and why I was seeing a series of 1's displayed. I changed all my references to just lcd.print(" "), or similar, and the graphical S-meter is now displaying properly with the rest of my code.

Also, since I was getting warning messages about my code size approaching maximum limits, I commented out the touch-key sections to save room and eliminate that warning. That didn't "fix" anything, but was probably a good thing to do.

Fantastic to get such help for a newbie in this sketch language.

=Vic=


 

...and it now looks like this:


John
 

Well done Vic, it looks really nice.

My SWR bars looks too "fat" in comparison so I need to adjust the characters and the code.

73, John


 

开云体育

Nic job! ? You might consider posting that section of the code in the files section to that others don't have to reinvent the wheel.?


Dr.?William J. Schmidt - K9HZ J68HZ 8P6HK ZF2HZ PJ4/K9HZ VP5/K9HZ PJ2/K9HZ

?

Owner - Operator

Big Signal Ranch – K9ZC

Staunton, Illinois

?

Owner – Operator

Villa Grand Piton - J68HZ

Soufriere, St. Lucia W.I.

Rent it:


email:??bill@...

?


On Mar 24, 2018, at 8:11 AM, Vic WA4THR via Groups.Io <vhklein@...> wrote:

...and it now looks like this:<BitX S_meter.jpg>


 

Awesome!


 

Still not totally satisfied (are we ever?), but I did do most of the coding with the idea that others could easily adopt it. It is all addition to the v1.27.7 BitX40 sketch by Allard Munter, PE1NWL, and pretty much takes all available resources. My quick attempt to comment out some code related to the touch-key option was not successful and caused some odd behaviors, so I put it all back in. Also, I want to see if I can calibrate the S-meter better than just "eyeballing" it. maybe then I'll post it, but certainly will help anyone trying to implement the same thing.

=Vic=


 

开云体育

Just gotta be a member to see it…

?

?

Dr. William J. Schmidt - K9HZ J68HZ 8P6HK ZF2HZ PJ4/K9HZ VP5/K9HZ PJ2/K9HZ

?

Owner - Operator

Big Signal Ranch – K9ZC

Staunton, Illinois

?

Owner – Operator

Villa Grand Piton – J68HZ

Soufriere, St. Lucia W.I.

Rent it:

Like us on Facebook!

?

Moderator – North American QRO Yahoo Group.

?

email:? bill@...

?

?

From: [email protected] [mailto:[email protected]] On Behalf Of John P
Sent: Thursday, March 22, 2018 4:43 PM
To: [email protected]
Subject: Re: [BITX20] Custom Graphics help for S-Meter

?

I totally screwed this post up trying to do it on my phone, so let me try again!

Vic, you might want to look at the SWR meter code in my software for the antenna analyzer over on the SoftwareControlledHamRadio group.

John - WA2FZW


Virus-free.


 

I have, on my website (although currently it's a hidden link) - an LCD Custom Character designer.

Let me know if it's helpful:

It's not an 'original' - it's taken from a fellow's 'now gone' incarnation.

Best to y'all...

Mike Yancey, KM5Z
Dallas, Texas, USA


 

开云体育

Wow is that cool…? That link is saved for future reference!

?

?

Dr. William J. Schmidt - K9HZ J68HZ 8P6HK ZF2HZ PJ4/K9HZ VP5/K9HZ PJ2/K9HZ

?

Owner - Operator

Big Signal Ranch – K9ZC

Staunton, Illinois

?

Owner – Operator

Villa Grand Piton – J68HZ

Soufriere, St. Lucia W.I.

Rent it:

Like us on Facebook!

?

Moderator – North American QRO Yahoo Group.

?

email:? bill@...

?

?

From: [email protected] [mailto:[email protected]] On Behalf Of Mike Yancey
Sent: Sunday, March 25, 2018 2:42 PM
To: [email protected]
Subject: Re: [BITX20] Custom Graphics help for S-Meter

?

I have, on my website (although currently it's a hidden link) - an LCD Custom Character designer.

Let me know if it's helpful:

It's not an 'original' - it's taken from a fellow's 'now gone' incarnation.

Best to y'all...

Mike Yancey, KM5Z
Dallas, Texas, USA


Virus-free.


 

After making some adjustments to the S-level thresholds, I am reasonably happy that the display seems to be tracking the S-meter readings on a commercial radio, so I uploaded the sketch and wiring to the files area.

=Vic=