1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

(Solved)Again problem with matrix, this time 8x32

Discussion in 'Arduino' started by fezder, Jan 4, 2016.

  1. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,718
    Likes:
    37
    k try 374 again
     
  2. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    Crap, got carried away with other stuff....experimented with home-made etching solution made of vinegar and hydrogen peroxide.....when warmed to about 40'c, man, it's so good stuff to etch pcb's at home! toner transfer is made with acetone, and yeah, I use laser printer. Made breakout board for ESP8266/07 module and TEA5767 fm-module, latter came out much better due better preaparation of PCB and other stuff too. And I use KiCad for design.

    But, I'll try now to come back to this subject, I'm sorry doggy!
     
  3. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    ok, tested that new sketch with both 16 and 8-bit fontmaps, no change. Digits are empty, serial monitor shows same thing as earlier
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland

    DOGGY! Still have that circuit intact, so I gave it shot with SPI. This allows to draw any character from fontmap (fontmap is int because array elements are 16-bit, not 8)
    So, it is possible. Do you see anything that could help further?
    Code (c):

    #include <SPI.h>
    //13=clock
    //11=data
    //10=latch
    //MSB
    int font [125]  =  //numbers stored here, int because of 16-bit size, unsigned char won't work
    { //Position, Character
      //  0B (null) M L K J I H G2, G1 F E D C B A DOT
      0B0001100001111110, // 0  0
      0B0000000000001100, // 1  1
      0B0000000110110110, // 2  2
      0B0000000110011110, // 3  3
      0B0000000111001100, // 4  4
      0B0000000111011010, // 5  5
      0B0000000111111010, // 6  6
      0B0000000000001110, // 7  7
      0B0000000111111110, // 8  8
      0B0000000111011110, // 9  9

      0B0000000000000000, // 10  \n
      0B0000000000000000, // 11
      0B0000000000000000, // 12
      0B0000000000000000, // 13  \r
      0B0000000000000000, // 14  \p
      0B0000000000000000, // 15
      0B0000000000000000, // 16
      0B0000000000000000, // 17
      0B0000000000000000, // 18
      0B0000000000000000, // 19

      0B0000000000000000, // 20
      0B0000000000000000, // 21
      0B0000000000000000, // 22
      0B0000000000000000, // 23
      0B0000000000000000, // 24
      0B0000000000000000, // 25
      0B0000000000000000, // 26
      0B0000000000000000, // 27  /esc
      0B0000000000000000, // 28
      0B0000000000000000, // 29

      0B0000000000000000, // 30
      0B0000000000000000, // 31
      0B0000000000000000, // 32  "space"
      0B0000000000000000, // 33  !
      0B0000000000000000, // 34
      0B0000000000000000, // 35
      0B0000000000000000, // 36
      0B0000000000000000, // 37
      0B0000000000000000, // 38
      0B0000000000000000, // 39

      0B0000000000000000, // 40
      0B0000000000000000, // 41
      0B0000000000000000, // 42
      0B0000000000000000, // 43
      0B0000000000000000, // 44
      0B0000000110000000, // 45  -(minus)
      0B0000000000000000, // 46
      0B0000000000000000, // 47

      0B0001100001111110, // 48  0
      0B0000000000001100, // 49  1
      0B0000000110110110, // 50  2
      0B0000000110011110, // 51  3
      0B0000000111001100, // 52  4
      0B0000000111011010, // 53  5
      0B0000000111111010, // 54  6
      0B0000000000001110, // 55  7
      0B0000000111111110, // 56  8
      0B0000000111011110, // 57  9

      0B0000000000000000, // 58  :
      0B0000000000000000, // 59
      0B0000000000000000, // 60
      0B0000000110010000, // 61  =
      0B0000000000000000, // 62
      0B0000000000000000, // 63
      0B0000000000000000, // 64
      0B0000000111101110, // 65  A
      0B0010010100011110, // 66  0B
      0B0000000001110010, // 67  C
      0B0010010000011110, // 68  D
      0B0000000011110010, // 69  E

      0B0000000011100010, // 70  F
      0B0000000101111010, // 71  G
      0B0000000111101100, // 72  H
      0B0010010000010010, // 73  I
      0B0000000000111100, // 74  J
      0B0100100011100000, // 75  K
      0B0000000001110000, // 76  L
      0B0000101001101100, // 77  M
      0B0100001001101100, // 78  N
      0B0000000001111110, // 79  O

      0B0000000111100110, // 80  P
      0B0100000001111110, // 81  Q
      0B0100000111100110, // 82  R
      0B0000000111011010, // 83  S
      0B0010010000000010, // 84  T
      0B0000000001111100, // 85  U
      0B0001100001100000, // 86  V
      0B0101000001101100, // 87  W
      0B0101101000000000, // 88  X
      0B0000000000000000, // 89  Y

      0B0000000000000000, // 90  Z
      0B0000000001110010, // 91  [
      0B0000000000000000, // 92
      0B0000000000011110, // 93  ]
      0B0000000000000000, // 94
      0B0000000000010000, // 95  _
      0B0000000000000000, // 96
      0B0000000010111110, // 97  a
      0B0000000011111000, // 98  b
      0B0000000010110000, // 99  c

      0B0000000010111100, // 100  d
      0B0000000011110110, // 101  e
      0B0000000000000000, // 102  f
      0B0000000000000000, // 103  g
      0B0000000011101000, // 104  h
      0B0000000000000000, // 105  i
      0B0000000000000000, // 106  j
      0B0000000000000000, // 107  k
      0B0000000000000000, // 108  l
      0B0000000000000000, // 109  m


      0B0000000000000000, // 110  n
      0B0000000010111000, // 111  o
      0B0000000000000000, // 112  p
      0B0000000000000000, // 113  q
      0B0000000000000000, // 114  r
      0B0000000000000000, // 115  s
      0B0000000000000000, // 116  t
      0B0000000000111000, // 117  u
      0B0000000000000000, // 118  v
      0B0000000000000000, // 119  w

      0B0000000000000000, // 120  x
      0B0000000000000000, // 121  y
      0B0000000000000000, // 122  z
      0B0000000000000000, // 123
      0B0000000000000000, // 124
    };



    void setup (void)
    {
      SPI.begin ();
    }

    void loop (void)
    {

      digitalWrite(SS, HIGH);  // SS is pin 10
      SPI.transfer(1);
      SPI.transfer16(font[millis() / 1000 % 10]);
      digitalWrite(SS, LOW);

      digitalWrite(SS, HIGH);  // SS is pin 10
      SPI.transfer(2);
      SPI.transfer16(font[millis() / 10000 % 10]);
      digitalWrite(SS, LOW);


    } // end of loop
     
     
  6. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,964
    Likes:
    1,099
    Fez:
    Indirectly related to your problem. For future reference, take a look at "structs" and "typecasting".
     
  7. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    Thanks Kiss, struct looked like array to me. And as for casting, Never used that, well much at least....
    But, finally, this works! Without SPI, just modifed that earlier skecth, used 16-bit fontmap, I'll attach video, fontmap & code soonish. PHEW...
     
  8. djsfantasi

    djsfantasi Member

    Joined:
    Mar 15, 2011
    Messages:
    161
    Likes:
    21
    Location:
    Metro Boston
    Struct can be considered an array of sorts, but it is much more than that. It's a way of organizing related values of possibly varying types into a single object, for simplicity in management and referencing data.

    One could have many arrays or related values and they could be manipulated as a whole by repeating an operation with a common index. Or in a struct, you can manipulate the values with a single step.
    Some pseudo code. A report is created for salesman commissions based on order of total sales.
    Code (text):
    dim int id[]={0,1,2}
    dim float sales[]={500.00,1000.00,800,00}
    dim string name[]={
    "Don","John","Ron"}
    ...
    // part of source code
    if (sales[i]<sales[i+1{) {
        tmpInt=id[i+1]
        id[i+1]=id[i]
        id[i]=tmpInt
        TmpString=name[id+1]
        name[id+1]=name[i]
        name[i]=tmpString
        TmpFloat=sales[i+1]
        sales[i+1]=sales[i]
        sales[i]=temprecord
        }
     
    Now using a struct (please remember this is pseudo code. I'm typing on my phone in a cabin in the woods. My syntax will be off)
    Code (text):
    dim struct salesrecord {
    int id
    float sales
    string name
    }
    dim salesrecord salesman[]
    dim salesrecord temprecord
    ...
    // part of source code
    If (salesman.sales[i]<salesman.sales[i+1]){
         temprecord=salesman[i+1]
         salesman[i+1]=salesman[i]
         salesman[i]=temprecord
        }
     
    • Informative Informative x 1
  9. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    here we go, 16-bit fontmap:
    Code (c):

    #include "FontMap14Segment.h"

    int dataPin = 2; // ic: 14, ser_in Define which pins will be used for the Shift Register control
    int latchPin = 3; // ic:12 silkscreen numbers!
    int clockPin = 4;


    unsigned char displayPointer = 0; // for interrupt use...
    int buffer1[2]; //16 bits for each digit
    int backbuffer[2]; // Spare screen for drawing on

    int power[16] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768};

    ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine, called every now and then, outside of loop
    {
      if (TIFR2) // Make sure its the timer interrupt.
      {
      setcolumn(displayPointer);  //column scanning
      setdata(buffer1[displayPointer]);
      PORTD = (1 << PORTD3);
      PORTD = (0 << PORTD3);

      //digitalWrite(latchPin ,HIGH);
      //digitalWrite(latchPin , LOW ); // STORECLOCK

      if (++displayPointer == 2)  //4 because there are two digits, each need 2x8 bits
      { displayPointer = 0;
      } // 32 LED row sections in total
      }
      TIFR2 = 0; // Clear timer 2 interrupt flag
    }



    void setcolumn(int col)  //loop that takes care of column scanning
    {
      signed char pos;
      for (pos = 16; pos > -1; pos--) //was pos=32, but again, only 4 columns now so pos=4
      {
      if (col == pos)
      {
      PORTD = (0 << PORTD2);  //digitalWrite(dataPin ,HIGH);  //swapping these reversed unlit-lit digits
      }
      else
      {
      PORTD = (1 << PORTD2);  //digitalWrite(dataPin ,LOW);
      }
      digitalWrite(clockPin , HIGH);
      digitalWrite(clockPin , LOW);
      }
    }



    void setdata(int dat) {
      int pos;
      for (pos = 0; pos < 16; pos++)
      {
      if (dat &  32768)  //these dat were 128, but changed them to 16 as 16=128/8
      {
      dat -= 32768;
      PORTD = (1 << PORTD2);  //digitalWrite(dataPin ,HIGH);  //swapping these caused whole screen to be reversed for lit-unlit segments
      }
      else
      {
      PORTD = (0 << PORTD2);  //digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
      }
      dat = dat * 2;
      digitalWrite(clockPin , HIGH);
      digitalWrite(clockPin , LOW);
      }
    }



    void clr() //clear
    {
      int addr;
      for (addr = 0; addr < 2; addr++)  // Empty display buffer, reduced from 32 to 4
      backbuffer[addr] = 0;
    }




    void Blit()  //transfers data between display buffer to screen buffer
    {
      int addr = 0;
      noInterrupts();  // disable all interrupts during setup
      for (addr = 0; addr < 2; addr ++)  //here also changed 32 to 4
      {
      buffer1[addr] = backbuffer[addr];  // put all data from display buffer to screen buffer
      }
      interrupts();  // enable all interrupts
    }


    void pixel(signed char x, signed char y, int cond)
    {
      int pix, msk;
      if (x < 0 || y < 0) return;  // outside drawing limits negative
      if (x > 1 || y > 15) return;  // outside drawing limits positive
      pix = power[y];
      msk = backbuffer[x];  // get exsisting data
      if (cond == 2)
      pix ^= msk;  // XOR data to screen
      if (cond == 1)
      {
      pix = ~pix;
      pix &= msk;  // AND data to screen
      }
      if (cond == 0)
      pix |= msk;  // OR data to screen
      backbuffer[x] = pix;  // apply changes
    }



    void charput(int ch, signed char x, signed char y)
    {
      signed char  y1;
      int disp;
      int disp2;

      disp = font[ch]; //look data from fontmap,
      for (y1 = 15; y1 > 0; y1--)  // eight pixels
      {
      disp2 = disp & power[y1];
      if (disp2 > 0)
      {
      pixel(x , y + y1, 0); // OR the pixel to the display buffer
      }
      }



    }



    void strput(const char* ch, signed char x, signed char y)
    {
      int addr;
      while (*ch )
      {
      charput(*ch++, x, y);  // write a string to the display buffer
      x += 1;
      }
    }


    void setup() //setup runs once
    {
      Serial.begin(9600);

      noInterrupts();  // disable all interrupts during setup
      DDRD = DDRD | B11111100;  //port registers used to set pin directions
      TCCR1A = 0;
      TCCR1B = 0;
      TCNT1 = 0;
      OCR1A = 260;  // compare match register value, was 31 for matrix (1920hz= 60hzx*32) but for now there's only 4 columns so: 4*60hz=240hz; 16mhz/256/240=260
      TCCR1B |= (1 << WGM12);  // CTC mode, free-running, clear on match
      TCCR1B |= (0 << CS10);  // 256 prescaler
      TCCR1B |= (0 << CS11);  // 256 prescaler
      TCCR1B |= (1 << CS12);  // 256 prescaler
      TIMSK1 |= (1 << OCIE1A);  // enable timer compare interrupt
      interrupts();  // enable all interrupts

    } // End main



    void loop() //just sitting here
    {
      for (int i = 3; i > -30; i--)
      {
      clr();
      strput("HACKLAB__MIKKELI", i, 0);
      Blit();
      delay(500);
      }
    }

     
    Youtube didn't like me for uploading, gotta figure out that later but here's video from my FB, should work, it's public:
     

    Attached Files:

  10. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    Only when trying to place more than 2 digits and using strput, or shifting x-position, doesn't work as intended, characters overlap. Odd.
     
  11. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,718
    Likes:
    37
    check it out, found an arduino debugger that plugs in to my visual studio, using atmel studio!!
    way better then the default arduino compiler, and worth the purchase price!!! also has 30day free trial...
    thought i should mention since debuggers helps alot when trying to find these little problems.... also hence the lack of response as i can only guess the problem

    http://www.visualmicro.com/page/Debugging-for-Arduino.aspx
     
  12. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    Thanks mate, I'll try it! :)
     
  13. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    Doggy, problem was putting too big values for arrays, tested wtih 128 matrises (1024 columns....) and text is readable, should get bigger display to see how it really behaves. Oh, and refresh rate is also bit off, and using teensy now.
     
  14. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    Found also that if one increases size of matrix, string can't be huge then....
     
  15. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    Aha, found the bug when I had to increase column sizes, this line caused malfuntions:
    Code (c):

      int pos;
      for (pos = columns; pos > -1; pos--)
      {
     
    I made tweak to code that complier takes care of calculating array sizes etc, and column integer is part of that (columns=matrises*8)
    But, I mitstakenly placed UNSIGNED char (values from 0-255) and this caused crash since singed char is too small and unsigned won't accept negative numbers, so had to place int instead.
    With pro mini, 22 matrises can be controlled, then ISR will be too fast for CPU speed (to prevent flicker, also RAM gets low, 75% used with 22 matrises). It's unclear for me how prescaler affect, only that bigger prescale=slower speed for ISR, if interval is kept same?

    Of course, to counter RAM, I could use FLASH, but it's complicated for me to use it....
     
    Last edited: Jun 17, 2016
  16. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,718
    Likes:
    37
    yah , just part of the fun, these little things happen all the time, in fact i recently just ran in to a problem where the size of a double changed across programming platforms, which made it tricky for decoding serial terminals.

    prescaler takes the clock frequency and divides it , so each tick takes longer.... plus there is OCR1A (i think its that one) which counts how many ticks from the "prescaled clock" before the interrupt is flagged

    75% is lots! i noticed the fontmap took alot of space too, some of the things I would do is cut back on global variables if we can, trim fontmap & others of unused variables (not the best idea though for fontmap), if you still have lots of program memory available.. another trick i had was to change the fontmap for example to if statements(similar to a trick of using goto, if and more flag variables when i ran out of stack space)....
    one time i was shown here how to convert program space to variable space using pointers, although it worked for my code i never understood it enough to be able to learn from, not too sure about other tricks or whats best, but im sure someone else will....
     
  17. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    Any bit towards perfect code is welcome :) fontmap took about half of ram IIRC....1008 bytes!
     
  18. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,718
    Likes:
    37
    • Like Like x 1
  19. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,718
    Likes:
    37
    Hey Fezd,
    I found the code to put your fontmap in to program memory instead of sram, as mentioned earlier:

    const unsigned char sample[] PROGMEM = {1,2,3,4};


    adding this part will free the memory : PROGMEM
    you also need to ensure that the variable is const
     
  20. fezder

    fezder Well-Known Member

    Joined:
    Dec 11, 2011
    Messages:
    1,665
    Likes:
    100
    Location:
    Mikkeli, Finland
    Thanks doggy! Say, you wouldn't have any idea how to approach 8x8x8 cube? I have one right here, only needs code....."only" lol :D
    If you want to join, I have it hooked up as I hooked matrix, in a way; 9 registers total daisy chained, last in line commands layers, and first 8 columns and rows of each layer. I wonder should I design 2d-matrix for this?
     
  21. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,718
    Likes:
    37
    is definitely similar to other matrix we have been using,

    is it mono color?
    and how is it wired, anodes/cathodes?
     

Share This Page