Go Down

Topic: MAX6959 and I2C (Read 1 time) previous topic - next topic

ichris93

Feb 09, 2013, 09:28 pm Last Edit: Feb 09, 2013, 10:32 pm by ichris93 Reason: 1
Hello all,

I am working on a project which requires a four digit seven segment display which is connected to my Arduino with a MAX6959 that interfaces with I2C.  I can get all of the segments to light up with the following display test code.
Code: [Select]

#include <Wire.h>

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


void loop()
{
 Wire.beginTransmission(0b0111000);
 Wire.write(0x07);
 Wire.write(0x01);  
 Wire.endTransmission();
}


But I can't figure out how to control the digits.  Here is a link to the data sheet, http://datasheets.maximintegrated.com/en/ds/MAX6958-MAX6959.pdf

Thanks!

pylon

You can use the following code to set the value of every digit:

Code: [Select]

byte d[] = { 0x7e, 0x60, 0x6d, 0x79, 0x33, 0x5b, 0x1f, 0x70, 0x7f, 0x7b };
void set_digit(byte digit, byte value) {
  Wire.beginTransmission(0x38);
  Wire.write(0x20 + digit);
  Wire.write(d[value]);
  Wire.endTransmission();
}

ichris93

I probably have the code setup wrong.  But bellow is what I have and it isn't working.  Thank you for your help.
Code: [Select]

#include <Wire.h>

void setup()
{
  Wire.begin(); // join i2c bus (address optional for master)
}
byte d[] = { 0x7e, 0x60, 0x6d, 0x79, 0x33, 0x5b, 0x1f, 0x70, 0x7f, 0x7b };
void set_digit(byte digit, byte value)
{Wire.beginTransmission(0x38);
  Wire.write(0x20 + digit);
  Wire.write(d[value]);
  Wire.endTransmission();
}

void loop()
{
set_digit(0, 0);
}

PaulS

Quote
But bellow is what I have and it isn't working.

The code does something. You haven't described that.
You want the code to do something. How that differs from what it does isn't clear.

The ball's back in your court.

ichris93

#4
Feb 11, 2013, 12:12 am Last Edit: Feb 11, 2013, 12:23 am by ichris93 Reason: 1

The code does something. You haven't described that.
You want the code to do something. How that differs from what it does isn't clear.

The ball's back in your court.


When I send it that code, the display doesn't show anything.  When I send it that code I would like it to display 0 on digit 0.  

pylon

You should have tried with another digit, because digit 0 is in decode mode by default. Insert the following into your setup routine:

Code: [Select]

Wire.beginTransmission(0x38);
Wire.write(0x01); // register decode mode
Wire.write(0x00); // disable decode mode for all digits
Wire.endTransmission();


A short description what the set_digit() routine does:

Code: [Select]
// array holding the bitsets for displaying digits 0 to 9
// see page 9, figure 10 of the datasheet for the segment numbering
byte d[] = { 0x7e, 0x60, 0x6d, 0x79, 0x33, 0x5b, 0x1f, 0x70, 0x7f, 0x7b };

void set_digit(byte digit, byte value) {
  Wire.beginTransmission(0x38); // address the MAX6959
  Wire.write(0x20 + digit); // register 0x20 is digit 0, 0x21 is digit 1, etc.
  Wire.write(d[value]); // write the value from the array to the register.
  Wire.endTransmission();
}

ichris93


You should have tried with another digit, because digit 0 is in decode mode by default. Insert the following into your setup routine:

Code: [Select]

Wire.beginTransmission(0x38);
Wire.write(0x01); // register decode mode
Wire.write(0x00); // disable decode mode for all digits
Wire.endTransmission();



Even with the following code, nothing happens.  What am I doing wrong?
Code: [Select]


#include <Wire.h>
byte d[] = { 0x7e, 0x60, 0x6d, 0x79, 0x33, 0x5b, 0x1f, 0x70, 0x7f, 0x7b };

void setup()
{
  Wire.begin();
  Wire.beginTransmission(0x38);
  Wire.write(0x01); // register decode mode
  Wire.write((uint8_t)0x00); // disable decode mode for all digits
  Wire.endTransmission();
}

void set_digit(byte digit, byte value)
{
  Wire.beginTransmission(0x38);
  Wire.write(0x20 + digit);
  Wire.write(d[value]);
  Wire.endTransmission();
}

void loop()
{
  set_digit(3, 1);
}

pylon

Let's extend setup to be sure that all registers have a valid content:

Code: [Select]
void setup()
{
  Wire.begin();
  Wire.beginTransmission(0x38);
  Wire.write(0x01); // register decode mode
  Wire.write(0x00); // disable decode mode for all digits
  Wire.write(0x3f); // intensity max
  Wire.write(0x03); // scan limit 3
  Wire.write(0x03); // normal operation
  Wire.endTransmission();
}

ichris93

#8
Feb 11, 2013, 02:34 am Last Edit: Feb 11, 2013, 02:37 am by ichris93 Reason: 1

Let's extend setup to be sure that all registers have a valid content:

Code: [Select]
void setup()
{
 Wire.begin();
 Wire.beginTransmission(0x38);
 Wire.write(0x01); // register decode mode
 Wire.write(0x00); // disable decode mode for all digits
 Wire.write(0x3f); // intensity max
 Wire.write(0x03); // scan limit 3
 Wire.write(0x03); // normal operation
 Wire.endTransmission();
}



Great!! Thank you! That finally has it working.  BUT you have 0X60 for 1 and it should be 0X30 and for 6 you have 0X1F and it should be 0X5F.  

Go Up