External data not reading

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
Post Reply
ChristopherNL
Posts: 4
Joined: Sun Mar 24, 2019 9:26 pm

External data not reading

Post by ChristopherNL » Sun Mar 24, 2019 9:43 pm

Hi all,

Got this piece of script (and some above, but there is no problem there...)
All running on a Yun rev 2. All works like a charm.

Code: Select all

void loop() {

   // Initialize the client library
  HttpClient client;
  HttpClient client2;

  // Make a HTTP request:
  client.get("http://www.fake.nl/t/1.txt");
  client2.get("http://www.fake.nl/t/2.txt");
  

  // if there are incoming bytes available
  // from the server, read them and print them:
  while (client.available()) {
    const char *t = client.read();
    const char *b = client2.read();
 
  dmd.clearScreen( true );
   dmd.selectFont(MyGraphicsFont);
   dmd.drawChar(  0,  0,  (t), GRAPHICS_NORMAL );
   dmd.drawChar(  0,  16,  (b), GRAPHICS_NORMAL );
   delay( 5000 );

  dmd.clearScreen( true );
   dmd.selectFont(System5x7);
   dmd.drawString(  0,  0, (t), 3, GRAPHICS_NORMAL );
   dmd.drawString(  0,  16, (b), 3, GRAPHICS_NORMAL );
   delay( 5000 );
  }
}
This works fine and shows the data that should be shown (is just one number):

Code: Select all

 dmd.clearScreen( true );
   dmd.selectFont(System5x7);
   dmd.drawChar(  0,  0,  (t), GRAPHICS_NORMAL );
   dmd.drawChar(  0,  16,  (b), GRAPHICS_NORMAL );
   delay( 5000 );
This doesn't show the correct characters. It does show text, but strange other symbols. . \ etc. (more than one, so drawChar won't work):

Code: Select all

 dmd.clearScreen( true );
   dmd.selectFont(System5x7);
   dmd.drawString(  0,  0, (t), 3, GRAPHICS_NORMAL );
   dmd.drawString(  0,  16, (b), 3, GRAPHICS_NORMAL );
   delay( 5000 );
Anyone know what the difference is and how I can solve the problem?
It also doesn't work in the marquee...

Thanks!

Brissieboy
Posts: 161
Joined: Fri Sep 20, 2013 7:25 am

Re: External data not reading

Post by Brissieboy » Sun Mar 24, 2019 11:04 pm

In

Code: Select all

dmd.drawString(  0,  0, (t), 3, GRAPHICS_NORMAL );
Looks like (t) is only pointing to a character and you're trying to print a string?

ChristopherNL
Posts: 4
Joined: Sun Mar 24, 2019 9:26 pm

Re: External data not reading

Post by ChristopherNL » Sun Mar 24, 2019 11:07 pm

Yes.
The strange thing is it works like it should using 'drawChar' and doesn't with 'drawString'.

User avatar
stryker
Posts: 280
Joined: Sat Jan 14, 2012 2:44 pm

Re: External data not reading

Post by stryker » Mon Mar 25, 2019 12:04 pm

It's hard to know without seeing the rest of your code, but why can you presume there are 3 characters to display following the client.read() granted you hard code the length as 3 in the calls to dmd.drawString()? There's nothing I see here that means you're waiting for 3 before displaying them. If there are only 2 received the 3rd will be uninitialised, and could display as anything that was there from previous excuted code. dmd.drawChar only expects one character, and you know for sure there will be one (at least, but 3's not guaranteed) That's one thought.

Another I have is I can't see where you allocate memory for the character array that t and b would store the 2nd and 3rd characters in. You may have, but if you're still stuck can you post the whole code so we can see the declarations?

Thanks, Geoff

ChristopherNL
Posts: 4
Joined: Sun Mar 24, 2019 9:26 pm

Re: External data not reading

Post by ChristopherNL » Wed Mar 27, 2019 10:25 pm

What happens:

I go from:

1.txt file:
"26"

Through myfile.ino

Code: Select all

 
Step1: 
  HttpClient client;
Step2:
  client.get("http://www.fake.nl/t/1.txt");
Step3:
  char t = client.read();
Step4: 
  dmd.drawChar(  0,  0,  (t), GRAPHICS_NORMAL );
In DMD.h

Code: Select all

//Draw a string
  void drawString( int bX, int bY, const char* bChars, byte length, byte bGraphicsMode);
In DMD.cpp

Code: Select all

void DMD::drawString(int bX, int bY, const char *bChars, byte length,
		     byte bGraphicsMode)
{
    if (bX >= (DMD_PIXELS_ACROSS*DisplaysWide) || bY >= DMD_PIXELS_DOWN * DisplaysHigh)
	return;
    uint8_t height = pgm_read_byte(this->Font + FONT_HEIGHT);
    if (bY+height<0) return;

    int strWidth = 0;
	this->drawLine(bX -1 , bY, bX -1 , bY + height, GRAPHICS_INVERSE);

    for (int i = 0; i < length; i++) {
        int charWide = this->drawChar(bX+strWidth, bY, bChars[i], bGraphicsMode);
	    if (charWide > 0) {
	        strWidth += charWide ;
	        this->drawLine(bX + strWidth , bY, bX + strWidth , bY + height, GRAPHICS_INVERSE);
            strWidth++;
        } else if (charWide < 0) {
            return;
        }
        if ((bX + strWidth) >= DMD_PIXELS_ACROSS * DisplaysWide || bY >= DMD_PIXELS_DOWN * DisplaysHigh) return;
    }
}
Somewhere in the code the "26" converts to something else. Because the screen shows 'EwA' and '.'

Anyone who knows how to fix the different steps with variables in variables in a way where 'INPUT' -> 'OUTPUT' without conversion?
Last edited by ChristopherNL on Wed Mar 27, 2019 10:27 pm, edited 1 time in total.

ChristopherNL
Posts: 4
Joined: Sun Mar 24, 2019 9:26 pm

Re: External data not reading

Post by ChristopherNL » Wed Mar 27, 2019 10:26 pm

Besides that I used this code as example

https://www.arduino.cc/en/Tutorial/HttpClientConsole

Code: Select all

/*
  Yún HTTP Client Console version for Arduino Uno and Mega using Yún Shield

 This example for the YunShield/Yún shows how create a basic
 HTTP client that connects to the internet and downloads
 content. In this case, you'll connect to the Arduino
 website and download a version of the logo as ASCII text.

 created by Tom igoe
 May 2013
 modified by Marco Brianza to use Console

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/HttpClient

 */

#include <Bridge.h>
#include <HttpClient.h>
#include <Console.h>

void setup() {
  // Bridge takes about two seconds to start up
  // it can be helpful to use the on-board LED
  // as an indicator for when it has initialized
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin();
  digitalWrite(13, HIGH);

  Console.begin();

  while (!Console); // wait for a serial connection
}

void loop() {
  // Initialize the client library
  HttpClient client;

  // Make a HTTP request:
  client.get("http://www.arduino.cc/asciilogo.txt");

  // if there are incoming bytes available
  // from the server, read them and print them:
  while (client.available()) {
    char c = client.read();
    Console.print(c);
  }
  Console.flush();

  delay(5000);
}

Post Reply