Show Posts
Pages: 1 2 [3] 4 5 6
31  Using Arduino / Displays / Re: Help add support for HT1632 in u8glib on: May 27, 2013, 04:02:21 pm
Yes, it writes the data to the chip in LSB

EDIT: I mean the display data!
32  Using Arduino / Displays / Re: Help add support for HT1632 in u8glib on: May 27, 2013, 03:13:29 pm
I'll share all the information I can. Ask me anything you need and I'll try to help you. Thanks for looking into this!

This is the command-set of the chip. There are more commands available but aren't used. Some of those commands are also not used but can be deleted after the driver is implemented. There are also definitions for command and data sizes.

Code:
#define HT1632_CMD_SYSDIS 0x00 // CMD= 0000-0000-x Turn off oscil
#define HT1632_CMD_SYSON 0x01 // CMD= 0000-0001-x Enable system oscil
#define HT1632_CMD_LEDOFF 0x02 // CMD= 0000-0010-x LED duty cycle gen off
#define HT1632_CMD_LEDON 0x03 // CMD= 0000-0011-x LEDs ON
#define HT1632_CMD_BLOFF 0x08 // CMD= 0000-1000-x Blink OFF
#define HT1632_CMD_BLON 0x09 // CMD= 0000-1001-x Blink On
#define HT1632_CMD_SLVMD 0x10 // CMD= 0001-00xx-x Slave Mode
#define HT1632_CMD_MSTMD 0x14 // CMD= 0001-01xx-x Master Mode
#define HT1632_CMD_RCCLK 0x18 // CMD= 0001-10xx-x Use on-chip clock
#define HT1632_CMD_EXTCLK 0x1C // CMD= 0001-11xx-x Use external clock
#define HT1632_CMD_COMS00 0x20 // CMD= 0010-ABxx-x commons options
#define HT1632_CMD_COMS01 0x24 // CMD= 0010-ABxx-x commons options
#define HT1632_CMD_COMS10 0x28 // CMD= 0010-ABxx-x commons options
#define HT1632_CMD_COMS11 0x2C // P-MOS OUTPUT AND 16COMMON OPTION
#define HT1632_CMD_PWM 0xA0 // CMD= 101x-PPPP-x PWM duty cycle

#define HT1632_ID_LEN 3 // IDs are 3 bits
#define HT1632_CMD_LEN 8 // CMDs are 8 bits
#define HT1632_DATA_LEN 8 // Data are 4*2 bits
#define HT1632_ADDR_LEN 7 // Address are 7 bits

This is the initialization sequence for the chip.
Code:
writeDataMSB(3, HT1632_ID_CMD, false); // IDs are 3 bits
writeDataMSB(8, HT1632_CMD_SYSDIS, true); // 8 bits
writeDataMSB(8, HT1632_CMD_SYSON, true); // 8 bits
writeDataMSB(8, HT1632_CMD_COMS11, true); // 8 bits
writeDataMSB(8, HT1632_CMD_LEDON, true); // 8 bits
writeDataMSB(8, HT1632_CMD_BLOFF, true); // 8 bits
writeDataMSB(8, HT1632_CMD_PWM+15, true); // 8 bits

This function writes IDs and command data into the display:
Code:
void writeDataMSB(byte cnt, byte data, bool extra) {
for(int8_t i = cnt - 1; i >= 0; i--) {
if ((data >> i) & 1) {
PORT |= 1 << DATA;
}
else {
PORT &= ~(1 << DATA);
}
//_nop();
PORT &= ~(1 << WR);
//_nop();
PORT |= 1 << WR;
//_nop();
    }

// Send an extra bit
if (extra) {
PORT |= 1 << DATA;
//_nop();
PORT &= ~(1 << WR);
//_nop();
PORT |= 1 << WR;
}
}

This function writes pixel data onto the display (after the appropriate command has been set):
Code:
void write_data(byte cnt, byte data) {
for (byte i = 0; i < cnt; i++) {
if ((data >> i) & 1) {
PORT |= 1 << DATA;
}
else {
PORT &= ~(1 << DATA);
}

PORT &= ~(1 << WR);
PORT |= 1 << WR;
}
}
PORT is the AVR port. DATA is the data pin and WR is the clock pin. Those should be changed to be set by u8glib I guess.

This code is used to write pixel data from a framebuffer:
Code:
selectDisplay(dispNum); // selects the display

writeDataMSB(3, HT1632_ID_WR); // Send "write to display" command
writeDataMSB(7, 0); // Send initial address (aka 0)

// Operating in progressive addressing mode
for (uint8_t addr = 0; addr < FB_SIZE; addr++) { // FB_SIZE is 48 bytes
value = framebuffer[addr];
writeDataLSB(8, value); 
}

releaseDisplay(dispNum);

I hope that helps!
33  Using Arduino / Displays / Re: Help add support for HT1632 in u8glib on: May 27, 2013, 11:27:59 am
What low-level functions do you need? There are some functions posted on Google Code and I assume they are used for data transfer.
34  Using Arduino / Displays / Help add support for HT1632 in u8glib on: May 26, 2013, 02:22:37 pm
It would be nice to have support for the HT1632 LED matrix panels in a graphics library. Can someone help code the device description for the u8glib library?

Some initial work (along with the appropriate datasheets) has been done here: https://code.google.com/p/u8glib/issues/detail?id=165

Unluckily I lack the proper skills to completely do this myself, I'm posting to raise awareness. I'm pretty sure someone else will also find it interesting. Tips and/or some code help will be extremely helpful.

Thanks!
35  Using Arduino / Programming Questions / Re: Printing fonts on HT1632 LED matrix (bitwise math and PROGMEM help!) on: February 12, 2013, 08:07:15 am
Everything you mentioned works correctly when I'm not using the PROGMEM directive and the pgm_read_byte function (just a plain array).

In other words, everything is fine (work as expected) until I move to the PROGMEM.

EDIT: I think I understand what's going on. I'm using
Code:
pgm_read_byte(font4x6[x])
which is wrong. Changing to
Code:
pgm_read_byte(font4x6 + x)
works. Ahh.
36  Using Arduino / Programming Questions / Re: Printing fonts on HT1632 LED matrix (bitwise math and PROGMEM help!) on: February 12, 2013, 07:38:15 am
The array declaration is at the first post, if that's what you mean!

EDIT: Oops, I meant at the declaration is at the top of the thread, not the file.
37  Using Arduino / Programming Questions / Re: Printing fonts on HT1632 LED matrix (bitwise math help!) on: February 12, 2013, 07:07:45 am
Thanks for all the replies, my problem was easier than I thought when I was creating the post (I blame it on sleep) smiley-twist

I'm stuck on another problem now. I also had this problem in the past and I never solved it. My array is stored in PROGMEM, so I need to use pgm_read_byte to get the data. All I get is garbare, not what I expect and get when not using PROGMEM and pgm_read_byte (aka a simple array).

This is the routine I wrote (I don't use the panel yet). The array definition is at the top of the file.
Code:
void print_char(char c, byte height, byte width) {
  c = c - 32;
  c = c * 6;

  for (int j = 0; j < height; j++) {
    for (int i = 7; i >= 0 ; i--) {
      if ((pgm_read_byte(&font4x6[c + j + 3]) & (1 << i)) != 0) {
        Serial.print("# ");
      }
      else {
        Serial.print("@ ");
      }
    }
    Serial.println("");
  }
}

Thanks for your answers smiley
38  Using Arduino / Programming Questions / Re: Printing fonts on HT1632 LED matrix (bitwise math help!) on: February 11, 2013, 12:07:10 pm
You want to read one bit from a byte value? How about using bitRead()?

I thought of that but I think it's better with bitwise math. The problem is, I can't think of a way to achieve that

Or use the more obtuse, but somehow more satisfying, bitwise operators to mask the bits you don't want, leaving only the one(s) that you do want.  The bitRead() function is easier to understand but make sure that you read the description in the reference to understand exactly which bit you are reading.  ie bit 0 is not the leftmost bit.

That's exactly what I'm looking for, the problem is I can't find anything related on the internet. What bitwise operation should I look for, for example?
39  Using Arduino / Programming Questions / Printing fonts on HT1632 LED matrix (bitwise math and PROGMEM help!) on: February 11, 2013, 08:39:18 am
I'm trying to implement some simple font printing on my HT1632 matrix, but I'm currently stuck at a very basic step of the implementation. I'm using stealing the fonts from the arduino-tvout library. This is how a font definition looks like:

Code:
PROGMEM const unsigned char font4x6[] = {
4,6,32,
//space
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
//!
0b01000000,
0b01000000,
0b01000000,
0b00000000,
0b01000000,
0b00000000,
[...]

My problem now is, how can I extract the bit information for my panel. I'm using two functions to set a LED on or off, how can I get a specific bit from the byte?
40  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: More os x native behaviour on: August 21, 2009, 06:43:27 am
The IDE is open source, you are allowed to make any changes you want. I don't think that's easy to make the IDE run perfectly on all the OSes.
41  Forum 2005-2010 (read only) / Syntax & Programs / Re: Printing and understanding international chars on: November 30, 2010, 06:14:37 am
I think I made some progress. I will try not to mess with file encodings and special compiler parameters.

When you cast a char to an integer, the number represents the character's position on the ASCII table. For example, the sketch below will print:

Quote
C
67

Code:
void setup() {
  Serial.begin(9600);
  
  char latin = 'C';
  
  Serial.println(latin);
  Serial.println((int)latin);
}

void loop() { }

If I change the char to '[ch915]', it prints:

Quote

-108

Why -108? If I make the char unsigned it prints 148. The sketch I want to print Greek chars should work with those numbers (instead of the ISO-8859-7). My questions now are, why does it print a negative number? Is it because its a 8bit unsinged and I declared it as a signed? In what encoding are the chars stored?

Thanks for your answers, you really helped smiley
42  Forum 2005-2010 (read only) / Syntax & Programs / Re: Printing and understanding international chars on: November 29, 2010, 04:05:00 pm
Quote
Open the sketch source file with some HEX editor and check how the char is stored there. It must be the same code that you are using in your program. If it is not, the file is still not in the correct encoding. If there is two or more bytes used for that char, it is still in UTF-8.

You are right. It is stored as CE 93 (two bytes). It should be C1.

Quote
How to change default encoding in Arduino IDE, I don't (yet) know, maybe someone else can help with that. If it is not possible, create some .h file with your string constants with some other editor and include this file in your sketch, but don't open/edit it with IDE.

Can you give a simple example? What do you mean with string constants?

Thanks for your help!
43  Forum 2005-2010 (read only) / Syntax & Programs / Re: Printing and understanding international chars on: November 29, 2010, 03:20:18 pm
This is what I got so far and unluckily it isn't working. I'm trying to make it print the char '[ch915]'.

This is the function:
Code:
void ht1632_putchar_greek(int x, int y, char c)
{
  byte charIndex;

  if (c < 193 || c > 254)
    charIndex = 0;
  else
    charIndex = c - 33;

  for (byte row=0; row<8; row++) {
    byte rowDots = pgm_read_byte_near(&greek[charIndex][row]);
    for (byte col=0; col<6; col++) {
      if (rowDots & (1<<(5-col)))
        ht1632_plot(x+col, y+row, 1);
      else
        ht1632_plot(x+col, y+row, 0);
      }
  }
}

This is the array (just the first 4 chars for now):
Code:
unsigned char PROGMEM greek[4][8] = {
  {
    0x00,    // ________   blank (ascii 32)
    0x00,    // ________
    0x00,    // ________
    0x00,    // ________
    0x00,    // ________
    0x00,    // ________
    0x00,    // ________
    0x00     // ________
  },
  {
    0x00,    // ________   A
    0x1C,    // ___XXX__
    0x22,    // __X___X_
    0x22,    // __X___X_
    0x3E,    // __XXXXX_
    0x22,    // __X___X_
    0x22,    // __X___X_
    0x00     // ________
  },
  {
    0x00,    // ________   B
    0x3C,    // __XXXX__
    0x22,    // __X___X_
    0x3C,    // __XXXX__
    0x22,    // __X___X_
    0x22,    // __X___X_
    0x3C,    // __XXXX__
    0x00     // ________
  },
  {
    0x00,    // ________
    0x3E,    // __XXXXX_
    0x20,    // __X_____
    0x20,    // __X_____
    0x20,    // __X_____
    0x20,    // __X_____
    0x20,    // __X_____
    0x00     // ________
  }
};

EDIT:
I call the function like this:
Code:
ht1632_putchar_greek(0, 0, '[ch915]');
44  Forum 2005-2010 (read only) / Syntax & Programs / Re: Printing and understanding international chars on: November 29, 2010, 02:05:40 pm
Quote
Unicode, if UTF-8 encoding is used, represents eatch character using 1..4 bytes.

http://en.wikipedia.org/wiki/UTF-8

But you could try to use iso-8859-7 charset:
http://czyborra.com/charsets/iso8859.html#ISO-8859-7
It is 8 bits per character and it should suit you well if you don't need to use any other "exotic" language simultaneously.

Nice idea. I'll create an array containing all the ISO-8859-7 chars in that order. But how will the function know that "[ch916]" is C4 and print it?

This is the function I'm talking about.
Code:
//*********************************************************************************************************
/*
 * Copy a character glyph from the myfont data structure to
 * display memory, with its upper left at the given coordinate
 * This is unoptimized and simply uses plot() to draw each dot.
 */
void ht1632_putchar(int x, int y, char c)
{
      // fonts defined for ascii 32 and beyond (index 0 in font array is ascii 32);
      byte charIndex;

      // replace undisplayable characters with blank;
      if (c < 32 || c > 126)
      {
            charIndex      =      0;
      }
      else
      {
            charIndex      =      c - 32;
      }

      // move character definition, pixel by pixel, onto the display;
      // fonts are defined as one byte per row;
      for (byte row=0; row<8; row++)
      {
            byte rowDots      =      pgm_read_byte_near(&myfont[charIndex][row]);
            for (byte col=0; col<6; col++)
            {
                  if (rowDots & (1<<(5-col)))
                        ht1632_plot(x+col, y+row, 1);
                  else
                        ht1632_plot(x+col, y+row, 0);
            }
      }
}

Thanks for your answers!
45  Forum 2005-2010 (read only) / Syntax & Programs / Re: Printing and understanding international chars on: November 29, 2010, 01:48:27 pm
Quote
Hard to say without knowing more about your LED matrix.  If it's something you've built then you can print anything you'd like on it.

Its a matrix based on the Holtek HT1632. The Arduino controls it. Forgot to mention!

Quote
It what way?
It prints garbage characters, as you said.

Quote
The AVR compilier supports eight-bit characters.  Traditionally, the first 127 characters are ASCII.  Using your example as an example, it's up to the reciever to decide how those eight-bits are interpreted.

What I want to do is make the Arduino print Greek characters on the matrix. I have a function that reads the "font" from an array and then print the corresponding character on the display. I want to extend this function and make it print more characters. The array contains the printable ASCII characters.

This is what came into my mind after your reply. I'll make another array containing the Unicode characters and modify the function to use that array when needed. Will that work, considering that Unicode chars use 16bits?

EDIT:
Quote
The serial port of the Arduino can only sent bytes (value 0..255) over the line. The receiving application interpret these byte values - typically as ASCII, however you are free to use another interpretation including Greek characters. The Arduino does not know, it just send bytes.

It's similar to writing a word document, selecting all and change the font to Greek. The (underlying) bytes won't change, but the interpretation and visualization is changed.

Several LCD screens have the option to define your own characterset.  If there are enough free definable chars in the LCD you could define the whole greek alphabet.
If you are sending the data to a PC/Mac, it is up to the receveing app to translate the byte to greek.

Hopes this helps.

Thanks! Yes it helped me clear some things smiley
Pages: 1 2 [3] 4 5 6