Arduino draws two points instead of one

Hi,

I’m having a problem with my code.

The code should draw a point on the “24x16 Dot-Matrix-Display Type DE-DP11112” display (two of them connected making it a 48x16 display, thus an buffer array of 48), but instead it draws two points at in my opinion random locations.
As can be seen in my code I tried multiply ways of figuring out what could possible be wrong without having found anything which works.

uint16_t buffer[48]={ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; //48 x 16-bit data


void takt() {
    digitalWrite(WR, LOW);
    CLK_DELAY;
    digitalWrite(WR, HIGH);
    CLK_DELAY;
}

// data to send in buffer, so no data parameter here
void senddata(uint8_t cs) {
  if(cs == 0) {
    // Chip-Selekt aktivieren
    digitalWrite(CS1, LOW);
  } else if(cs != 0) {
    // Chip-Selekt aktivieren
    digitalWrite(CS2, LOW);
  }
  send(1);
  send(0);
  send(1);

  // send the adress of the chip for the data to go to
  for(uint8_t x = 0; x < 7; x++) {
    send(0);
  }
  
  // send the data itself
  for(uint8_t x = 0; x < width; x++) {
    for(uint8_t y = 0; y < height; y++) {
      send(y,buffer[x+cs]);
      //sendcollum(buffer[x + cs]);
      //digitalWrite(DT, (((buffer[x + cs]) >> (x)) & 0x01));
      //takt();
      // Debug-Print
      Serial.print(buffer[x + cs]);
      Serial.print('\n');
    }
  }
  //Chip-Selekt deactivation
  digitalWrite(cs, HIGH);
}

void sendcollum(uint16_t cmd) {
  for(uint8_t i = 0; i < height; i++) {
  
    /*if((cmd & MASK01) == 0) {
      digitalWrite(DT, LOW);
    } else {
      digitalWrite(DT, HIGH);
    }*/
    send(i,cmd);
  }
  takt();
  
  cmd = (cmd >> 1);
}

void send(int index,uint16_t data){
  send(bitRead(data,index));
}

void send(bool b){
  digitalWrite(DT,b); // send bool
  digitalWrite(WR,LOW);
  CLK_DELAY;
  digitalWrite(WR,HIGH);
  CLK_DELAY;
}

void drawPoint(uint8_t x, uint8_t y, uint8_t cs) {
  uint16_t mask = (1L << height) - 1;
  buffer[x] = buffer[x] | mask & (1 << (y - 1));
  
  senddata(cs);
}

I hope someone can find what is wrong as I wasn’t able to find the solution in the past probably 4 hours.

Please show your entire sketch, not just a snippet.

/*    Hardware: AVR Board 201x und 24x16 Dot-Matrix-Display Typ DE-DP11112 */


#include <util/delay.h>

#define CS1 8
#define CS2 9
#define CS3 10 
#define CS4 11  
#define WR 12 
#define RD 13
#define DT A4 

#define SYS_EN     0b100000000010   //Enable Display System Oszillator
#define M_MODE     0b100000110000   //Set Display MASTER-Mode
#define LED_ON     0b100000000110   //Enable Display LEDs
#define LED_OFF    0b100000000100   //Disable Display LEDs
#define NMOS_COM16 0b100001001000   //Display Mode 24x16 NMOS  open Drain Output
#define PWM_04     0b100101000110   //PWM:  4/16 dutycycle
#define PWM_08     0b100101001110   //PWM:  8/16 dutycycle
#define PWM_16     0b100101011110   //PWM: 16/16 dutycycle
#define BLK_ON     0b100000010010   //Blink-Mode On
#define BLK_OFF    0b100000010000   //Blink-Mode Off

#define MSBMASK   0b100000000000           
#define MASK16    0b1000000000000000      
#define MASK01    0b0000000000000001    
#define MASK10    0b1000000000        
#define MASK03    0b100              
#define MASKOBEN  0b0000000011111111
#define MASKUNTEN 0b1111111100000000

#define CLK_DELAY  _delay_us(2);//macro: wait 2µ

static uint8_t pat_1[8]={0,0b00000000,0b01000010,0b01111111,0b01000000,0b00000000,0,0};
static uint8_t pat_2[8]={0,0b01000010,0b01100001,0b01010001,0b01001001,0b00000110,0,0};
static uint8_t ruf_p[8]={0,0b00000000,0b00000000,0b01001111,0b00000001,0b00000000,0,0};
static uint8_t fra_p[8]={0,0b00000010,0b00000010,0b01010001,0b00001001,0b00000110,0,0};
static uint8_t num_p[8]={0,0b00100100,0b01111111,0b00100100,0b01111111,0b00100100,0,0};

// 26 letters, 8 Columns each letter
static uint8_t alphabet[26][8] = {
  {0,0b01111110,0b00010001,0b00010001,0b00010001,0b01111110,0,0}, 
  {0,0b01111111,0b01001001,0b01001001,0b01001001,0b00110110,0,0}, 
  {0,0b00111110,0b01000001,0b01000001,0b01000001,0b00100010,0,0}, 
  {0,0b01111111,0b01000001,0b01000001,0b00100010,0b00011100,0,0}, 
  {0,0b01111111,0b01001001,0b01001001,0b01001001,0b01000001,0,0},
  {0,0b01111111,0b00001001,0b00001001,0b00001001,0b00000001,0,0},
  {0,0b00111110,0b01000001,0b01001001,0b01001001,0b01111010,0,0},
  {0,0b01111111,0b00001000,0b00001000,0b00001000,0b01111111,0,0},
  {0,0b00000000,0b01000001,0b01111111,0b01000001,0b00000000,0,0},
  {0,0b00100000,0b01000000,0b01000001,0b00111111,0b00000001,0,0},
  {0,0b01111111,0b00001000,0b00010100,0b00100010,0b01000001,0,0},
  {0,0b01111111,0b01000000,0b01000000,0b01000000,0b01000000,0,0},
  {0,0b01111111,0b00000010,0b00001100,0b00000010,0b01111111,0,0},
  {0,0b01111111,0b00000100,0b00001000,0b00010000,0b01111111,0,0},
  {0,0b00111110,0b01000001,0b01000001,0b01000001,0b00111110,0,0},
  {0,0b01111111,0b00001001,0b00001001,0b00001001,0b00000110,0,0},
  {0,0b00111110,0b01000001,0b01010001,0b00100001,0b01011110,0,0},
  {0,0b01111111,0b00001001,0b00011001,0b00101001,0b01000110,0,0},
  {0,0b01000110,0b01001001,0b01001001,0b01001001,0b00110001,0,0},
  {0,0b00000001,0b00000001,0b01111111,0b00000001,0b00000001,0,0},
  {0,0b00111111,0b01000000,0b01000000,0b01000000,0b00111111,0,0},
  {0,0b00011111,0b00100000,0b01000000,0b00100000,0b00011111,0,0},
  {0,0b00111111,0b01000000,0b00111000,0b01000000,0b00111111,0,0},
  {0,0b01100011,0b00010100,0b00001000,0b00010100,0b01100011,0,0},
  {0,0b00000111,0b00001000,0b01110000,0b00001000,0b00000111,0,0},
  {0,0b01100001,0b01010001,0b01001001,0b01000101,0b01000011,0,0}
};

static const int height = 16;
static const int width = 24;
static const int bufferSize = (int)((height * width) / 8);

uint16_t output[4]={ CS1, CS2, WR, DT };
uint16_t buffer[bufferSize]={ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; //48 x 16-bit Daten

void takt() {
    digitalWrite(WR, LOW);
    CLK_DELAY;
    digitalWrite(WR, HIGH);
    CLK_DELAY;
}

void wait_xms ( uint16_t ms )     
{
    for(; ms > 0; ms--) _delay_ms(1);
}

void sendcom(uint16_t cmd, uint8_t cs)      
{
  digitalWrite(DT, HIGH);
  digitalWrite(cs,LOW);
  
  for(int8_t i = 12; i > 0; i--) {
    digitalWrite(DT, ((cmd & MSBMASK) >> 11));
    takt();
    cmd = cmd << 1;
  }
  digitalWrite(cs, HIGH);
}

// data to send in buffer, so no data parameter here
void senddata(uint8_t cs) {
  if(cs == 0) {
    digitalWrite(CS1, LOW);
  } else if(cs != 0) {
    digitalWrite(CS2, LOW);
  }
  send(1);
  send(0);
  send(1);

  // send the adress of the chip for the data to go to
  for(uint8_t x = 0; x < 7; x++) {
    send(0);
  }
  
  // send the data itself
  for(uint8_t x = 0; x < width; x++) {
    for(uint8_t y = 0; y < height; y++) {
      send(y,buffer[x+cs]);
      //sendcollum(buffer[x + cs]);
      //digitalWrite(DT, (((buffer[x + cs]) >> (x)) & 0x01));
      //takt();
      // Debug-Print
      Serial.print(buffer[x + cs]);
      Serial.print('\n');
    }
  }
  //Chip-Selekt deactivation
  digitalWrite(cs, HIGH);
}

void sendcollum(uint16_t cmd) {
  for(uint8_t i = 0; i < height; i++) {
    /*if((cmd & MASK01) == 0) {
      digitalWrite(DT, LOW);
    } else {
      digitalWrite(DT, HIGH);
    }*/
    send(i,cmd);
  }
  takt();
  cmd = (cmd >> 1);
}


void send(int index,uint16_t data){
  send(bitRead(data,index));
}

void send(bool b){
  digitalWrite(DT,b);//send bool
  digitalWrite(WR,LOW);
  CLK_DELAY;
  digitalWrite(WR,HIGH);
  CLK_DELAY;
}

/**
 * SETUP
 */

void setup() {
  Serial.begin(9600);
  for(uint16_t i : output) {
    pinMode(i, OUTPUT);
  }
  sendcom(SYS_EN, CS1);
  sendcom(M_MODE, CS1);
  sendcom(NMOS_COM16, CS1);
  sendcom(LED_ON, CS1);
  sendcom(PWM_16, CS1);
  sendcom(BLK_OFF, CS1);

  sendcom(SYS_EN, CS2);
  sendcom(M_MODE, CS2);
  sendcom(NMOS_COM16, CS2);
  sendcom(LED_ON, CS2);
  sendcom(PWM_16, CS2);
  sendcom(BLK_OFF, CS2);
}

void drawPoint(uint8_t x, uint8_t y, uint8_t cs) {
  uint16_t mask = (1L << height) - 1;
  buffer[x] = buffer[x] | mask & (1 << (y - 1));
  
  senddata(cs);
}
 
void loop() {
  drawPoint(42, 1, CS2);
}

What happens when you fill the buffer with a test pattern, like 0x55 0xAA 0x55 0xAA... ?

aarg:
What happens when you fill the buffer with a test pattern, like 0x55 0xAA 0x55 0xAA... ?

As I currently don't have acess to the board I can't test it with this pattern, but testing it with 0x0 and 0x1 gave me these results:

  • 0x0 --> screen cleared, even when something was displayed before
  • 0x1 --> screen lights up

Thought would be nice to know a way to test code without having the board and display lying around here.

sha-dow:
As I currently don't have acess to the board I can't test it with this pattern, but testing it with 0x0 and 0x1 gave me these results:

  • 0x0 --> screen cleared, even when something was displayed before
  • 0x1 --> screen lights up

Thought would be nice to know a way to test code without having the board and display lying around here.

How can you have results, without any board and display? I'm confused.

aarg:
How can you have results, without any board and display? I’m confused.

Because I don’t have a board or a display but a friend of me got this hardware.
Well, I could test the 0xAA and 0x55 stuff today and the result is some interesting animation
with 3 moving blocks. One beeing at the top, one at the bottom and one a bit further towards the middle in the middle of the height.

EDIT: Ok, I found one bug in my code in senddata:

  //Chip-Selekt deactivation
  digitalWrite(cs, HIGH);

to

  //Chip-Selekt deactivation
  if(cs == 0) {
    digitalWrite(CS1, HIGH);
  } else if(cs != 0) {
    digitalWrite(CS2, HIGH);
  }

Now I’ve got the upper part of the screen light up while the bottom part is disabled. In the upper part every second LED lights up.
It’s also some animation, the upper part lights up from x0 towards the end of the screen at x48 and moves then the LEDs start to get disabled beginning from x0 towards x48.
Meaning it lights up as intended, the first 8 LEDs of each collum light up with the template 01010101 and 10101010. Thought somehow it is animated while drawPoint seems to be doing nothing anymore.

Main loop:

// clear the screen
  for(int i = 0; i < bufferSize; i++) {
    buffer[i] = 0x0;
  }
// copy 0x55 0xAA 0x55 0xAA template into the buffer to be displayed
  for(int i = 0; i < bufferSize; i++) {
    buffer[i] = buffer2[i];
  }
  senddata(0);
  senddata(1);

Note: drawPoint doesn’t seem to be working anymore. Atleast no LED lights up on the screen when just using drawPoint.

  if(cs == 0) {
    digitalWrite(CS1, HIGH);
  } else if(cs != 0) {

If cs does not contain 0, is there ANY possible way that the evaluation after the else statement will EVER be anything but true? If not, clearly there is no reason to perform the test. If so, you live in a universe with different logic than the rest of us. Perhaps you need to consult a forum in your universe, where they don't require ALL of your code (like we do).