Neomatrix not displaying full text [SOLVED]

Hi All

I have set up an Adafruit 8x8 neomatrix with a spark core to make a (rather large) badge for my son. The full text doesn’t display and I wondered if you might know why it doesn’t? I am using Spark Dev (the new version).

The text displays in different colours up to Happy Bi and then it stops and re-starts in a different colour.

my .ino code is:-

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8,8,4,1, PIXEL_PIN,
  NEO_TILE_TOP   + NEO_TILE_LEFT   + NEO_TILE_ROWS   + NEO_TILE_PROGRESSIVE +
  NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE,
  PIXEL_TYPE);

const uint16_t colors[] = {
  matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };

void setup() {
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(30);
  matrix.setTextColor(matrix.Color(80,255,0));
}

int x    = matrix.width();
int pass = 0;

void loop() {
  matrix.fillScreen(0);
  matrix.setCursor(x, 0);
  matrix.print(F("Happy Birthday William"));
  if(--x < -36) {
    x = matrix.width();
    if(++pass >= 3) pass = 0;
    matrix.setTextColor(colors[pass]);
  }
  matrix.show();
  delay(100);
}

I assume that having got to the point at which the neomatrix will display anything that I must have the correct GFX.cpp, gamma.h etc. in my compile folder.

If I change the message to 123456789 then the scrolling message gets to 7 and a bit of 8.

Thank you.

Since setCursor() sets the pixel position from where to render the text, you need to calculate the maximum displacement based on font width, screen width and text length.
If you use the standard font of Adafruit_GFX I think this is 6px per character.

char yourText[64] = "Here comes your Text";
int  pixelPerChar = 6;
int  maxDisplacement;
...
void setup()
{
  ...
  maxDisplacement = strlen(yourText) * pixelPerChar + matrix.width();
}

void loop()
{
  ...
  if (--x < -maxDisplacement)
  {
    x = matrix.width();
    ...
  }
  ...
}

BTW: If you want to make the text dynamic, you could make use of Spark.function(). Then you can change the text on the fly - e.g. out of Spark Dev :wink:

2 Likes

I have a spark publish with a webhook that calls my php script that calls a spark function with the new string to display.

I’ll tidy up the code a bit and share if your interested

1 Like

@ScruffR @Hootie81

Thank you very much gentlemen for your, as ever, speedy and helpful responses. I will give them a shot this evening. I wonder how long the matrix will last powered from the battery shield ?
Hoodie, thanks for you kind offer of some code. It sounds intriguing, but I must confess that the web hooks and php scripts sounds both a bit out of my envelope and fun! So yes please. I would love to have a go with it.

Thank you very much :smiley:.

@ScruffR, Works like a charm :slight_smile: again thank you very much,

I saw this the other day and thought… why not - how hard can it be??

http://hackaday.io/project/3-fled

and then I thought maybe I could use a spark variable and some of @Hootie81’s magic and hey presto you have a massive message board. I might have a go at adapting some pong code for the background. Or even (with his permission) nick a bit of @luz code and have a message fire board!! :smile:

I was out being inspired today and as my Mum would say ,it’s rude not to share so here is where I went,



It doesn’t flicker in real life like it does on the you tube clip. It is quite smooth. On closer inspection it looks to be 14 panels of 16 x (something like 128) LEDS, just like thye adafruit ones but only white and weatherproof.

Very impressive. :slight_smile:

I should also say that the Julian that made it is not this Julian LOL.

1 Like

@ScruffR,

I am playing with a bit of code, I have been trying to get it to work all day but just struggling a bit. I have made a 10 x 15 WS2812 matrix and have been scrolling text over it no problem - using your advice on making the diplay show more than seven characters.

I am trying to display the time but keep getting errors. It seems to work OK when I use the Time.timeStr(), but I wanted to write my own string showing the variables I wanted to display - more as a learning exorcise than anything else. I think my error is to do with my handling of strings and if you can point me at a good tutorial I would appreciate it.

anyway here is the code -

 Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(15,10,1,1, PIXEL_PIN,
  NEO_TILE_TOP   + NEO_TILE_LEFT   + NEO_TILE_ROWS   + NEO_TILE_PROGRESSIVE +
  NEO_MATRIX_BOTTOM + NEO_MATRIX_RIGHT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
  PIXEL_TYPE);

const uint16_t colors[] = {
  matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
  
String totaltime=String(Time.hour()+":"+Time.minute());
  int  pixelPerChar = 6;
  int  maxDisplacement;


void setup() {
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(100);
  matrix.setTextColor(matrix.Color(80,255,0));
  maxDisplacement = strlen(totaltime) * (pixelPerChar + matrix.width());
  Time.zone(+1);
}

int x    = matrix.width();
int pass = 0;

void loop() {
  matrix.fillScreen(0);
  matrix.setCursor(x, 0);
  matrix.print(F(totaltime));
  if(--x < -maxDisplacement) {
    x = matrix.width();
    if(++pass >= 3) pass = 0;
    matrix.setTextColor(colors[pass]);
  }
  matrix.show();
  delay(100);
}

The error is in line 106, but I can not work out how to solve it.

BTW what does the F do in the line matrix.print (F(something));??

Many thanks

:slight_smile:

Hi Julian,

the easiest first. The F() macro doesn’t do anything on the Particle devices, it just gets thrown out by the proprocessor or you just remove it yourself.
But on Arduino it does this http://stackoverflow.com/questions/16597437/arduino-f-what-does-it-actually-do

As for string handling, you’ve got several options.
Going with your approach using String you’d write something like this

String totaltime;

void setup()
{
  totaltime = "" + String(Time.hour()) + ":" + String(Time.minute());
  ...
  maxDisplacement = totaltime.length() * (pixelPerChar + matrix.width());
  ...
}

The leading "" is there due to some bug in the String class :wink:

But since I personally don’t like using String, I’d do it this way

char totaltime[6];

void setup()
{
  sprintf(totaltime, "%02d:%02d", Time.hour(), Time.minute());
  ...
}

Currently sprintf() is not supported on the Photon, but it should be as soon firmware version 0.4.2 gets released.


This didn’t help at all, since your code does not even have 106 lines and the actuall error message would be required too.

Hey @ScruffR, thank you for your response. I will give your code a try tonight and see how I get on. If past performance is anything to go by I am sure it will be fine.

I don’t think I would have got to the “” due to the String class bug. The sprintf would work because I am running on a core.

The code does have 106 lines (but I cut out the first comment lines :blush:).

Thank you very much.

1 Like

Hey @ScruffR sorted. Thank you very much. It will be good to have a play with sprintf as I have not used it before for formatting data.

:smile:

If you declare a neomatrix and then want to use neopixel functions - can you? So for example if I wanted to scroll text such as the time and then fill the matrix with a rainbow()? Can you mix them?

Cheers,

Julian

As I haven’t got any experience with NeoPixels @peekay123 or @wgbartley will be able to help you with that better.

Hi @ScruffR, I wonder if you can explain this to me?

   sprintf(totaltime, "%02d:%02d:%02d", Time.hour(), Time.minute(), Time.second());
  maxDisplacement = strlen(totaltime) * (pixelPerChar + matrix.width());
  matrix.fillScreen(0);
  matrix.setCursor(x, 0);
  matrix.print(F(totaltime));

produces something like 18:49:8

but also 18:49:12? - where the ? is upside down.

So to explain in words, where the seconds are a double figure number i.e.10+ then there is an upside down ? following on the display.

I have tried different variations of %02d, but none seem to change the (upside down ?)?

https://drive.google.com/file/d/0B-9YMXoxu6zyQ1N0NHpkV3lRQk0/view?usp=sharing

Have you extended the size of totaltime to accommodate the extra chars?

char totaltime[6];  // should be at least 9
1 Like

Thanks for that @ScruffR. spot on as always. :slight_smile: TYVM :slight_smile:

Is there a problem in declaring a string length that is far longer than you might need? Could I declare char totaltime[64]? Is there a down side to doing this? Is 64 as long as you can go?

I was going to add the day/month/year every five minutes as well, so declaring a longer string would be required for that.

There is no problem in declaring it longer than needed as long you’re not running out of space somewhere else.

In theory there would not be any limit to the possible string length in C. In practice your available free RAM and the addressing regime of your processor does impose limits tho’.
But char veryLongStr[32767]; would definetly be allowed and give you a 32KB string.
If you’d ever need such a long string :wink:

1 Like

wait so you got NeoMatrix working on Spark? I have been trying to get this working for ages. Worked fine on Nano but i have two 16x16 neopixel matrices i was converting images to. I was hoping to use the spark to add some web code to it :slight_smile:

I read through this thread but couldn’t figure out what library/code you fixed. sorry for being such a dunce.

Sorry for the late reply. How can I help you?

I have used the standard neon matrix library and compiled it with particle dev. Works like a dream.

How can I help you to get yours working?

:grinning:

Hey @synteny,

here is my code (such as it is!)

 /*-------------------------------------------------------------------------
  Spark Core library to control WS2811/WS2812 based RGB
  LED devices such as Adafruit NeoPixel strips and matrices.
  Currently handles 800 KHz and 400kHz bitstream on Spark Core,
  WS2812, WS2812B and WS2811.

  Also supports Radio Shack Tri-Color Strip with TM1803 controller
  400kHz bitstream.

  PLEASE NOTE that the NeoPixels require 5V level inputs
  and the Spark Core only has 3.3V level outputs. Level shifting is
  necessary, but will require a fast device such as one of the following:

  [SN74HCT125N]
  http://www.digikey.com/product-detail/en/SN74HCT125N/296-8386-5-ND/376860

  [SN74HCT245N]
  http://www.digikey.com/product-detail/en/SN74HCT245N/296-1612-5-ND/277258

  [TXB0108PWR]
  http://www.digikey.com/product-search/en?pv7=2&k=TXB0108PWR

  If you have a Spark Shield Shield, the TXB0108PWR 3.3V to 5V level
  shifter is built in.

  Written by Phil Burgess / Paint Your Dragon for Adafruit Industries.
  Modified to work with Spark Core by Technobly.
  Modified for use with Matrices by delianides.
  Contributions by PJRC and other members of the open source community.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing products
  from Adafruit!
  --------------------------------------------------------------------*/

#include "application.h"
#include "neomatrix.h"

// IMPORTANT: Set pixel PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_TYPE WS2812B

// MATRIX DECLARATION:
// Parameter 1 = width of EACH NEOPIXEL MATRIX (not total display)
// Parameter 2 = height of each matrix
// Parameter 3 = number of matrices arranged horizontally
// Parameter 4 = number of matrices arranged vertically
// Parameter 5 = pin number (most are valid)
// Parameter 6 = matrix layout flags, add together as needed:
//   NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
//     Position of the FIRST LED in the FIRST MATRIX; pick two, e.g.
//     NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
//   NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs WITHIN EACH MATRIX are
//     arranged in horizontal rows or in vertical columns, respectively;
//     pick one or the other.
//   NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns WITHIN
//     EACH MATRIX proceed in the same order, or alternate lines reverse
//     direction; pick one.
//   NEO_TILE_TOP, NEO_TILE_BOTTOM, NEO_TILE_LEFT, NEO_TILE_RIGHT:
//     Position of the FIRST MATRIX (tile) in the OVERALL DISPLAY; pick
//     two, e.g. NEO_TILE_TOP + NEO_TILE_LEFT for the top-left corner.
//   NEO_TILE_ROWS, NEO_TILE_COLUMNS: the matrices in the OVERALL DISPLAY
//     are arranged in horizontal rows or in vertical columns, respectively;
//     pick one or the other.
//   NEO_TILE_PROGRESSIVE, NEO_TILE_ZIGZAG: the ROWS/COLUMS OF MATRICES
//     (tiles) in the OVERALL DISPLAY proceed in the same order for every
//     line, or alternate lines reverse direction; pick one.  When using
//     zig-zag order, the orientation of the matrices in alternate rows
//     will be rotated 180 degrees (this is normal -- simplifies wiring).
//   See example below for these values in action.
// Parameter 7 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 pixels)
//   NEO_GRB     Pixels are wired for GRB bitstream (v2 pixels)
//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA v1 pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip)
//   For Spark Core developement it should probably also be WS2812B if you're
//   using adafruit neopixels.

// Example with three 10x8 matrices (created using NeoPixel flex strip --
// these grids are not a ready-made product).  In this application we'd
// like to arrange the three matrices side-by-side in a wide display.
// The first matrix (tile) will be at the left, and the first pixel within
// that matrix is at the top left.  The matrices use zig-zag line ordering.
// There's only one row here, so it doesn't matter if we declare it in row
// or column order.  The matrices use 800 KHz (v2) pixels that expect GRB
// color data.

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(15,10,1,1, PIXEL_PIN,
  NEO_TILE_TOP   + NEO_TILE_LEFT   + NEO_TILE_ROWS   + NEO_TILE_PROGRESSIVE +
  NEO_MATRIX_BOTTOM + NEO_MATRIX_RIGHT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
  PIXEL_TYPE);

const uint16_t colors[] = {
  matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
//  char yourText[64] = "Good morning Will and Eve";
char totaltime[64];
  int  pixelPerChar = 6;
  int  maxDisplacement;


void setup() {
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(100);
  matrix.setTextColor(matrix.Color(80,255,0));

  Time.zone(+1);
}

int x    = matrix.width();
int pass = 0;
int min = Time.minute();


void loop() {


  sprintf(totaltime, "The time is %02d:%02d:%02d", Time.hour(), Time.minute(), Time.second());
  maxDisplacement = strlen(totaltime) * (pixelPerChar + matrix.width());
  matrix.fillScreen(0);
  matrix.setCursor(x, 0);
  matrix.print(F(totaltime));
  if(--x < -maxDisplacement) {
    x = matrix.width();
    if(++pass >= 3) pass = 0;
    matrix.setTextColor(colors[pass]);
  }
  matrix.show();
  delay(50);
}

You need to include the Adafruit GFX library, neopixel libaray and Neomatrix library. My pixel matrix is (at the moment) one on its own. It is 10 pixels high and 15 wide. That is why my declaration starts with 15,10,1,1. For your situation you will have to decide how you are going to put your two matricies next to each other and then declare them accordingly.

Are your matrices Adafruit ones? like this?

You may run into power issues if trying to run a 16 x 16 from the core directly. I have powered mine through a 5V 2.1mm power adaptor. this also provides power to the core.

The image above shows it running the “standard” rainbow code - which is very pretty. Here it is not running as a matrix but as a string of ws2812 LEDs if you see what I mean.

The code above declares a matrix and then scrolls the time across it.

Hope that helps.

If not just ask. If I dont know (and I probably won’t) I know who we can pull in to help you get it sorted.

Just remember you can NEVER have too many LEDS :smile:

I am sure I have some plans for the laser cut case somewhere if you are interested :smile:

1 Like

Late to the party here, but what do you have your matrix mounted in ? Seems nicely diffused - thanks !

Hi

Better late than never! I placed three sheets of tracing paper over the LEDS and then used some smoked perspex to make a cover.

If you need more information, please let me know.

1 Like