Creating hexadecimal numbers for e ink display

So I would like to modify the pixels by myself, and then convert these pixels into hexadecimal numbers. My problem is the loop. Arduino mega can't compile. I tried to reduce the loops' variables upper limit, if i reduce it to 1, so the loop only runs once then it works, but if any of the loop variables is bigger than 1 than it's just not doing anything.
I assumed my arrays are too big, so I started to use 2 dimensional arrays as you can see in the code, but it doesn't help at all.
the code:


int s =15;
int o=15;

void setup() {
Serial.begin(9600);
}
  

void loop() {
  
 byte kp[128][80]={0};//pixels of a display with 128 pixels in a row and 80 in a column, these are either 0 or 1 
 
  byte h[1280][2]={0}; //I want to get hexadecimal number, so first I would convert the bits below to decimal, upper 4 bits to h[x][0], lower 4 bits to h[x][1], and than i could easily convert these to the hexadecimal format i need for example: "0xFF" 
 
 
  kp[s][o]=1;    kp[s][o+1]=1;  kp[s][o+2]=1;  kp[s][o+3]=1;            // this is an "A" letter. i modify the kp array's values so it look like this 
  kp[s+1][o]=1;                                kp[s+1][o+3]=1;
  kp[s+2][o]=1; kp[s+2][o+1]=1; kp[s+2][o+2]=1;kp[s+2][o+3]=1;
  kp[s+3][o]=1;                                kp[s+3][o+3]=1;
  kp[s+4][o]=1;                                kp[s+4][o+3]=1;
    
  
int sz=0;
int i=0;
int j=0;

while (i<128)
{
  while (j<80)
  {


 h[sz][0]=8*kp[i][j]+4*kp[i][j+1]+2*kp[i][j+2]+kp[i][j+3];      //converting the upper 4 bits
 h[sz][1]=8*kp[i][j+4]+4*kp[i][j+5]+2*kp[i][j+6]+kp[i][j+7];    //converting the lower 4 bits
  
sz++;
i++;
j+=8;

Serial.print(sz);
Serial.print(" ");
Serial.print(h[sz][0]);
Serial.print(" ");
Serial.println(h[sz][1]);


  }
  }

  
}

Try to imagine that we can't see your code

Back to you.

Yeah I tried to upload the file, but couldn't do that since I am new here, so I just modyfied my post

On a processor with 8192 bytes of RAM

Please remember to use code tags when posting code

so instead of storing zeros and ones in bytes, i should maybe bitWrite the bites, so one byte would already consist 8 pixels?

Or using multiple samaller arrays could help too?

That would be a start… would still require 1280 bytes to have a black and white (off/on) frame buffer.

Are you trying to create a font? How large each digit would be (width and height in pixels)?

First remember a pixel only requires one bit, so your Array is 8X what is needed.
If color then it gets more complex but still much smaller than you have allocated.

then convert these pixels into hexadecimal numbers

Not clear what you mean by this. Are you talking about the pixel location? If so would describe this conversion is plain english?

its a regular black and white e ink display. It would be just nice if I could write all kind of texts.
i just wanted to write an "A" first. 4 pixels wide 5 pixels high

I'm really not clear what you're doing - if it is designing a font, just get some squared paper.

So you need to build a font of B&W glyphs.
First approach would be that Each glyph requires 4x5= 20 bits and for ease of bitwise operations you would probably use 4 bytes of 5 significant bits

so for the alphabet (upper case I suppose) it’s 26 letters, +10 digits and may be a bit of punctuation. If you have 50 glyphs (Or do you want to go for the full printable ASCII chars?), then it’s 50x4= 200 bytes of memory (which could be in flash)

If you pack 2 glyphs together you could represent them as 5 bytes (of 2x4= 8 bits) and your 50 glyphs would be 50/2x5=125 bytes. It would require a bit of math and bitwise operation to extract the representation of the actual glyph

Yeah okay, so the main idea was to create a big array with 128 rows and 80 columns, so each variable of the array would be either 0 or 1, black or white. After this I would modify this array so that if we imagine the array the ones would look like an "A" in it.
image
I already have this.
After this I want to create the hexadecimal numbers which represent the position of the pixels.

If your hex isn't that strong, you could always use the "0b" binary notation.

I have a demo program which uses hexadecimal numbers. The font is not the problem..... yet:D, my problem is the loop. Its weird because if (i<1) and (j<1) then my code runs. But if either of i or j can be bigger, so the loop would work as a loop, than it doesn't work anymore.

But okay I will now try to reduce my variable waste so i will try to use bitWrite so i will use all 8 bits of a byte not only 1

Don’t underestimate what the optimizer can do for you if it sees you don’t need the whole array and just a few well known cells. While loop can be unwound and the array just replaced by a few variables

Curious why you wish to roll your own rather than using one of the already published libraries?

A week ago I used the GxEDP library with a simple example. It ran in a pro mini. The example printed text and bitmapped screens. My ePaper is 176 X 264 (2.7")

I have since upgaded to the more current GxEPD2 library.

I would just like to write it for myself it's for a school project so would be best if i made it.

1 Like

Its good to hear you are working on your project yourself instead of asking for a solution as so many others have.
Good luck to you, your integrity will be a good asset in the future. (as long as you don't go into politics :slight_smile: )

haha thank you:)
So I tried to do this a bit differently by using the bytes' bits as the pixels themselves.

So now the loop goes smooth, but when i try to convert the bits to hexadecimal numbers I can't see the correct values as i print them to the serial monitor. They are just zeros. But when i do it without a loop multiplying the bits with their value it seems to be good, i checked without a loop.
So for one specefic one, for example

h[0][0]= 8bitRead(kp[0][0],0)+4bitRead(kp[0][0],1)+2*bitRead(kp[0][j0,2)+bitRead(kp[0][0],3);

h[0][0] would give me the correct decimal value of these 4 bits, i tried this. But with the loop it just doesn't work.

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}
void loop() {
 byte kp[128][10]={0};    //in every byte every bit represents a pixel, i have 10 times 8 pixen in a row and 128 pixel in a column
 int h[1280][2]={0};      //i will need 1280 hexadecimal number which represents these bytes with the 8 pixels
kp[10][5]=255;
kp[13][5]=255;
kp[16][6]=255;
int sz=0;
for (int i=0; i<128; i++)
{
  for (int j=0; j<10; j++)
  {
   h[sz][0]= 8*bitRead(kp[i][j],0)+4*bitRead(kp[i][j],1)+2*bitRead(kp[i][j],2)+bitRead(kp[i][j],3); //the upper 4 bits converted to deciaml later to hexadecimal
   h[sz][1]= 8*bitRead(kp[i][j],4)+4*bitRead(kp[i][j],5)+2*bitRead(kp[i][j],6)+bitRead(kp[i][j],7); //lower 4 bits converted to decimal          -||-
   sz++;
/*
   Serial.print(sz);
   Serial.print(" ");
   Serial.print(h[sz][0]);
   Serial.print(" ");
   Serial.print(h[sz][1]);
   Serial.print(" ");
   Serial.print(kp[10][5]);
   Serial.print(" ");
   Serial.println(kp[13][5]);*/
  }
}
}

Sorry for some reason some multiplications can be seen below like 8*bitRead(...... looks like 8bitRead(... so the *-s are missing

I think I understand what you're doing here, but just for clarification... You are looking for a way to create bitmaps as arrays, and use them to write characters to a monochrome display. You want to display numbers and letters on the display based on the bits that are set in the array that represent the pixels in the character.

If that's a correct assessment, have I got a deal for you! :slight_smile:

I recently wrote a utility to create bitmaps for an OLED display. It's web based and coded in JavaScript, but it may give you some insights on how to isolate bits and map them to pixels. (JavaScript is not all that different from C.) You can find it here: GitHub - DavesCodeMusings/oled-bitmapper

The README has details on how to get started, and there's a link to a live version you can use.