Close

Super Stumped! Helps? :D

A project log for Stylin' safety jacket.

I always feel like jackets needed more blinky sh*t. Now dreams become reality.

scissorfeindScissorfeind 01/14/2015 at 06:012 Comments

Programming is hard for me, but I wanted to wait until after the contest to ask for help. For one piece of the jacket I wanted to create a set of modular matrix displays, each with with their own controller board and linked together by a ribbon cables. To the back of this I will add some kind of sealant and then a piece of Velcro to secure it to the jacket. I feel that this makes each display easy to adhere, remove and replace should one break. Please see my circuit below, presently it is built around parts I removed from various thrifted electronics.

Note: Now that the contest is over I am considering breaking my own rule of using only free parts or things had at a thrift store. As you will see the way I am trying to organize the data is esoteric at best, and this is due to the way I have four displays spread across three shift registers, as opposed to giving each display its own shift register which would make coding much simpler. This is solely because I only had 3.

I would like to create a system of stored character bit maps which can be used to make different words and controlled by a serial text string of 8 characters.. Right now I plan to have this string act as instructions for both the character on each Display and its position in a grouping of 8.This string will be processed by a separate function which will load the character map into the appropriate place in a String element, chopped and then shiftOut()'d. This String element would have 16 bits, the first 12 being each anode (plus 4 extra, presently unused) and the final 8 'activating' each of the 7 rows of cathodes plus 1 extra unused. I am planning on having each character map made of four frames due to the nature of the common cathodes of my displays, I feel this is the least amount of frames needed to display more complex letters like Q. I have seen code which lights up each pixel in a bit map individually, however that was with many fewer pixels. All four displays comes to 140 pixels controlled by 20 anodes, one for each column, and 7 common cathodes, one for each row.

This is a pile of very rough mock ups for code which I barely understand. If anyone has any pointers about my overall approach or individual coding techniques, I am welcoming all criticism.

Here is the code I am trying to use to calculate pre made character bit maps ( is that what you call them? ) into shiftable data. Right here I am just sending the data out to the serial monitor so I can play with the concept.

String allOff = String(0b00000000);
String allOn  = String(0b11111111);
String halfOn  = String(0b10101010);
//String arrayFun[4]  = { String(0b10101010), String(0b11111111), String(0b10101010), String(0b00000000) };
String playVal  ;


int ledPin = 13;

byte rowData[4];
byte colData[4];

byte *charframe1Name[7] = {
} 
;

byte charAf1[7] = {
  B10000000,
  B00000000,
  B11000000,
  B00100000,
  B10010000,
  B00001000,
  B10000000 
};

byte charAf2[7] = {
  B01001000,
  B00000000,
  B00001000,
  B00000000,
  B01001000,
  B00000000,
  B01011000 
};

byte charAf3[7] = {
  B00001000,
  B00001000,
  B00001000,
  B00001000,
  B00001000,
  B00000000,
  B00000000 
};

byte charAf4[7] = {
  B00000000,
  B00000000,
  B11110000,
  B11110000,
  B11110000,
  B11110000,
  B11110000 
};

void setup() {
  Serial.begin(9600);
  Serial.print(F("Setup"));
  delay(100);
  pinMode(ledPin, OUTPUT); 
}





void loop() {
  while(!Serial.available()) {

    /* I want this part to eventually shift the array elements into a string
    for(int i = 0; i < 4; i++) {
     
     digitalWrite(ledPin, HIGH);
     Serial.print(F("playVal : "));
     Serial.println(playVal.toInt(), DEC);
     //int valJar = playVal.toInt();
     //Serial.print(F("valJar : "));
     //Serial.println(valJar, BIN);
     playVal += arrayFun[i];
     playVal += String("*");
     Serial.print(F("allOn : "));
     Serial.println(allOn.toInt(), BIN);
     Serial.print(F("i : "));
     Serial.println(i);
     
     Serial.print(F("length : "));
     Serial.println(playVal.length());
     
     delay(500); 
     digitalWrite(ledPin, LOW);
     delay(500);
     }
     */
   
    Serial.println(F("LOOP"));
    calculateString(charAf1, 0 );
    calculateString(charAf2, 1 );
    calculateString(charAf3, 2 );
    calculateString(charAf4, 3 );
    //Serial.println(String(charCols));
    delay(10000);

  }
}
//function to convert the character frame bytes into a string
byte calculateString(byte* charframe1Name, byte chardataElem){

  Serial.println(F("calc"));


  //check if row is used in frame bitmap and save off or on into
  for (int y = 0; y < 7; y++) 
  { 

    if (charframe1Name[y] > 1)
    {
      bitWrite(rowData[chardataElem], y, 1) ;///  write cathode patterns into rowData array as bytes
    }
    else
    {
      bitWrite(rowData[chardataElem], y, 0) ;
    }
  }

  //check which columns are used in frame bitmap by ORing all lines together
  for (int u = 0; u < 7; u++)
  {
    colData[chardataElem] |= charframe1Name[u];
  }


/*really not sure about this, need to do more research.

union charMaps
{
  
  rowData[];
  colData[];
}
*/

//print out the row and column data.
  Serial.print(F("Char Data Array Element Number: Binary - "));
  Serial.println(chardataElem);
  Serial.print(F("Row Data Array Element Value - "));
  Serial.print(rowData[chardataElem], BIN);
  Serial.print(F(" - Decimal - "));
  Serial.println(rowData[chardataElem], DEC);
  Serial.print(F("Column Data Array Element Value - "));
  Serial.print(colData[chardataElem], BIN);
  Serial.print(F(" - Decimal - "));
  Serial.println(colData[chardataElem], DEC);
  //compare rows among
  //}

 // calculate how many different cathode patterns are used 
   //write into
   for (int z = 0; z < 5; z++)
   {
   if (rowData[z+1] == rowData[z])
   {
   rowData[z] = rowData[z+1];
   }
   }
   
}






Here is the code I am using to shift the data out to the displays so far. Note there are inconsistencies between this and the code above, they are not unified and I

think i broke this text editor..?

have

nt

whats happening!

figured if I should save the rendered "shiftable bits" into array elements or a string yet. In my mind it will be faster to just shift out array elements populated by a processing function rather than slice them out of a String. Also this code refers to another tab in the Arduino IDE where I am just keeping the character bit maps.
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595s
int dataPin = 11;//cathodes


int ledPin = 13;

byte frameOne[3] ;
byte frameTwo[3] ;
byte frameThree[3] ;
byte frameFour[3] ;

//byte 1: cathodes(7s)
//byte 2: anodes(5s) Disp 4 and extra
//byte 3: anodes(5s) Disp 2, 3 and 4
//byte 4: anodes(5s) Disp 1 and 2

String frame1String = String(0b00000000000000000000000000000000);
String frame2String = String(0b00000000000000000000000000000000);

String frame3String = String(0b00000000000000000000000000000000);
String frame4String = String(0b00000000000000000000000000000000);

String frame5String = String(0b00000000000000000000000000000000);
String frame6String = String(0b00000000000000000000000000000000);

String frame17tring = String(0b00000000000000000000000000000000);
String frame28tring = String(0b00000000000000000000000000000000);



int sensorPin = A7;    // select the input pin for the potentiometer

int sensorValue = 0;  // variable to store the value coming from the sensor


void setup() {
  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);

  pinMode(dataPin, OUTPUT);


  pinMode(ledPin, OUTPUT);

  Serial.begin(9600);
}

void loop() {
  while(!Serial.available())
  {
    digitalWrite(ledPin, LOW);

    for (int i=0 ; i < 8 ; i++){
      digitalWrite(ledPin, LOW);
      sensorValue = analogRead(sensorPin);




      //frame 1
      digitalWrite(latchPin, LOW);
      // shift out the bits for frame one:
      shiftOut(dataPin, clockPin, LSBFIRST,  frameOne[1]);  //byte 1: cathodes(7s)
      shiftOut(dataPin, clockPin, LSBFIRST,  frameOne[2]); //byte 2: anodes(5s) Disp 4 and extra
      shiftOut(dataPin, clockPin, LSBFIRST,  frameOne[3]);  //byte 3: anodes(5s) Disp 2, 3 and 4
      shiftOut(dataPin, clockPin, LSBFIRST,  frameOne[4]);  //byte 4: anodes(5s) Disp 1 and 2

      //take the latch pin high so the LEDs will light up:
      digitalWrite(latchPin, HIGH);

      // pause before showing next frame:
      delay(1);
      
      //frame 2
      digitalWrite(latchPin, LOW);
      // shift out the bits for frame two:
      shiftOut(dataPin, clockPin, LSBFIRST,  frameTwo[1]);  //byte 1: cathodes(7s)
      shiftOut(dataPin, clockPin, LSBFIRST,  frameTwo[2]); //byte 2: anodes(5s) Disp 4 and extra
      shiftOut(dataPin, clockPin, LSBFIRST,  frameTwo[3]); //byte 3: anodes(5s) Disp 2, 3 and 4
      shiftOut(dataPin, clockPin, LSBFIRST,  frameTwo[4]); //byte 4: anodes(5s) Disp 1 and 2

      //take the latch pin high so the LEDs will light up:
      digitalWrite(latchPin, HIGH);
      delay(1);
      
      //frame 3
      digitalWrite(latchPin, LOW);
      // shift out the bits for frame two:
      shiftOut(dataPin, clockPin, LSBFIRST,  frameThree[1]);  //byte 1: cathodes(7s)
      shiftOut(dataPin, clockPin, LSBFIRST,  frameThree[2]); //byte 2: anodes(5s) Disp 4 and extra
      shiftOut(dataPin, clockPin, LSBFIRST,  frameThree[3]); //byte 3: anodes(5s) Disp 2, 3 and 4
      shiftOut(dataPin, clockPin, LSBFIRST,  frameThree[4]); //byte 4: anodes(5s) Disp 1 and 2

      //take the latch pin high so the LEDs will light up:
      digitalWrite(latchPin, HIGH);  
      delay(1);
      
      //frame 4
      digitalWrite(latchPin, LOW);
      // shift out the bits for frame two:
      shiftOut(dataPin, clockPin, LSBFIRST,  frameFour[1]);  //byte 1: cathodes(7s)
      shiftOut(dataPin, clockPin, LSBFIRST,  frameFour[2]); //byte 2: anodes(5s) Disp 4 and extra
      shiftOut(dataPin, clockPin, LSBFIRST,  frameFour[3]); //byte 3: anodes(5s) Disp 2, 3 and 4
      shiftOut(dataPin, clockPin, LSBFIRST,  frameFour[4]); //byte 4: anodes(5s) Disp 1 and 2

      //take the latch pin high so the LEDs will light up:
      digitalWrite(latchPin, HIGH);  
      delay(1);
    }

  }

}

void updateFrames (byte dispNo, byte textChar[]) {
  for(int i = 0; i < 5; i++)
  {
//    frameOne[i] = (frame1String );
 //   frameTwo[i] = (frame2String);
 //   frameThree[i] = (frame3String);
  }

}

byte calculateString(byte* charframe1Name){
byte colData[7];
  for (byte x; x > 8; x++ )
  {

    for (int y = 0; y < 8; y++) {
      bitWrite(colData[x],y, bitRead(charframe1Name[x], y)) ;
    }
  }
}








Discussions

Scissorfeind wrote 01/27/2015 at 20:25 point

Hey suicidal.banana! Thanks for the tip! I have realized that my design is going to be reliant on SMT parts which I am not able to scrounge so easily, thus I should probably abandon my current circuit as it grew out of my junk pile, not anything coherent.

  Are you sure? yes | no

suicidal.banana wrote 01/14/2015 at 12:51 point

What i would prolly do is use attiny's to make a chainable matrix display (attiny + shift register if needed + led matrix)

Theres plenty of stuff you can find online about how to easily chain attinys, but the gist of it is that you give each 'reciever' an id, then have the controller just constantlly send out <id> <action> <id> <action> <id> <action> (where <action> would be something like turning on led 'x1-y3' or even a range of leds (prolly better)) and all the attiny's just check if <id> matches their own, if it does, process, if it doesnt, send further along the chain

  Are you sure? yes | no