Scrolling numbers on Uno R4's 12x8 matrix LED

I want to write the distance information coming from HC-SR04 on the 12x8 matrix LEDs of Uno R4 as scrolling numbers. But what I see is random scrolling garbled symbols, occasionally legible numbers here and there. And the scrolling animation is also stuttery.

What am I doing wrong?

#include "ArduinoGraphics.h"
#include "Arduino_LED_Matrix.h"

ArduinoLEDMatrix matrix;

const int trigPin = 13;
const int echoPin = 12;

long duration;
int distance;

void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600); // Starts the serial communication
  matrix.begin();
  matrix.beginDraw();
  matrix.stroke(0xFFFFFFFF);
}

void loop() {
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance);

    // Make it scroll!

  matrix.beginDraw();
  matrix.stroke(0xFFFFFFFF);
  matrix.textScrollSpeed(50);
  // add the text

  matrix.textFont(Font_5x7);
  matrix.beginText(0, 1, 0xFFFFFF);
  matrix.println(distance);
  matrix.endText(SCROLL_LEFT);
  matrix.endDraw();

}

Have you got the scrolling working alone - without the ultrasonic bit?

Yes. It was taken straight out of Arduino documentation.

Post images for clarification.

Could this be a "float to ascii" conversion that has no EOL?

There's something odd here. I took the Arduino example, which worked fine. I then removed a few of the leading and trailing spaces from the Hello World! string and oddball characters started showing up.

Playing with the original Arduino scrolling example a little more, there's definitely something wrong in the ArduinoGraphics library.

(TL;DR version: you may not be doing anything wrong. The library appears to have its own problems.)

This cut down example runs just fine:

// To use ArduinoGraphics APIs, please include BEFORE Arduino_LED_Matrix
#include "ArduinoGraphics.h"
#include "Arduino_LED_Matrix.h"

ArduinoLEDMatrix matrix;

void setup() {
  Serial.begin(115200);
  matrix.begin();
}

void loop() {

  // Make it scroll!
  matrix.beginDraw();

  matrix.stroke(0xFFFFFFFF);
  matrix.textScrollSpeed(50);

  // add the text
  const char text[] = "    1234    ";
  matrix.textFont(Font_5x7);
  matrix.beginText(0, 1, 0xFFFFFF);
  matrix.println(text);
  matrix.endText(SCROLL_LEFT);

  matrix.endDraw();
}

Change the text[] definition to (removing 1 character):

const char text[] = "    123    ";

and the sketch bombs with the following display on the serial port:

Firmware name: "/tmp/arduino/sketches/069C5336A6084E0A3D5FF5EAEE0D2C97/Scrolling
Numbers.ino", compiled on: Sep 23 2023
Fault on interrupt or bare metal(no OS) environment
===== Thread stack information =====
  addr: 20007e38    data: 00000005
  addr: 20007e3c    data: 00000007
  addr: 20007e40    data: 00004c33
  addr: 20007e44    data: 2000067c
  addr: 20007e48    data: 2000069c
  addr: 20007e4c    data: 20007e68
  addr: 20007e50    data: 00000000
  addr: 20007e54    data: 0000488f
  addr: 20007e58    data: 20202020
  addr: 20007e5c    data: 20333231
  addr: 20007e60    data: 0d202020
  addr: 20007e64    data: 0000a40a
  addr: 20007e68    data: 00000001
  addr: 20007e6c    data: 2000067c
  addr: 20007e70    data: 2000069c
  addr: 20007e74    data: 00000000
  addr: 20007e78    data: 00000041
  addr: 20007e7c    data: 00000001
  addr: 20007e80    data: 000000ff
  addr: 20007e84    data: 00004aed
  addr: 20007e88    data: 000000ff
  addr: 20007e8c    data: 000000ff
  addr: 20007e90    data: 00000000
  addr: 20007e94    data: 2000067c
  addr: 20007e98    data: 00004040
  addr: 20007e9c    data: 0000a500
  addr: 20007ea0    data: ffffffff
  addr: 20007ea4    data: 20003064
  addr: 20007ea8    data: 05000000
  addr: 20007eac    data: 00004851
  addr: 20007eb0    data: 05460000
  addr: 20007eb4    data: 000043fd
  addr: 20007eb8    data: 2000067c
  addr: 20007ebc    data: 00004481
  addr: 20007ec0    data: 00000001
  addr: 20007ec4    data: 20202020
  addr: 20007ec8    data: 20333231
  addr: 20007ecc    data: 00202020
  addr: 20007ed0    data: 00000000
  addr: 20007ed4    data: 0000ad0d
  addr: 20007ed8    data: 0001214d
  addr: 20007edc    data: 40046f00
  addr: 20007ee0    data: 00000000
  addr: 20007ee4    data: 0000ad4b
  addr: 20007ee8    data: 0001214d
  addr: 20007eec    data: 00004f6f
  addr: 20007ef0    data: 0001214d
  addr: 20007ef4    data: 00008213
  addr: 20007ef8    data: 00008209
  addr: 20007efc    data: 00002599
====================================
=================== Registers information ====================
  R0 : 20000000  R1 : 00010fb3  R2 : 00010fa0  R3 : ffffffa4
  R12: 00000003  LR : 00004c8f  PC : 00004c6c  PSR: a1000000
==============================================================
Bus fault is caused by precise data access violation
The bus fault occurred address is 1ffffe90
Show more call stack info by run: addr2line -e "/tmp/arduino/sketches/069C5336A6
084E0A3D5FF5EAEE0D2C97/ScrollingNumbers.ino".elf -a -f 00004c6c 00004c8e 0000488
e 00004aec 000043fc 00004480 0000ad0c 0000ad4a 00004f6e 00008212 00008208

which, after running addr2line points to line 257 in ArduinoGraphics.cpp, or:

const uint8_t* b = _font->data[c];

which is in the text(...) function that converts each character in the string to its bitmap and adds it to the buffer. At first glance, it might be that somehow the loop has gone past the end of the string and is indexing nonsense data. Why it's doing that... I haven't figured out.

maybe

Looking at the library code, it didn't appear to be an issue. But in any case, println() calls were used.

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