Dangerous Prototypes

Other projects => Past projects => Web platform => Topic started by: rvbcrs on April 23, 2010, 07:01:58 pm

Title: Sure Electronics Dot Matrix Displays
Post by: rvbcrs on April 23, 2010, 07:01:58 pm
Hi Ian, All!

I have recently purchased my first Arduino clone the Seeeduino from Seeed! Great device, it also gave me a change to test out the Dot Matrix Displays from Sure Electronics I had laying around. There are now more and more Libraries beeing made available for these devices, it's all for an arduino.

How great would it be to use these displays in combination with the Web Platform! Only I have no idea how to port / use this code on the Web Platform.

Here is a youtube movie I made from the Displays:
http://www.youtube.com/watch?v=mgD9x1YAYFM (http://http://www.youtube.com/watch?v=mgD9x1YAYFM)

Here is the link to another cool project with the panels!:
http://www.atomsandelectrons.com/blog/post/Pushing-Pixels.aspx (http://http://www.atomsandelectrons.com/blog/post/Pushing-Pixels.aspx)

Hope someone can help!

Thanks,

RvBCrS
Title: Re: Sure Electronics Dot Matrix Displays
Post by: rvbcrs on April 24, 2010, 11:51:16 am
Ok this is what I did up until now, it's not working, because I'm missing something here ;)

I Add this to the HardwareProfile.h:
Code: [Select]
//MATRIX
#define CLK PORTAbits.RA9
#define DAT PORTCbits.RC3
#define CS1  PORTCbits.RC4

Then I added a file with all the matrices code DotMatrix.c:
Code: [Select]
void init_command(unsigned int command_data); //send commad data to HT1632 
void set2416(void);                      //initialize HT1632
void MCU_Data_2416(unsigned char *p);   //send 16 bits data to HT1632 once       
void MCU_Address_2416(unsigned char address);  //send address to 1632's RAM
void senddata1(void);   //send data to HT1632 to display information
void delay(void);

unsigned char Array1[128]={
                        0x11,0x10,0x01,0x81,0x10,0x01,0x81,0x81,
                        0x22,0x20,0x02,0x42,0x20,0x02,0x42,0x20,
                        0x33,0x30,0x03,0xc3,0x30,0x03,0xc3,0x30,
                        0x44,0x40,0x04,0x24,0x40,0x04,0x24,0x40,
                        0x55,0x50,0x05,0xa5,0x50,0x05,0xa5,0x50,
                        0x66,0x60,0x06,0x66,0x60,0x06,0x66,0x60,
                        0x77,0x70,0x07,0xe7,0x70,0x07,0xe7,0x70,
                        0x88,0x80,0x08,0x18,0x80,0x08,0x18,0x80,
                       
                        0x88,0x80,0x08,0x18,0x80,0x08,0x18,0x80,
                        0x77,0x70,0x07,0xe7,0x70,0x07,0xe7,0x70,
                        0x66,0x60,0x06,0x66,0x60,0x06,0x66,0x60,
                        0x55,0x50,0x05,0xa5,0x50,0x05,0xa5,0x50,
                        0x44,0x40,0x04,0x24,0x40,0x04,0x24,0x40,
                        0x33,0x30,0x03,0xc3,0x30,0x03,0xc3,0x30,
                        0x22,0x20,0x02,0x42,0x20,0x02,0x42,0x20,
                        0x11,0x10,0x01,0x81,0x10,0x01,0x81,0x10
                        };                       

unsigned char temp1,row;//temp1 : which bit to send
                        //row: row of byte_matrix

void delay(void)
{
   unsigned char i,j;
   for(i=0;i<200;i++)
   {
      j++;
   }
}

void init_command(unsigned int command_data)
{
   unsigned int i,j;
   command_data=command_data&0xfff;
   command_data=command_data<<4;
   CS1=1;
   CS1=0;

     for(i=0;i<12;i++)
   {
      CLK=0;
      j=command_data&0x8000;
      command_data=command_data<<1;
      j=j>>15;
      DAT=j;
      CLK=1;
   }
   CS1=1;
}

void set2416(void)
{
   //sys en
   init_command(0b100000000010);
   //led on
   init_command(0b100000000110);
   //blink on
//   init_command(0b100000010010);
   //master mode
   init_command(0b100000101110);
   //RC
   init_command(0b100000110110);
   //commons option
   init_command(0b100001011110);
   //pwm duty
   init_command(0b100101111110);
}


void MCU_Data_2416(unsigned char *p)
{
   unsigned char i,k;           
   
    for(i=0 ; i<8 ; i++)
   {
      CLK= 0;            //clk = 0 for data ready
       
       k= *(p+i*8+row)&temp1;
       if(k==0)
           DAT=0;
        else   
         DAT=1;
       
        CLK=1;             //clk = 1 for data write into 2416
   }
    for(i=0 ; i<8 ; i++)
   {
      CLK= 0;            //clk = 0 for data ready
      k=*(p+i*8+row+64)&temp1;
       if(k==0)
           DAT=0;
        else   
         DAT=1;
       
        CLK=1;             //clk = 1 for data write into 2416
   }
    temp1=temp1>>1;
                       
}

void MCU_Address_2416(unsigned char address)
{
   unsigned char i,temp;
     
   temp = 0x40;                     //address has 7 bits. MSB fisrt
   
   for(i=0;i<7;i++)
   {
      CLK= 0;             //clk = 0 for data ready
         if((temp & address) == 0)   
         DAT= 0;
      else           
         DAT= 1;
      CLK= 1;            //clk = 1 for data write into 1632
      temp >>= 1;
   }
}

void senddata1(void)
{
   unsigned char i,pos,addr;

   
     CS1=1;
     delay();
     CS1=0;
     delay();

     CLK=0;
     DAT=1;
     CLK=1;


     CLK=0;
     DAT=0;
     CLK=1;


     CLK=0;
     DAT=1;
     CLK=1;
     
     temp1=0x80;
     MCU_Address_2416(0x00);
     for(row=0;row<3;row++)
      {
         for(i=0;i<8;i++)
         { 
            MCU_Data_2416(Array1);
            if(temp1==0x00) temp1=0x80;
         }
      }
     delay();
     CS1=1;
}

Next in the main.c InitHardware(void):
Code: [Select]
// Matrix Test Config! 
TRISAbits.TRISA9=0;
TRISCbits.TRISC3=0;
TRISCbits.TRISC4=0;

In main(void) methode I added:
Code: [Select]
set2416(); 
 delay();

And in the while(1){//never ending loop:
Code: [Select]
{senddata1();} // Matrix Test

That's it, I must be forgetting something, or maybe it's not going to work at all because of the speed of the MCU or something, I hope you guys can give me a push in the right direction here..

Thanks!
Title: Re: Sure Electronics Dot Matrix Displays
Post by: rsdio on April 24, 2010, 02:16:24 pm
Looks like you're trying to bit bang raw I/O ports on a fancy processor that already has hardware support for protocols like I2C and SPI. There are a few problems with your approach. First of all, your code makes absolutely no attempt to control the timing of the clock and data transitions - only the sequence. Second of all, your bit manipulation is very inefficient. Also, creating a delay by spinning in a for () loop is the worst possible example of firmware coding.

Your best bet is to download the dsPIC33FJ128GP204 data sheet - a must for any firmware development - and learn all that this chip can do. The Web Platform was designed to make the existing hardware support for SPI and I2C available on the I/O pins. All you need to do is find the compatible peripheral in the dsPIC and set it up for your dot matrix display. You set the appropriate clock rates and load the peripheral registers with the commands, and then the hardware takes care of the timing of individual bits while your firmware is free to deal with other things. When the serial word is complete, you can either respond to an interrupt if you've enabled that, or poll for the 'done' bit, and then move on to the next command word.

P.S. What chip is on the Sure Electronics dot matrix display? You will also need the data sheet for that specific part so that you know how to set the dsPIC port into a compatible mode.
Title: Re: Sure Electronics Dot Matrix Displays
Post by: rvbcrs on April 25, 2010, 12:40:55 am
Wow, thanks rsdio for your reply. The problem is that I do not really have a good idea where to start, the chip on the display is the HT1632. I really like to use the library that is available here: http://milesburton.com/index.php/Arduino_&_the_Sure_2416_Information_Display (http://http://milesburton.com/index.php/Arduino_&_the_Sure_2416_Information_Display) It is all code for AVR chips, and I have no clue if it is possible to port it to PIC code.
Title: Re: Sure Electronics Dot Matrix Displays
Post by: rsdio on April 25, 2010, 01:24:04 am
I must be cursed with the yoke of the electrical engineer: I can't help but want to learn how everything works before I start coding. Well, with the exception of something like OpenGL, where I don't really feel the need to learn the GPU assembly before doing some 3D. The good news is that when something goes wrong, you're prepared to figure it out if you have the hardware background. The bad news is that the ramp up is tough.

Anyway, there's basically no hope of reusing the Arduino library without some hardware understanding. It would be like compiling a Mac OS X device driver on Windows. Following the link you gave, I see a Troubleshooting section which says:
Quote
If you are using any MCU besides the AtMega328 you may need to change the "bitBlast" method of MatrixDisplay.cpp. Change the called function to digitalWrite which takes advantage of the inbuild port selection/write
My worry is that I've never heard of using C++ for PIC, so I don't even know if the compiler can handle anything more than C. Maybe the dsPIC compiler supports C++ and I never noticed.

By the way, I could be wrong about the dsPIC having hardware support for this serial display chip. It appears from the documentation that I found on these HT1632 boards that there is a chip select, write clock, read clock, and data. That's not SPI, because SPI has two data lines and one clock. It's also not I2C, which only has one clock and one data. If you're willing to use the display in write-only mode, then you could use the I2C functions of the dsPIC. But you're probably going to want to read the board as well.

Without getting into the details, I will make a broad comment. You can assign the chip select to a dsPIC port pin and bit bang it manually. That would be fine. But I recommend that you use the serial peripherals on the dsPIC to run the clock and data. The key is in the data sheets for the dsPIC and the manual for the HT1632 which shows timing diagrams.
Title: Re: Sure Electronics Dot Matrix Displays
Post by: rvbcrs on April 25, 2010, 01:54:22 am
Unfortunatly I'm not an electrical engineer by far! I like electronics and even more I like led's ;) The code I posted earlier is code from the manufacturer of the displays (Sure Electronics) They don't really provided much info for these displays, but thanks to the guys at the arduino forums I could finally use the displays. But the final goal (for me) was always to use them in combination with the Web Platform, I'm just a big sucker for big led displays controlled over the intenernet ;)

Anyway, I don't think it is possible to wright C++ code for the PIC Mcu's so I guess the only thing I have is the code from the manufacturer, and the fact that there seems to be more people out there who succeeded in interfacing the displays with a PIC MCU. http://pasanmicroprojects.wordpress.com/2010/02/18/ht1632-successfully-interfaced-with-pic-mcu/ (http://http://pasanmicroprojects.wordpress.com/2010/02/18/ht1632-successfully-interfaced-with-pic-mcu/)

He writes on his blog:
Quote
It can be driven by SPI like interface. It can be easy interfaced to any microcontrollers.

It doesn't say clearly it has a SPI interface, but..
Title: Re: Sure Electronics Dot Matrix Displays
Post by: rsdio on April 25, 2010, 03:09:02 am
Shame on Sure Electronics for distributing such awful code. Perhaps they just assemble the boards. I'd like to know more about the HT1632 chip and confirm who manufactures it, especially whether there is a separate data sheet for the chip that isn't specific to this one board. I only found one document for the HT1632 board, and the one odd thing I noticed is that the data line is bidirectional, but there are separate clocks. That doesn't seem to match SPI, I2C, or any UART that I know of. Let's look at each variation:

SPI generally has 4 wires: SCK (master Serial Clock), MISO (Master Input Slave Output) data, MOSI (Master Output Slave Input) data, and CS (Chip Select).  Chip Select allows more than one device on the same bus, but you need a separate CS for each device. It is notable that each wire has only one circuit driving the signal, with the other end listening. This makes it difficult to connect the HT1632 to SPI, since SPI keeps data separated so that each direction is on a separate pin. You can't just ties those lines together for SPI operation because the MOSI circuit would fight with the HT1632 circuit - two outputs on one line is bad. So, while it might be fair to say the HT1632 is "like" SPI, especially if you are bit-banging, but it isn't directly compatible at the hardware electronics level. I suppose it's remotely possible to do with two SPI ports, one in master mode and one in slave mode (which would produce separate clocks), but you're still left with two devices driving the data line at the same time, and that's a tough one to solve.

I2C only has a single clock, so I don't know how you would separate out a write clock and read clock as needed by the HT1632. With additional hardware - a 1-to-2 demultiplexer - you could take the I2C clock and connect it to two HT1632 clocks such that only one is active at a time. That's probably too much trouble since it requires glue logic, and I'm not even sure it would work without testing.

UART peripherals are more flexible, but they're generally asynchronous, meaning there is no clock on its own line. Also, a UART generally keeps TX (transmit) and RX (receive) separate, which still is not compatible with the HT1632. The PIC usually has a EUSART (Enhanced Universal Synchronous/Asynchronous Receiver Transmitter), and it might be possible to get it working with the CS/WR/RD/DATA hardware on the display board. I think better terms would be CS/WCLK/RCLK/DATA, but the HT1632 is marked with just WR/RD.

Bottom line is that I see few options:

1) Improve the timing of the bit-banging code, which would require almost completely rewriting it, and hope that it doesn't waste too much of the dsPIC power.

2) Investigate the UART for synchronous support. Note that while writing this I decided to scan the dsPIC data sheet and see that it has a UART, not a USART or EUSART, so you're flat out of luck.

3) Give up on reading the board and use SPI master mode. Connect an I/O pin to CS. Leave RD (RCLK) unconnected (better yet, use a pull-up if there isn't one on the HT1632 board already). Then connect CLK to WR (WCLK) and MOSI to DATA. So in the end, I guess the HT1532 is SPI-like if you don't want to use the full features of the board.
Title: Re: Sure Electronics Dot Matrix Displays
Post by: rvbcrs on April 25, 2010, 12:16:55 pm
Hi rsdio, I think this is really all going above my head, I understand some of what your saying, but go implement it is a whole other thing for me ;)

The chip is from HOLTEK, I think you found out already, but just to be sure. Here is the site with info about the chip: http://www.holtek.com/English/docum/consumer/1632.htm (http://http://www.holtek.com/English/docum/consumer/1632.htm)
And here is de datasheet: http://www.holtek.com/pdf/consumer/1632v120.pdf (http://http://www.holtek.com/pdf/consumer/1632v120.pdf)

I guess I have to stick with the arduino for now until some more electrical gifted person figures out how to get it to work with the WebPlatform ;)
Title: Re: Sure Electronics Dot Matrix Displays
Post by: rsdio on April 26, 2010, 08:39:40 am
Looks like I really did come into the Web Platform discussion a little late. I happened to click on "Bus Pirate" as a key word on the site, and came up with the following entry:

http://dangerousprototypes.com/2010/01/ ... #more-2797 (http://dangerousprototypes.com/2010/01/18/demo-sure-led-matrix/#more-2797)

This article mentions that the Bus Pirate was used to get things working, and then the demo was moved over to the web platform. I couldn't find anything on using this board with the web platform, but the articles does say "more on that later," so perhaps it hasn't been written up yet.

Maybe you can pick up where this article left off, or maybe you can ask for more details on how it was moved to the web platform.
Title: Re: Sure Electronics Dot Matrix Displays
Post by: ian on April 27, 2010, 01:58:31 pm
Hey guys, I'm getting here late. I started Twitter scroller with these boards based on the tweet-tree code, but didn't get around to finishing it. Can you upload your source? I'll take a look at it.

The SURE boards are a mess (documentation wise), and the command set is just silly. The timing isn't too important, but they do have to be interfaced at 5volts (that means pull-up resistors on 5volt tolerant pins with high-impedance outputs, see the Bus Pirate demo).
Title: Re: Sure Electronics Dot Matrix Displays
Post by: rvbcrs on April 27, 2010, 02:55:30 pm
Thanks Ian! There are more and more people discovering those Sure Electronics screens, I have found various code samples, but most of them are for Arduino like systems. I have attached 4 files. The SourceSample.txt is from Sure Electronics. The ht1632_write_Commands.h, ht1632_Commands and Source file.txt are from: http://pasanmicroprojects.wordpress.com/2010/02/18/ht1632-successfully-interfaced-with-pic-mcu/ (http://http://pasanmicroprojects.wordpress.com/2010/02/18/ht1632-successfully-interfaced-with-pic-mcu/) But is written in MikroC.

Can't wait Ian, oh by the way, we both have the Sure Electronics 24x16 boards, but I just ordered 10 8x32 displays :) so if there is anyway you could support thos too that would be supurb! ;)

Thanks,

RvBCrS
Title: Re: Sure Electronics Dot Matrix Displays
Post by: ian on April 27, 2010, 03:24:52 pm
Is it possible to .zip up the project you started for the web platform? I thought it looked like you had started some work on an MPLAB project already.

Did you see this? I think it is helpful for scrolling and stuff:
http://www.atomsandelectrons.com/blog/p ... ixels.aspx (http://www.atomsandelectrons.com/blog/post/Pushing-Pixels.aspx)
Title: Re: Sure Electronics Dot Matrix Displays
Post by: rvbcrs on April 27, 2010, 03:43:27 pm
I was indeed just begun, I have no idea if it makes any sense what I have done, but attached are the 2 files I changed in the WebPLatform firmware.

( ! ) Fatal error: Uncaught exception 'Elk_Exception' with message 'Please try again. If you come back to this error screen, report the error to an administrator.' in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
( ! ) Elk_Exception: Please try again. If you come back to this error screen, report the error to an administrator. in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
Call Stack
#TimeMemoryFunctionLocation
10.01142114800session_write_close ( )...(null):0
20.01172246376ElkArte\sources\subs\SessionHandler\DatabaseHandler->write( )...(null):0
30.01172247152Database_MySQL->query( ).../DatabaseHandler.php:119
40.05652385872Database_MySQL->error( ).../Db-mysql.class.php:273