Arduino Forum

Using Arduino => Project Guidance => Topic started by: BrianL on Jul 15, 2019, 07:45 pm

Title: Scrolling Display £ symbol
Post by: BrianL on Jul 15, 2019, 07:45 pm
Hi
Firstly, sorry if this is in the wrong area, Mods please move as necessary
Secondly, I'm the original total knob when it comes to writing or reading programmes. So no tech talk!
What is my problem (other than no t being IT literate).. Well, I have a 8 unit MD MAX72xx driven from a Arduino Uno and loaded from #include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>)
All works well but I cant get a UK £ sign.  (Pound symbol)
How is this achieved please - In very simple terms please.
BTW I have tried to read through the Tutorials but cant initially find anything that relates or that I can understand!!
Title: Re: Scrolling Display £ symbol
Post by: hammy on Jul 15, 2019, 08:33 pm
I'm not sure what you are doing as your details are sketchy...

ASCII tables might give you a clue ?
Title: Re: Scrolling Display £ symbol
Post by: groundFungus on Jul 15, 2019, 08:46 pm
I think that the characters available are dictated by the font that you are using.  Here is a page with information on using fonts with Parola. (https://majicdesigns.github.io/MD_Parola/page_software.html)
Title: Re: Scrolling Display £ symbol
Post by: Paul__B on Jul 16, 2019, 02:08 pm
OK, first things first.

You need to go and read the forum instructions (http://arduino.cc/forum/index.php/topic,148850.0.html) so that you can go back and modify your original post (not re-post it) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window.  Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window.  But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read.  If you do not post it as "code" it can as you now see, be quite garbled and is always more difficult to read.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper.  People can usually see the mistakes directly and do not want to have to actually load it in their own IDE.  And that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space.  Do use blank lines, but only between complete functional blocks.



The information you are seeking on how to put the pound symbol in the font is explained here (https://arduinoplusplus.wordpress.com/2016/11/13/parola-fonts-a-to-z-managing-fonts/) but I agree it is not easy to follow.  Someone - even Marco himself - may pop in to explain if you are lucky.  The usual convention is to put the English Pound symbol in place of the octothorp (https://en.wikipedia.org/wiki/Number_sign) "#".

Try replacing the font line numbered 35 in MD_MAX72xx_font.cpp
Code: [Select]
 5, 0x14, 0x7f, 0x14, 0x7f, 0x14,  // 35 - '#'

with
Code: [Select]
 5, 0x68, 0x7e, 0x49, 0x41, 0x22  // 35 - '£'
Title: Re: Scrolling Display £ symbol
Post by: BrianL on Jul 19, 2019, 09:48 am
Sorry about the errors I'm learning (Slowly!)  I have removed the reply which contained the whole sketch.
I did post this message as a continuation of my first post, but its failed to get a reply, so I've moved it to a new Quick Reply following on from the last post.

I used the code line you suggested and removed the code for# and replaced all the code with your suggestion. Saved then uploaded the whole sketch.  The £ sign now appears in the scrolling display BUT it now has an A immediately before it??  e.g. Admission: A£ 5.00    I cant get rid of the preceding A.   Any further help would be welcomed.
Title: Re: Scrolling Display £ symbol
Post by: Paul__B on Jul 19, 2019, 05:16 pm
Sorry about the errors I'm learning (Slowly!)  I have removed the reply which contained the whole sketch.
That was a very silly thing to do!  :smiley-eek:

I used the code line you suggested and removed the code for# and replaced all the code with your suggestion. Saved then uploaded the whole sketch.  The £ sign now appears in the scrolling display BUT it now has an A immediately before it??  e.g. Admission: A£ 5.00    I cant get rid of the preceding A.
I can only suppose you made a mistake in the edit.  Might have to recover the original font file and try again.  :smiley-roll:

(Where is Marco?  I am sure I got the pattern change correct!)
Title: Re: Scrolling Display £ symbol
Post by: BrianL on Jul 20, 2019, 12:00 pm
I simply deleted the line numbered 35 which showed a # symbol at the end and copied and pasted your new line in. Saved it then the sketch containing the new line was uploaded to Arduino. When powered up the scrolling text displayed correctly and the £ sign was then present (In two places) but each has a preceding A immediately before the £.  See screen shot 3 attachment

A very silly thing to do?  It was stated in an earlier post that I shouldn't have pasted the sketch as I did??

Below is the sketch again..Hopefully inserted correctly using the </> icon.  Blank spaces are already there from the pre made sketch? You can view this by downloading it,  if its not already in the library.  I'm beginning to get very lost now Im a total novice and do not understand coding or basic or anything such like. I can follow step by step instructions but if they start getting technical then it may as a well be written in Mandarin!  This little project started as a simple task and seems now to be getting deeper and deeper in to coding alterations and errors being made!  It originally was a simple to build 8 segment LED display, connect to Arduino Uno, look for ready made sketch, download the lot to PC then load to Arduino and see the scrolling results!   (Ctrl-T takes me to a New Tab in Google Chrome?)

Code: [Select]
[code]
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>



// Use the Parola library to scroll text on the display
//
// Demonstrates the use of the scrolling function to display text received
// from the serial interface
//
// User can enter text on the serial monitor and this will display as a
// scrolling message on the display.
// Speed for the display is controlled by a pot on SPEED_IN analog in.
// Scrolling direction is controlled by a switch on DIRECTION_SET digital in.
// Invert ON/OFF is set by a switch on INVERT_SET digital in.
//
// UISwitch library can be found at https://github.com/MajicDesigns/MD_UISwitch
// MD_MAX72XX library can be found at https://github.com/MajicDesigns/MD_MAX72XX
//

#include <MD_Parola.h>
#include <MD_MAX72XX.h>
#include <SPI.h>

// set to 1 if we are implementing the user interface pot, switch, etc
#define USE_UI_CONTROL 0

#if USE_UI_CONTROL
#include <MD_UISwitch.h>
#endif

// Turn on debug statements to the serial output
#define DEBUG 0

#if DEBUG
#define PRINT(s, x) { Serial.print(F(s)); Serial.print(x); }
#define PRINTS(x) Serial.print(F(x))
#define PRINTX(x) Serial.println(x, HEX)
#else
#define PRINT(s, x)
#define PRINTS(x)
#define PRINTX(x)
#endif

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::ICSTATION_HW
#define MAX_DEVICES 8
#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10

// HARDWARE SPI
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// SOFTWARE SPI
//MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// Scrolling parameters
#if USE_UI_CONTROL
const uint8_t SPEED_IN = A5;
const uint8_t DIRECTION_SET = 8;  // change the effect
const uint8_t INVERT_SET = 9;     // change the invert

const uint8_t SPEED_DEADBAND = 5;
#endif // USE_UI_CONTROL

uint8_t scrollSpeed =30;    // default frame delay value
textEffect_t scrollEffect = PA_SCROLL_LEFT;
textPosition_t scrollAlign = PA_LEFT;
uint16_t scrollPause = 000; // in milliseconds

// Global message buffers shared by Serial and Scrolling functions
#define BUF_SIZE 75
char curMessage[BUF_SIZE] = { ""};
char newMessage[BUF_SIZE] = { "FMRC Exhibition 2019 Admission : Adult £5.00  Child £3.00  Under 5's free" };
bool newMessageAvailable = true;

#if USE_UI_CONTROL

MD_UISwitch_Digital uiDirection(DIRECTION_SET);
MD_UISwitch_Digital uiInvert(INVERT_SET);

void doUI(void)
{
  // set the speed if it has changed
  {
    int16_t speed = map(analogRead(SPEED_IN), 0, 1023, 10, 150);

    if ((speed >= ((int16_t)P.getSpeed() + SPEED_DEADBAND)) ||
      (speed <= ((int16_t)P.getSpeed() - SPEED_DEADBAND)))
    {
      P.setSpeed(speed);
      scrollSpeed = speed;
      PRINT("\nChanged speed to ", P.getSpeed());
    }
  }

  if (uiDirection.read() == MD_UISwitch::KEY_PRESS) // SCROLL DIRECTION
  {
    PRINTS("\nChanging scroll direction");
    scrollEffect = (scrollEffect == PA_SCROLL_LEFT ? PA_SCROLL_RIGHT : PA_SCROLL_LEFT);
    P.setTextEffect(scrollEffect, scrollEffect);
    P.displayClear();
    P.displayReset();
  }

  if (uiInvert.read() == MD_UISwitch::KEY_PRESS)  // INVERT MODE
  {
    PRINTS("\nChanging invert mode");
    P.setInvert(!P.getInvert());
  }
}
#endif // USE_UI_CONTROL

void readSerial(void)
{
  static char *cp = newMessage;

  while (Serial.available())
  {
    *cp = (char)Serial.read();
    if ((*cp == '\n') || (cp - newMessage >= BUF_SIZE-2)) // end of message character or full buffer
    {
      *cp = '\0'; // end the string
      // restart the index for next filling spree and flag we have a message waiting
      cp = newMessage;
      newMessageAvailable = true;
    }
    else  // move char pointer to next position
      cp++;
  }
}

void setup()
{
  Serial.begin(57600);
  Serial.print("\n[Parola Scrolling Display]\nType a message for the scrolling display\nEnd message line with a newline");

#if USE_UI_CONTROL
  uiDirection.begin();
  uiInvert.begin();
  pinMode(SPEED_IN, INPUT);

  doUI();
#endif // USE_UI_CONTROL

  P.begin();
  P.displayText(curMessage, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
}

void loop()
{
#if USE_UI_CONTROL
  doUI();
#endif // USE_UI_CONTROL

  if (P.displayAnimate())
  {
    if (newMessageAvailable)
    {
      strcpy(curMessage, newMessage);
      newMessageAvailable = false;
    }
    P.displayReset();
  }
  readSerial();
}
[/code]


Now when I look at the MD_MAX72XX-font.cpp file   35 is the # see screen shot 1 below.  But further down the code and sitting at 163 is a £ entry ??  See screen shot 2   So now I'm even more confused!  :o

Title: Re: Scrolling Display £ symbol
Post by: PaulRB on Jul 20, 2019, 02:41 pm
Faversham?
Furness?
Falkirk?

(https://forum.arduino.cc/index.php?action=dlattach;topic=626481.0;attach=317112)
(https://forum.arduino.cc/index.php?action=dlattach;topic=626481.0;attach=317114)
(https://forum.arduino.cc/index.php?action=dlattach;topic=626481.0;attach=317116)
Title: Re: Scrolling Display £ symbol
Post by: Paul__B on Jul 20, 2019, 02:42 pm
I simply deleted the line numbered 35 which showed a # symbol at the end and copied and pasted your new line in. Saved it then the sketch containing the new line was uploaded to Arduino. When powered up the scrolling text displayed correctly and the £ sign was then present (In two places) but each has a preceding A immediately before the £.  See screen shot 3 attachment
(https://forum.arduino.cc/index.php?action=dlattach;topic=626481.0;attach=317116) (https://forum.arduino.cc/index.php?action=dlattach;topic=626481.0;attach=317116)

That is a very mangled display!  Just hold the reset button to take a picture!  OK, it is not an "A", so I wonder what it is?

Oh, silly me!  :smiley-eek:  You have inserted a UNICODE symbol into your sketch, which is two bytes!  To use the modified file, you must specify the pound as a simple "#".


Ctrl-T takes me to a New Tab in Google Chrome?
Ctrl-T in the Arduino IDE formats the sketch according to common "C" conventions, making it as readable as possible - at the expense of some neatness.

Now when I look at the MD_MAX72XX-font.cpp file   35 is the # see screen shot 1 below.  But further down the code and sitting at 163 is a £ entry ??  See screen shot 2   So now I'm even more confused!  :o
So it was unnecessary.  You appear to have a different font file to mine - in mine, "Pounds" does appear as character 156 and most of the non-ASCII set is different.  In fact, mine is almost but not quite standard IBMSCII while yours corresponds to a different code page!

Given this, I would advise restoring the original file if you can (since I gave you the original pattern for character 35) and you will see what happens then.  The pound symbol is already there; you just have to specify it.  I was getting excessively bold (or trying to make it too easy to write the characters).

ASCII tables might give you a clue ?
Yes, the ASCII table (http://www.asciitable.com/)!  :smiley-lol:
Title: Re: Scrolling Display £ symbol
Post by: BrianL on Jul 20, 2019, 04:42 pm
(https://forum.arduino.cc/index.php?action=dlattach;topic=626481.0;attach=317116) (https://forum.arduino.cc/index.php?action=dlattach;topic=626481.0;attach=317116)




Oh, silly me!  :smiley-eek:  You have inserted a UNICODE symbol into your sketch, which is two bytes!  To use the modified file, you must specify the pound as a simple "#".


Ctrl-T in the Arduino IDE formats the sketch according to common "C" conventions, making it as readable as possible - at the expense of some neatness.
So it was unnecessary.  You appear to have a different font file to mine - in mine, "Pounds" does appear as character 156 and most of the non-ASCII set is different.  In fact, mine is almost but not quite standard IBMSCII while yours corresponds to a different code page!

Given this, I would advise restoring the original file if you can (since I gave you the original pattern for character 35) and you will see what happens then.  The pound symbol is already there; you just have to specify it.  I was getting excessively bold (or trying to make it too easy to write the characters).
Yes, the ASCII table (http://www.asciitable.com/)!  :smiley-lol:
So this is where I come unstuck!... Unicode in my sketch?  Where is it?  Only thing I've altered AFAIK is the scrolling text to be displayed and the pause time at end of display to zero.

I can restore the file to original and save it.  How and where do I specify it? (The £ symbol) - Now that's where I started!  :-)
Title: Re: Scrolling Display £ symbol
Post by: groundFungus on Jul 20, 2019, 04:46 pm
What text editor did you use to modify the file?  Maybe the editor does not work in ASCII text.  Use a program like Notepad that works only only with ASCII text?
Title: Re: Scrolling Display £ symbol
Post by: Paul__B on Jul 21, 2019, 12:52 am
No, it is not the editor used to modify the MD_MAX72XX-font.cpp file, but inserting a Unicode character into the strings specified in the IDE that generates the double character.  The "£" in the editor (as in this text) is two bytes.

If - using the modified file - you put "#" in your strings to be displayed, it will come out as "£".  Otherwise you have to put char(163) into the string.
Title: Re: Scrolling Display £ symbol
Post by: BrianL on Jul 21, 2019, 12:19 pm
Thanks Paul__B, I will keep the .cpp file as original. 
But how and where exactly would I enter char(163) in the sketch??   I'm not at all conversant with alterations and how to do them. I am an absolute beginner with no basic or C understanding, so I need hand holding!!! 
Title: Re: Scrolling Display £ symbol
Post by: Paul__B on Jul 21, 2019, 03:13 pm
Try
Code: [Select]
char newMessage[BUF_SIZE] = { "FMRC Exhibition 2019 Admission : Adult "+char(163)+"5.00  Child "+char(163)+"3.00  Under 5's free" };
Title: Re: Scrolling Display £ symbol
Post by: BrianL on Jul 21, 2019, 03:36 pm
With that replacing the original and when I run the 'Verify' command I get an error message (see screen shot below)....
Ironically if I insert a $ before 5.00 and 3.00   It works perfectly with the $ symbol showing correctly.
Code: [Select]
char newMessage[BUF_SIZE] = { "FMRC Exhibition 2019 Admission : Adult $5.00  Child $3.00  Under 5's free" };
  If I change the $ to £ it then reverts to the (looks like) A£. 
Without the £ or any other currency symbol it works correctly too. 
It has to be something to do with the £ ???

BTW  Note the Hardware is #define HARDWARE_TYPE MD_MAX72XX::ICSTATION_HW 
Not #define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW   as this when used causes the text to be upside down and scroll form the wrong end!   The ICSTATION_HW seems to work correctly (possibly?)
Title: Re: Scrolling Display £ symbol
Post by: PaulRB on Jul 21, 2019, 05:54 pm
Please don't attach images of error messages. There is a "copy messages" button above the error message window. You can then paste them into your post between code tags.

(https://forum.arduino.cc/index.php?action=dlattach;topic=626481.0;attach=317237)
Title: Re: Scrolling Display £ symbol
Post by: PaulRB on Jul 21, 2019, 05:57 pm
You can't use + to concatenate strings in C, and there is no char() function. You can use + to concatenate Strings (the capital S makes a difference) but using Strings is discouraged because causes problems with MCU with small ram memories like Uno.

Try
Code: [Select]
char newMessage[BUF_SIZE] = { "FMRC Exhibition 2019 Admission : Adult \xA35.00  Child \xA33.00  Under 5's free" };

(163 is A3 in hex)
Title: Re: Scrolling Display £ symbol
Post by: BrianL on Jul 21, 2019, 06:18 pm
Tried your line in place of the original..  Made no difference.  There are no £ signs displayed
Title: Re: Scrolling Display £ symbol
Post by: PaulRB on Jul 21, 2019, 06:27 pm
But what did you see?

Try \x9C instead of \xA3.

@Paul__B why did you suggest 163? Did you find that in Marco's font files or something.
Title: Re: Scrolling Display £ symbol
Post by: BrianL on Jul 21, 2019, 06:34 pm
I have played around a bit. I added a space between \xA3 and the amount, so as its like \xA3 5.00   and it works
Thank you for all the help offered.

BTW to answer the question above...  using the line as supplied allowed all other text to work but no £ symbol appeared. Adding the space has resolved it. 
Title: Re: Scrolling Display £ symbol
Post by: PaulRB on Jul 21, 2019, 06:38 pm
Adding the space has resolved it.  
Did it also cause a space to appear between the £ and the 3?

PS. Still curious about my unanswered question from post #7.
Title: Re: Scrolling Display £ symbol
Post by: BrianL on Jul 21, 2019, 06:40 pm
I added a space for both £5 and £3  Now sitting here watching it scroll nicely  :)
Title: Re: Scrolling Display £ symbol
Post by: PaulRB on Jul 21, 2019, 06:43 pm
Sorry, I have this bad habit of editing my messages and adding extra text if I think no one else has replied to the thread.

What I meant to ask was, has adding the space in the code caused an extra space to appear on the display, in addition to the £?
Title: Re: Scrolling Display £ symbol
Post by: BrianL on Jul 21, 2019, 06:54 pm
Yes there is a space between each £ symbol and the amount in both cases but it looks okay.
Faversham   :D
Title: Re: Scrolling Display £ symbol
Post by: PaulRB on Jul 21, 2019, 07:51 pm
Hmm, well I'm glad you're happy with that space but it annoys me because I don't know how to get rid of it.

Is there a C expert reading this thread so knows the answer?  Clearly, without an intervening space, the 5 in "\xA35.00"is interpreted as part of the hex value. But how to stop that without printing some unwanted (non-hex) character?
Title: Re: Scrolling Display £ symbol
Post by: Paul__B on Jul 22, 2019, 12:45 am
Try \x9C instead of \xA3.

@Paul__B why did you suggest 163? Did you find that in Marco's font files or something.
Thank you for the correction on "C" strings.    :smiley-cool:

As I explained in #8, it seems the font file that BrianL has is not the same as I have, as presumably do you, which is essentially "IBMSCII", so the 165 matches his font file.  To mine it would be 156.  YMMV.  I have not checked which version I have.  :smiley-eek: