Pages: 1 [2] 3   Go Down
Author Topic: Help add support for HT1632 in u8glib  (Read 2652 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 2
Posts: 85
(╯°□°)╯︵ ┻━┻
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes I did. I moved out the communication specific parts to a seperate sketch and I'm doing tests. I am trying to fill the display with data (fill the whole LED RAM). Something is broken and only three columns light up, but I hope I'll sort this out really soon!
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 85
(╯°□°)╯︵ ┻━┻
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Success! I have a complete sketch and I am able to send data on the display.

This is the working sketch, it flashes the screen on and off: http://pastebin.com/yrQtneA4

I have implemented the changes in my copy of u8glib but had no success in making it work. First of all, I did this change as we discussed:

Code:
[...]
switch(msg)
  {
    case U8G_DEV_MSG_INIT:
ht1632_init();
      break;
    case U8G_DEV_MSG_STOP:
      break;
[...]

To make sure that everything is ok, I changed the ht1632_init() procedure to:
Code:
void ht1632_init(void)
{
  digitalWrite(CS_PIN, LOW);
  /* init display once after startup */
  ht1632_write_data_MSB(3, HT1632_ID_CMD, false); // IDs are 3 bits
  ht1632_write_data_MSB(8, HT1632_CMD_SYSDIS, true); // 8 bits
  ht1632_write_data_MSB(8, HT1632_CMD_SYSON, true); // 8 bits
  ht1632_write_data_MSB(8, HT1632_CMD_COMS11, true); // 8 bits
  ht1632_write_data_MSB(8, HT1632_CMD_LEDON, true); // 8 bits
  ht1632_write_data_MSB(8, HT1632_CMD_BLOFF, true); // 8 bits
  ht1632_write_data_MSB(8, HT1632_CMD_PWM+15, true); // 8 bits 
  digitalWrite(CS_PIN, HIGH);

  // Fill the screen
  // #######################################
  digitalWrite(CS_PIN, LOW);
  ht1632_write_data_MSB(3, HT1632_ID_WR, false); // Send "write to display" command
  ht1632_write_data_MSB(7, 0, false);
  uint8_t i;
  for(i = 0; i<48; ++i)
  {
    ht1632_write_data(8,0xFF);
  }
  digitalWrite(CS_PIN, HIGH);
  // #######################################
}

I also did made change to the sketch in order to have only to invoke only the init function:
Code:
void loop(void)
{
  u8g_t u8g;
 
  u8g_Init(&u8g, &u8g_dev_ht1632_26x16);
  /*u8g_FirstPage(&u8g);
  u8g_SetColorIndex(&u8g, 1);
  do  {
    u8g_SetFont(&u8g, u8g_font_7x13);
    u8g_DrawStr(&u8g, 0, 14, "ABCgdef");
  }while( u8g_NextPage(&u8g) );*/
  delay(1000);
}

What should I do now?
Logged

Germany
Offline Offline
Edison Member
*
Karma: 136
Posts: 1491
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what happens if you uncomment your draw procedure?
You should also move the init procedure into setup():
Code:
u8g_t u8g;
 
void setup(void) {
  u8g_Init(&u8g, &u8g_dev_ht1632_26x16);
}

void loop(void) {
  u8g_FirstPage(&u8g);
  u8g_SetColorIndex(&u8g, 1);
  do  {
    u8g_SetFont(&u8g, u8g_font_7x13);
    u8g_DrawStr(&u8g, 0, 14, "ABCgdef");
  }while( u8g_NextPage(&u8g) )
  delay(1000);
}
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 85
(╯°□°)╯︵ ┻━┻
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is my current sketch:
Code:
#include "U8glib.h"

u8g_t u8g;

void setup(void)
{
  u8g_Init(&u8g, &u8g_dev_ht1632_26x16);
}

void loop(void)
{
  u8g_FirstPage(&u8g);
  u8g_SetColorIndex(&u8g, 1);
  do  {
    //u8g_SetFont(&u8g, u8g_font_7x13);
    //u8g_DrawStr(&u8g, 0, 14, "ABCgdef");
  }while( u8g_NextPage(&u8g) );
  delay(1000);
}

I am sure that the init procedure is called. I placed digitalWrite(13, HIGH) on the first and the LED lights up. It not bright as it should, for some reason it's dim. EDIT: Something might be using the SPI port on u8glib. I uploaded the Blink example and it's bright as it should. I don't have anything connected on pin 13.

Nothing is shown on the display. I still have my custom code to fill the graphics RAM (like my test sketch).

EDIT2:
Minor success! I'm not getting the full RAM filled again but I'm looking into it. That's what was missing.
Code:
 pinMode(DATA_PIN, OUTPUT);
  pinMode(WR_PIN, OUTPUT);
  pinMode(CS_PIN, OUTPUT);

  digitalWrite(DATA_PIN, HIGH);
  digitalWrite(WR_PIN, HIGH);
  digitalWrite(CS_PIN, HIGH);
smiley-cool
« Last Edit: May 30, 2013, 03:38:24 pm by Abfahrt » Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 85
(╯°□°)╯︵ ┻━┻
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

New post because my last one is a mess. I finally got it working! Data is being sent. After init finishes the whole display is lit up. When I uncomment the do statement (not the contents, just the statement) about half of the screen turns black. If I uncomment the contents of the screen garbage is written on the cleared part.
Logged

Germany
Offline Offline
Edison Member
*
Karma: 136
Posts: 1491
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you post a picture of the "garbage"? Could it be the upper part of "ABC". Maybe mirrored?
Can you also post the current sketch?

Oliver
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 85
(╯°□°)╯︵ ┻━┻
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is what is currently shown on the display. You can see the uncleared part on the right and the garbage on the left. http://imgur.com/KsbFLz1

This is the sketch:
Code:
#include "U8glib.h"

u8g_t u8g;

void setup(void)
{
  u8g_Init(&u8g, &u8g_dev_ht1632_26x16);
}

void loop(void)
{
  u8g_FirstPage(&u8g);
  u8g_SetColorIndex(&u8g, 1);
  do  {
    u8g_SetFont(&u8g, u8g_font_7x13);
    u8g_DrawStr(&u8g, 0, 14, "ABCgdef");
  }while( u8g_NextPage(&u8g) );
  delay(1000);
}
Logged

Germany
Offline Offline
Edison Member
*
Karma: 136
Posts: 1491
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you also post your current "u8g_dev_ht1632.c" file?
I assume that the data write will look similar to this code:
Code:
void ht1632_transfer_data(uint8_t page, uint8_t cnt, uint8_t *data)
{
  uint8_t addr;
  /* send data to the ht1632 */
  digitalWrite(CS_PIN, LOW);
  ht1632_write_data_MSB(3, HT1632_ID_WR, false); // Send "write to display" command
  ht1632_write_data_MSB(7, page*26, false); // Oliver: Not sure if this calculation is correct

  // Operating in progressive addressing mode
  for (addr = 0; addr < cnt; addr++)
  {
    ht1632_write_data(8, data[addr]); 
  } 
  digitalWrite(CS_PIN, HIGH);
}


How will the display change if you modify the code to this (only display the first page of u8glib)?
Code:
void ht1632_transfer_data(uint8_t page, uint8_t cnt, uint8_t *data)
{
  uint8_t addr;

  if ( page != 0 )
   return;
  /* send data to the ht1632 */
  digitalWrite(CS_PIN, LOW);
  ht1632_write_data_MSB(3, HT1632_ID_WR, false); // Send "write to display" command
  ht1632_write_data_MSB(7, page*26, false); // Oliver: Not sure if this calculation is correct

  // Operating in progressive addressing mode
  for (addr = 0; addr < cnt; addr++)
  {
    ht1632_write_data(8, data[addr]); 
  } 
  digitalWrite(CS_PIN, HIGH);
}

One big problem for me is, that i do not understand how the bits are mapped on the screen.
Maybe you could output the following pattern instead of 0xFF:
Code:
// Fill the screen
  // #######################################
  digitalWrite(CS_PIN, LOW);
  ht1632_write_data_MSB(3, HT1632_ID_WR, false); // Send "write to display" command
  ht1632_write_data_MSB(7, 0, false);
  uint8_t i;
  for(i = 0; i<48; ++i)
  {
    ht1632_write_data(8,i);
  }
  digitalWrite(CS_PIN, HIGH);
  // #######################################
Maybe you can make another picture with this pattern, so that we can better understand how the bits are mapped to the screen.

Please excause asking for so many code and pictures, but remote programming sometimes seems to be very complicated...

Oliver

Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 85
(╯°□°)╯︵ ┻━┻
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is the file I'm using: http://pastebin.com/cWTa7B2a

I changed page*8 to page*26 and this is the result: http://imgur.com/RTgFkhE

Changing both page*26 and adding the if-statement: http://imgur.com/JBJ5gut

The screen is filled from top left downwards. A byte will fill the first 8 pixels from 0,0 to 0,8, the second will fill 0,8 to 0,16! The picture makes it more clear though: http://imgur.com/0UILEN8

I'm more than happy to help you implement it, I asked it in the first place! smiley-grin Thanks again for looking into this!
Logged

Germany
Offline Offline
Edison Member
*
Karma: 136
Posts: 1491
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The screen is filled from top left downwards. A byte will fill the first 8 pixels from 0,0 to 0,8, the second will fill 0,8 to 0,16! The picture makes it more clear though: http://imgur.com/0UILEN8

Ah, i see the problem. I was assuming, that the first byte goes to 0,0 to 0,8 and the second byte goes to 1,0 to 1,8.
B0 -> B1 -> B2-> ... -> B23
B24 -> B25-> ... -> B47
However, memory structure is like this:
B0 B2 B4 ...
B1 B3 B5 ...

I fixed this in the code and also integrated your other modifications (including the renaming to 24x16) into a new prerelase (attached pre6).
So the question is again: What will you see?

Oliver

* u8glib_arduino_v1.13pre6.zip (1016.51 KB - downloaded 11 times.)
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 85
(╯°□°)╯︵ ┻━┻
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Display is working! Thank you very much!!!

You can remove this piece of code from the init function:
Code:
 digitalWrite(CS_PIN, LOW);
  ht1632_write_data_MSB(3, HT1632_ID_WR, false); // Send "write to display" command
  ht1632_write_data_MSB(7, 0, false);
  for(i = 0; i<48; ++i)
  {
    ht1632_write_data(8, 0xFF);
  }
  digitalWrite(CS_PIN, HIGH);

One last thing! The display support 16 levels of brightness. Do you think that should be added as contrast in u8glib? I did a start:
Code:
case U8G_DEV_MSG_CONTRAST:
  digitalWrite(CS_PIN, LOW);
  ht1632_write_data_MSB(3, HT1632_ID_CMD, false);
  ht1632_write_data_MSB(8, HT1632_CMD_PWM + pwmValue, true);
  digitalWrite(CS_PIN, HIGH);
  return 1;
But I'm not sure how the brightness value is passed and if return 1 should be removed. pwmValue should be a uint8_t between 0 and 15.
« Last Edit: May 31, 2013, 05:05:51 am by Abfahrt » Logged

Germany
Offline Offline
Edison Member
*
Karma: 136
Posts: 1491
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great.

I will implement the set contrast feature. Additionally i will also try to make pin handling more flexible.
Would it be possible to make another picture from your device for my gallery page (http://code.google.com/p/u8glib/wiki/gallery)? This would be cool.

Thanks so far.
Oliver
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 85
(╯°□°)╯︵ ┻━┻
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have 4 of these displays and I'm planning on using them as one, 48x32 display. Do you want a picture of the big one or the small 24x16 one? It's hard to display anything readable on the 24x16 display.

Again, thanks for making this possible!
Logged

Germany
Offline Offline
Edison Member
*
Karma: 136
Posts: 1491
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Anything is fine, but I think a picture of your current 24x16 will be sufficient.

Thanks a lot.

Oliver
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 85
(╯°□°)╯︵ ┻━┻
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here you go: http://imgur.com/QNmhuju

Thanks for the cooperation! Keep up the good work smiley-grin
Logged

Pages: 1 [2] 3   Go Up
Jump to: