Pages: 1 [2] 3 4   Go Down
Author Topic: Flex Sensor and Mini 8X8 LED Matrix????  (Read 4486 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

- Moderator
Logged

Offline Offline
Edison Member
*
Karma: 64
Posts: 2466
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the tutorial you've linked to the two pots are used to position a lit LED (one sets the X-axis position and the other sets the Y-axis position.)

As to which pin is what on a matrix -
1) if you can find a datasheet then your work is cut out for you
2) if you can't find a datasheet then you get in there in a DMM and "pin it out", an exercise in process of elimination

Matrixes are for doing letters and pictures with and such, for making a flashlight they're a hassle.
When discussing matters related to your sketch - always post your code.
Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Offline Offline
Edison Member
*
Karma: 64
Posts: 2466
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't have a flexsensor, but I have a pot.  
I didn't want to rig up a bunch of LEDs (it's your project), but I have a bulb that pulls 120mA (considerable draw), used a MOSFET.  So, I rigged that much up and used the following sketch; pretty short and sweet --

Code:
/*
   read pot (sensor)
   result PWM
   repeat
*/
const byte sensorPin = 3;
const byte lightPin = 0;
int sensorval;

void setup()
{
  pinMode (lightPin, OUTPUT);
}

void loop ()
{
  sensorRead();
  analogWrite (lightPin,sensorval);
}

void sensorRead ()
{
  delay(10);
  sensorval = analogRead(sensorPin);
  sensorval = sensorval/4;  //  1024/4 = 256
  if (sensorval < 20)       // for solid OFF "zone"
  {
    sensorval = 0;
  }  
}

I used an ATtiny85 instead of a full-blown Arduino, but, again, same difference.  
For the analogWrite pins, use one of the designated PWM pins (D13 is not one.)  
For the analogRead, use A0-A5.

> > >  I guess I wasn't paying close enough attention - you've bought a matrix already.  
I don't have any good suggestions for that (other than not using it.)  You'll have to home-run 16 wires or something (not good)?  I'm not a 7219 maven.  Code intensive little things for being so "handy". 
So, I guess your dilemma is: How To Vary the Intensity of LEDs with a 7219?

Also, with a 5x7, say, being a rectangle, basically everyone wants to reckon that as 5 columns and 7 rows.
But a square has as many rows as columns, so whether it's column cathodes or column rows is more, to me, in the eye of the beholder.  Page 3 of your linked PDF shows how they figure though. I guess, looking at the labelled side with the pins pointing down, pin 1 is on the left (and pin 16 is directly opposite it on the other side.)
« Last Edit: February 24, 2013, 11:45:15 am by Runaway Pancake » Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26570
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's the connections you want.
This code was written for IDE 00223 and is kinda long, but it gets the job done.
Need to declare all the variables with addresses per the MAX7219 datasheet, Table 2.
May have to change "SS" to "SSpin" or similar.

Code:
// ***********************************************************************************************
void setup() // stuff that runs once before looping forever
{
  // start up SPI to talk to the MAX7221
  SPI.begin(); // nothing in () because we are the master
  pinMode(SS, OUTPUT);  // Slave Select for SPI  <--- Need this here before any SPI writes

  //  MAX7221
  // write shutdown register  
  digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(SHUTDOWN_ADDRESS);  // select the Address,
  SPI.transfer(0x00);      // select the data, 0x00 = Outputs turned off
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip:
  // Serial.println("shutdown register, dislays off");

  //  write intensity register
  digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(INTENSITY_ADDRESS);  // select the Address,
  SPI.transfer(intensity);      // select the data
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip:
  //Serial.println("intensity register ");

  // write scanlimit register
  digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(SCANLIMIT_ADDRESS);  // select the Address,
  SPI.transfer(0xFF);      // select the data - FF = all 8 digits
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip:
  //Serial.println("scanlimit register ");

  // write decode register
  digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(DECODE_MODE);  // select the Address,
  SPI.transfer(0xFF);      // select the data - FF = all 8 digits
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip:
  //Serial.println("decode register ");

  //display test
  digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(DISPLAYTEST_ADDRESS);  // select the Address,
  SPI.transfer(0x01);      // select the data
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip:
  //Serial.println("digit display test on ");
  delay (100);

  digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(DISPLAYTEST_ADDRESS);  // select the Address,
  SPI.transfer(0x00);      // select the data
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip:
  //Serial.println("digit display test off ");
  delay (100);

  // write shutdown register for normal display operations
  digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(SHUTDOWN_ADDRESS);  // select the Address,
  SPI.transfer(0x01);      // select the data, 0x01 = Normal Ops
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip:
  //Serial.println("shutdown register, displays on ");

  digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(digit0_address);  // select the Address,
  SPI.transfer(0xFF);      // all segments on
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip
  
  digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(digit1_address);  // select the Address,
  SPI.transfer(0xFF);      // all segments on
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip

    digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(digit2_address);  // select the Address,
  SPI.transfer(0xFF);      // all segments on
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip

    digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(digit3_address);  // select the Address,
  SPI.transfer(0xFF);      // all segments on
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip

    digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(digit4_address);  // select the Address,
  SPI.transfer(0xFF);      // all segments on
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip

    digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(digit5_address);  // select the Address,
  SPI.transfer(0xFF);      // all segments on
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip

    digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(digit6_address);  // select the Address,
  SPI.transfer(0xFF);      // all segments on
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip

    digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(digit7_address);  // select the Address,
  SPI.transfer(0xFF);      // all segments on
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip
    
} // end of void setup(), ready to interact with users

void loop(){
  //  write intensity register - vary from 0x00 (dim) to 0x0F (bright)
  digitalWrite(SS,LOW);  // take the SS pin low to select the chip:
  SPI.transfer(INTENSITY_ADDRESS);  // select the Address,
  SPI.transfer(intensity);      // select the data
  digitalWrite(SS,HIGH);   // take the SS pin high to de-select the chip:
  //Serial.println("intensity register ");
}


* MAX7219_8x8.jpg (63.28 KB, 960x720 - viewed 28 times.)
« Last Edit: February 24, 2013, 10:29:56 pm by CrossRoads » Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's the connections you want.
This code was written for IDE 00223 and is kinda long, but it gets the job done.
Need to declare all the variables with addresses per the MAX7219 datasheet, Table 2.
May have to change "SS" to "SSpin" or similar.


Great thanks a million. Sorry for cross threading but felt could get more answers faster and would have deleted after anyways as I know no one likes a know nothing cluttering good forums, again apologies for my ignorance this is just a project where our teachers really have thrown us in the deep end and expect too much as design students given the time they give us.  Alas I have the entire matrix and MAX wired except for 2 things:

1) What do i do with pin 24 if the matrix is all I want to rig?
2) As per my calculations-although I don't think I fully understand variables
I need a 30K resistor to be safe http://www.adafruit.com/datasheets/BL-M07C881.PDF

Instead of the code writing the brightness of the matrix I believe I may try the "bar graph" way of lighting LEDs
to simulate dimming and brightening by just changing the number of LED rows that are lit.
https://www.youtube.com/watch?v=mBLKXD-xxMs

This guy is doing without a MAX??
Does that mean I will get more power to matrix?

Will get resistor tomorrow and try it all out! Excited.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry for cross threading but felt could get more answers faster ...

No, it just wastes time as some people reply to one thread and some to another. Then they realize there are two threads going. Then they complain to a moderator. Then the moderator has to track it all down, merge / delete / warn. See how much time that wastes?

Quote
... and would have deleted after anyways  ...

Don't delete threads please. This place is supposed to help other people as well, not just you.

How to use this forum
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26570
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Pin 24 - leave it disconnected
Resistor - yeah, 30K sounds like it could be in range per pages 10 & 11.
I don't know anything about your matrix.  One resistor, easy to change it.

You can drive the matrix like that, but you'll smoke the arduino pins sooner or later.
You want bright? Look at high mcd individual LEDs instead.
Wire up 8, turn in 1,2,3,4,5,6,7,8 with increasing brightness.
http://www.dipmicro.com/store/LED5W
20mA will be blinding bright! Wear your shades, use a PWM pin for dimming.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You want bright? Look at high mcd individual LEDs instead.
Wire up 8, turn in 1,2,3,4,5,6,7,8 with increasing brightness.
http://www.dipmicro.com/store/LED5W
20mA will be blinding bright! Wear your shades, use a PWM pin for dimming.

http://www.dipmicro.com/store/IRF9540
http://www.dipmicro.com/store/STP16NF06

So these^^ MOSFETs would be comparable to the ones Pancake was helping me with but from that other site?
About to do a combined order from dipmicro is there anything else I should grab from that site?

Will be getting the resistor from radioshack later today...
Logged

Offline Offline
Edison Member
*
Karma: 64
Posts: 2466
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

IRF9540? NO, it's P-channel
STP16NF06?  It's N-channel; still not "truly" logic-level - it may be acceptable with the current ( ID ) of your project.

> > > Get This -- http://www.dipmicro.com/store/FQP30N06L
« Last Edit: February 26, 2013, 11:32:35 am by Runaway Pancake » Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Many thanks Runaway!!

You guys are making me think this will actually get done!
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26570
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

35mOhm, nice.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dip Micro still hasn't come yet ugh but anxious for to set up the bright LEDS when it does.

Setup the max7219 and matrix I have now but only 6 random LEDs come on.
Attached is an image of my matrix pins from its data sheet.
I still feel like I don't have the proper MAX and matrix pins lined up.
My matrix is the one on the left.  I understand the MAX outputs but they are SEGA or w/e not just simple
1,2,3,4... 16


Another problem could be that I didn't jump the +/- on the breadboard enough.
(I only did one jump on the other opposite side of the bread board)
Would this cause my problem?

If still working on this matrix is a waste of any of your time we can just wait until
the super brights come in with the MOSFETS and rig that up.  Not sure I still understand how that
is going to work but will do more reading/tests of what both of you have posted thus far.

Thank you so much for all you guys have given...


* BL-M07C881W-11 .png (142.04 KB, 979x400 - viewed 26 times.)
« Last Edit: February 28, 2013, 12:31:29 pm by bandrake » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Attached is how I had it rigged up.
Obviously ripped out the matrix in frustration but just so you guys can confirm
that I did have the other things correct:

4 and 9 ground
18 R and 19 V+
.1uF cap
1uF cap
Jump at opp end

Here's the code I was running also:

Quote
/* code for max 7219 from maxim,
reduced and optimised for useing more then one 7219 in a row,
______________________________________
 
 Code History:
 --------------
 
The orginal code was written for the Wiring board by:
 * Nicholas Zambetti and Dave Mellis /Interaction Design Institute Ivrea /Dec 2004
 * http://www.potemkin.org/uploads/Wiring/MAX7219.txt
 
First modification by:
 * Marcus Hannerstig/  K3, malm� h�gskola /2006
 * http://www.xlab.se | http://arduino.berlios.de
 
This version is by:
 * tomek ness /FH-Potsdam / Feb 2007
 * http://design.fh-potsdam.de/
 
 * @acknowledgements: eric f.
 
-----------------------------------
 
General notes:
 
 
-if you are only using one max7219, then use the function maxSingle to control
 the little guy ---maxSingle(register (1-8), collum (0-255))
 
-if you are using more then one max7219, and they all should work the same,
then use the function maxAll ---maxAll(register (1-8), collum (0-255))
 
-if you are using more than one max7219 and just want to change something
at one little guy, then use the function maxOne
---maxOne(Max you wane controll (1== the first one), register (1-8),
collum (0-255))
 
/* During initiation, be sure to send every part to every max7219 and then
 upload it.
For example, if you have five max7219's, you have to send the scanLimit 5 times
before you load it-- other wise not every max7219 will get the data. the
function maxInUse  keeps track of this, just tell it how many max7219 you are
using.
*/
 
int dataIn = 2;
int load = 3;
int clock = 4;
 
int maxInUse = 1;    //change this variable to set how many MAX7219's you'll use
 
int e = 0;           // just a varialble
 
                     // define max7219 registers
byte max7219_reg_noop        = 0x00;
byte max7219_reg_digit0      = 0x01;
byte max7219_reg_digit1      = 0x02;
byte max7219_reg_digit2      = 0x03;
byte max7219_reg_digit3      = 0x04;
byte max7219_reg_digit4      = 0x05;
byte max7219_reg_digit5      = 0x06;
byte max7219_reg_digit6      = 0x07;
byte max7219_reg_digit7      = 0x08;
byte max7219_reg_decodeMode  = 0x09;
byte max7219_reg_intensity   = 0x0a;
byte max7219_reg_scanLimit   = 0x0b;
byte max7219_reg_shutdown    = 0x0c;
byte max7219_reg_displayTest = 0x0f;
 
void putByte(byte data) {
  byte i = 8;
  byte mask;
  while(i > 0) {
    mask = 0x01 << (i - 1);      // get bitmask
    digitalWrite( clock, LOW);   // tick
    if (data & mask){            // choose bit
      digitalWrite(dataIn, HIGH);// send 1
    }else{
      digitalWrite(dataIn, LOW); // send 0
    }
    digitalWrite(clock, HIGH);   // tock
    --i;                         // move to lesser bit
  }
}
 
void maxSingle( byte reg, byte col) {    
//maxSingle is the "easy"  function to use for a     //single max7219
 
  digitalWrite(load, LOW);       // begin    
  putByte(reg);                  // specify register
  putByte(col);//((data & 0x01) * 256) + data >> 1); // put data  
 
  digitalWrite(load,HIGH);
}
 
void maxAll (byte reg, byte col) {    // initialize  all  MAX7219's in the system
  int c = 0;
  digitalWrite(load, LOW);  // begin    
  for ( c =1; c<= maxInUse; c++) {
  putByte(reg);  // specify register
  putByte(col);//((data & 0x01) * 256) + data >> 1); // put data
    }
    
  digitalWrite(load,HIGH);
}
 
void maxOne(byte maxNr, byte reg, byte col) {    
//maxOne is for adressing different MAX7219's,
//whilele having a couple of them cascaded
 
  int c = 0;
  digitalWrite(load, LOW);  // begin    
 
  for ( c = maxInUse; c > maxNr; c--) {
    putByte(0);    // means no operation
    putByte(0);    // means no operation
  }
 
  putByte(reg);  // specify register
  putByte(col);//((data & 0x01) * 256) + data >> 1); // put data
 
  for ( c =maxNr-1; c >= 1; c--) {
    putByte(0);    // means no operation
    putByte(0);    // means no operation
  }
 
  digitalWrite(load,HIGH);
}
 
 
void setup () {
 
 
  pinMode(dataIn, OUTPUT);
  pinMode(clock,  OUTPUT);
  pinMode(load,   OUTPUT);
 

  digitalWrite(clock, HIGH);  
 
//initiation of the max 7219
  maxAll(max7219_reg_scanLimit, 0x07);      
  maxAll(max7219_reg_decodeMode, 0x00);  // using an led matrix (not digits)
  maxAll(max7219_reg_shutdown, 0x01);    // not in shutdown mode
  maxAll(max7219_reg_displayTest, 0x00); // no display test
   for (e=1; e<=8; e++) {    // empty registers, turn all LEDs off
    maxAll(e,0);
  }
  maxAll(max7219_reg_intensity, 0x0f & 0x0f);    // the first 0x0f is the value you can set
                                                  // range: 0x00 to 0x0f
}  
 
void loop () {
 
 
  //if you use just one MAX7219 it should look like this
  /*
   maxSingle(1,1);                       //  + - - - - - - -
   maxSingle(2,2);                       //  - + - - - - - -
   maxSingle(3,4);                       //  - - + - - - - -
   maxSingle(4,8);                       //  - - - + - - - -
   maxSingle(5,16);                      //  - - - - + - - -
   maxSingle(6,32);                      //  - - - - - + - -
   maxSingle(7,64);                      //  - - - - - - + -
   maxSingle(8,128);                     //  - - - - - - - +
 
  */
  //if you use more than one MAX7219, it should look like this
 
  /*
  maxAll(1,1);                       //  + - - - - - - -
  maxAll(2,3);                       //  + + - - - - - -
  maxAll(3,7);                       //  + + + - - - - -
  maxAll(4,15);                      //  + + + + - - - -
  maxAll(5,31);                      //  + + + + + - - -
  maxAll(6,63);                      //  + + + + + + - -
  maxAll(7,127);                     //  + + + + + + + -
  maxAll(8,255);                     //  + + + + + + + +
  */
 
  //
 
  //if you use more then one max7219 the second one should look like this
 
 
   maxSingle(1,1);                       //  + - - - - - - -
   maxSingle(2,2);                       //  - + - - - - - -
   maxSingle(3,4);                       //  - - + - - - - -
   maxSingle(4,8);                       //  - - - + - - - -
   maxSingle(5,16);                      //  - - - - + - - -
   maxSingle(6,32);                      //  - - - - - + - -
   maxSingle(7,64);                      //  - - - - - - + -
   maxSingle(8,128);                     //  - - - - - - - +
 
 
  //
  delay(2000);
 
}


* IMG_2700.jpg (2178.95 KB, 3264x2448 - viewed 24 times.)
« Last Edit: February 28, 2013, 12:45:03 pm by bandrake » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26570
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The Row pins go to the DIGIT outputs,
The Anode pins go the SEGMENT outputs.
If its not working, then you're likely wired incorrectly.
Here's 4 of them driving 4 matrices.



* 8x32shield.jpg (158.89 KB, 1043x629 - viewed 29 times.)
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Row pins go to the DIGIT outputs,
The Anode pins go the SEGMENT outputs.
If its not working, then you're likely wired incorrectly.
Here's 4 of them driving 4 matrices.

Ok great I think I will be able to figure that then will wire post and post a picture ASAP

Only reason I didn't use your code Crossroads is because I couldn't figure out how to edit to verify.
I can only figure simple things like editing pin numbers lol sorry.  No need to reload code but may be
necessary when get the LCDs going so I can have that one perfect.  Thanks so much.
Logged

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