E-Paper Display trouble sending serial string

Hi Guys,

I'm currently working on a project to display a String on the e-Paper display by waveshare.

I've set up everything and modified the demo program, that is shipped by waveshare.
I can display any text i create in that file.

However I'm trying to receive text via Serial.read() that is sent by the Arduino software. (e.G. "Hello").

To start off, my code looks like this:

* File                : Arduino-epd
* Hardware Environment: 
* Build Environment   : Arduino
* Version             : V1.6.1
* By                  : WaveShare
*                                  (c) Copyright 2005-2015, WaveShare
*                                       http://www.waveshare.net
*                                       http://www.waveshare.com
*                                          All Rights Reserved
#include "epd.h"

const int led = 13;                           //user led
char tmp = -1;

void draw_text_demo(const void *str)
  epd_set_color(BLACK, WHITE);
  char* ptr = (char*)str;
  epd_disp_string(ptr, 200, 250);



void setup(void)
  user led init
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);

   start serial connection

void loop(void)
  Draw text demo

  char str[5];

   Wait for serial input
  if (Serial.available() > 0){
    int index = 0;
    while (Serial.available() > 0)
      tmp = Serial.read();
      str[index] = tmp;
    str[index] = '\0';


The corresponding cpp method epd_disp_string() looks like this:

* Function Name  : void epd_disp_string(const void * p, int x0, int y0)
* Description    : 
* Input          : 
* Output         : None
* Return         : 
* Attention		   : None
void epd_disp_string(const void * p, int x0, int y0)
	int string_size;
	unsigned char * ptr = (unsigned char *)p;
	string_size = strlen((const char *)ptr);
	string_size += 14;
	_cmd_buff[0] = FRAME_B;
	_cmd_buff[1] = (string_size >> 8) & 0xFF;
	_cmd_buff[2] = string_size & 0xFF;
	_cmd_buff[3] = CMD_DRAW_STRING;
	_cmd_buff[4] = (x0 >> 8) & 0xFF;
	_cmd_buff[5] = x0 & 0xFF;
	_cmd_buff[6] = (y0 >> 8) & 0xFF;
	_cmd_buff[7] = y0 & 0xFF;
	strcpy((char *)(&_cmd_buff[8]), (const char *)ptr);
	string_size -= 5;
	_cmd_buff[string_size] = FRAME_E0;
	_cmd_buff[string_size + 1] = FRAME_E1;
	_cmd_buff[string_size + 2] = FRAME_E2;
	_cmd_buff[string_size + 3] = FRAME_E3;
	_cmd_buff[string_size + 4] = _verify(_cmd_buff, string_size + 4);
	_putchars(_cmd_buff, string_size + 5);

Everything compiles without any exception or warning.
BUT: When I run the program and try to send a String, the display does not react, but however the correct String is sent back to the Serial Monitor on my PC (via Serial.print(ptr) inside draw_text_demo()). So the the Arduino receives the String correctly, it just seems like it is unable to run the .cpp method epd_disp_string() as seen above.

When I overwrite the str variable inside the code to single chars like:

      str[0] = (char)'H';
      str[1] = (char)'E';
      str[2] = (char)'L';
      str[3] = (char)'L';
      str[4] = (char)'O';
      str[5] = '\0';

and pass it to draw_text_demo() everything works perfectly fine. The screen displays the string and the string is sent back to the Serial Monitor.

Am I missing something with Serial.read()? I feel like the values inside the char-array 'str' are not real chars. Is that possible?

It's a long time since I've been programming in C++ the last time, but I don't think its a syntax issue. Or is it?

Hopefully i didn't miss any important information. If so, feel free to ask.

Thank you so much in advance guys, I'm really stuck in this one. :confused:

Best wishes

Hi Tobi

From the code snippet of your code it is hard to tell what is wrong. You might show more of your code.

Maybe you confound C “string” character arrays with C++ String class?

The Waveshare demo code is not so nice to use; I converted it to a C++ class. See attached zip.


WVS43EPD.zip (5.02 KB)