Post topics, source code that relate to the Arduino Platform

User avatar
By fezder
#59136 Sorry If I posted this in wrong section or made any other ridiculous error!

First post here, annoying to me that it is about asking for help but can't really help it.
I have 8x32 LED-matrix (bit-banging 74595's that are daisy chained), that works when I issue text as well as rotation commands etc. via etiher bluetooth, hc-05 or wired serial. But, now I figured that adding wifi-ability/compatibility, would certainly increase It's uses, problems start to pop, which I have no Idea of where they come from.
I have feeling, that ESP-01 code Is the culprit, since I started using ESP8266 in what, maybe month ago.
Serial monitor shows data as I excpect; text\r\n (what my matrix code expects too, in my understanding)
First, the esp-part of code (I program using arduino IDE, so I don't "need" to learn new programming language, well, apart from HTML)
THE problem, is that data is shown only very small time, blinks very quickly. Inititally, before any text input, MDNS is shown on matrix, and even that flickers a lot (my code has flicker issues with longer text srings, but once I have this part covered, I'll switch to teensy, no flicker issues with that)
This is what it should show like, tested with both hc-05 and wired serial:
https://www.facebook.com/photo.php?fbid ... 2f7ab46a3e
video showing that It truly works, this is not with serial input, but scrolling text still.
https://www.youtube.com/watch?v=k5QvCQ7vaiE
When using ESP, It's like text is shown only very short time, but according ti serial monitor, no extra line feeds are fed from esp to arduino.

The code for ESP8266-part I mangled from this post:
http://embedded-lab.com/blog/wifi-enabl ... x-display/
Scematic:
http://i.imgur.com/8WdpaNR.jpg


I can tell more of hardware if needed, or post more code.
Thanks in advance!.
Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

MDNSResponder mdns;

// Replace with your network credentials
const char* ssid = "KONIG_WS01";
const char* password = "admin";

ESP8266WebServer server(80);

String webPage = "";


void setup(void) {

  webPage += "<h1>ESP8266 Web Server</h1>";
  webPage +=   "<form action='msg'><p>Type your message <input type='text' name='msg' size=100 autofocus> <input type='submit' value='Submit'></form>";


  delay(1000);
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }

  server.on("/", []() {
    server.send(200, "text/html", webPage);
  });

    server.on("/msg", []() {
    server.send(200, "text/html", webPage);
  String msg = server.arg("msg");
  Serial.println(msg);    delay(1000);
  });

 
  server.begin();
  Serial.println("HTTP server started");
}

void loop(void) {
  server.handleClient();
}

And then, the relevant parts of matrix code (part what processes the serial input data)




Code: Select all
char string[40]; //array to store incoming data
char textFromPc[40]; //array to store actual text to show on matrix

char c;
byte index;
byte textlength; //for dynaminc scroll length
char * strtokIndx; // this is used by strtok() as an index


 byte Yoffset = 0;
byte Rotation = 0;

void setup() //setup runs once
{
  DDRD = DDRD | B11111100; //port registers used to set pin directions
  Serial.begin(115200);
}


void loop() //just sitting here
{

  if (Serial.available() > 0)
  {
    c = Serial.read();

    if ((c != '\r') && (c != '\n')) //Keep these out of our buffer
    {
      string[index++] = c; //Add whatever we receive to the buffer
    }

    else
    {
      textlength = index * 8 + 32;  // *8, since matrises are 8-wide, and 32 to scroll whole screen.
      string[index++] = '\0';//Converts the array into a string
      index = 0; //next time we start from beginning index
      parseData(); //time to parse data received
      //showParsedData(); //for debugging!

    }
  }
  clr();
  text(textFromPc, 31 - millis() / 100 % textlength, Yoffset, Rotation);
  draw();
}




void parseData()  //function for splitting the array
{

  strtokIndx = strtok(string, ",");     // get the first part - the TEXT PART
  strcpy(textFromPc, strtokIndx); // copy it to messageFromPC

  strtokIndx = strtok(NULL, ",");
  Yoffset = atoi(strtokIndx);

  strtokIndx = strtok(NULL, ",");
  Rotation = atoi(strtokIndx);

}


EDIT: forgot something relevant....
Last edited by fezder on Thu Dec 08, 2016 3:45 am, edited 1 time in total.
User avatar
By fezder
#59223 Aha! Seems I have bug In my code, since I debugged bit with serial monitor.
This is code I used to debug, arriving data, what is going to buffer, and what is in buffer:
Code: Select all
char string[40]; //array to store incoming data
char textFromPc[40]; //array to store actual text to show on matrix

char c;
byte index;
byte textlength; //for dynaminc scroll length


void setup() //setup runs once
{
  Serial.begin(9600);
}


void loop() //just sitting here
{

  if (Serial.available() > 0)
  {
    c = Serial.read();
    Serial.print("before buffer:  ");
    Serial.println(c, DEC);

    if ((c != '\r') && (c != '\n')) //Keep these out of our buffer
    {
      string[index++] = c; //Add whatever we receive to the buffer
      //Serial.print("going to buffer:  ");
      //Serial.println(c, DEC);
    }
    else
    {
      textlength = index * 8 + 32;  // *8, since matrises are 8-wide, and 32 to scroll whole screen.
      string[index++] = '\0';//Converts the array into a string
      //Serial.print("at buffer, received in ASCII:  ");
      //Serial.println(string);
      index = 0; //next time we start from beginning index
    }
  }
}

Normal, written straight from monitor,when pressed enter:
Code: Select allbefore buffer:  10 //line feed!
at buffer, received in ASCII:    //nothing, since, LN is ignored

and, with esp:
Code: Select allbefore buffer: 13    //hmm, carrion return?
at buffer, received in ascii:
before buffer :10
at buffer, received in ascii:


and same test, with character "h":
normal:
Code: Select allbefore buffer:  104
going to buffer:  104
before buffer:  10
at buffer, received in ASCII:  h

esp:
Code: Select allbefore buffer: 104
going to buffer:104
before buffer: 13
at buffer , received in ASCII: h
before buffer: 10
at buffer, received in ASCII:

WHILE writing this, I found bug in my arduino part, so this fixed: (LN wasn't terminator in my code!)
Code: Select all
    if(c=='\n')
    {
      textlength = index * 8 + 32;  // *8, since matrises are 8-wide, and 32 to scroll whole screen.
      string[index++] = '\0';//Converts the array into a string
      //Serial.print("at buffer, received in ASCII:  ");
      //Serial.println(string);
      index = 0; //next time we start from beginning index

      parseData(); //time to parse data received
      //showParsedData(); //for debugging!

    }