Pages: [1]   Go Down
Author Topic: MAX6959 and I2C  (Read 1070 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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!
« Last Edit: February 09, 2013, 04:32:15 pm by ichris93 » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5236
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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();
}
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I probably have the code setup wrong.  But bellow is what I have and it isn't working.  Thank you for your help.
Code:
#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);
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 632
Posts: 50182
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  
« Last Edit: February 10, 2013, 06:23:43 pm by ichris93 » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5236
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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:
// 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();
}
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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:

#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);
}
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5236
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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();
}
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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.  
« Last Edit: February 10, 2013, 08:37:06 pm by ichris93 » Logged

Pages: [1]   Go Up
Jump to: