Go Down

Topic: 7-Segment Shield on Arduino UNO? (Read 3101 times) previous topic - next topic

Merko

Hi.
I got this 7-Seg shield (http://www.gravitech.us/7segmentshield.html). But i cannot get it to work with my Arduno UNO.
Anyone got any idea what could be wrong?

I tried the sample code from the page:
Code: [Select]
/***************************************************************************

                    Copyright 2008 Gravitech
                       All Rights Reserved

****************************************************************************/

/***************************************************************************
File Name: I2C_7SEG_Temperature.pde

Hardware: Arduino Diecimila with 7-SEG Shield

Description:
  This program reads I2C data from digital thermometer and display it on 7-Segment

Change History:
  03 February 2008, Gravitech - Created

****************************************************************************/

#include <Wire.h>

#define BAUD (9600)    /* Serial baud define */
#define _7SEG (0x38)   /* I2C address for 7-Segment */
#define THERM (0x49)   /* I2C address for digital thermometer */
#define EEP (0x50)     /* I2C address for EEPROM */
#define RED (3)        /* Red color pin of RGB LED */
#define GREEN (5)      /* Green color pin of RGB LED */
#define BLUE (6)       /* Blue color pin of RGB LED */

#define COLD (23)      /* Cold temperature, drive blue LED (23c) */
#define HOT (26)       /* Hot temperature, drive red LED (27c) */

const byte NumberLookup[16] =   {0x3F,0x06,0x5B,0x4F,0x66,
                                0x6D,0x7D,0x07,0x7F,0x6F,
                                0x77,0x7C,0x39,0x5E,0x79,0x71};

/* Function prototypes */
void Cal_temp (int&, byte&, byte&, bool&);
void Dis_7SEG (int, byte, byte, bool);
void Send7SEG (byte, byte);
void SerialMonitorPrint (byte, int, bool);
void UpdateRGB (byte);

/***************************************************************************
Function Name: setup

Purpose:
  Initialize hardwares.
****************************************************************************/

void setup()
{
 Serial.begin(BAUD);
 Wire.begin();        /* Join I2C bus */
 pinMode(RED, OUTPUT);    
 pinMode(GREEN, OUTPUT);  
 pinMode(BLUE, OUTPUT);  
 delay(500);          /* Allow system to stabilize */
}

/***************************************************************************
Function Name: loop

Purpose:
  Run-time forever loop.
****************************************************************************/

void loop()
{
 int Decimal;
 byte Temperature_H, Temperature_L, counter, counter2;
 bool IsPositive;
 
 /* Configure 7-Segment to 12mA segment output current, Dynamic mode,
    and Digits 1, 2, 3 AND 4 are NOT blanked */
   
 Wire.beginTransmission(_7SEG);    
 Wire.send(0);
 Wire.send(B01000111);
 Wire.endTransmission();
 
 /* Setup configuration register 12-bit */
   
 Wire.beginTransmission(THERM);    
 Wire.send(1);
 Wire.send(B01100000);
 Wire.endTransmission();
 
 /* Setup Digital THERMometer pointer register to 0 */
   
 Wire.beginTransmission(THERM);    
 Wire.send(0);
 Wire.endTransmission();
 
 /* Test 7-Segment */
 for (counter=0; counter<8; counter++)
 {
   Wire.beginTransmission(_7SEG);
   Wire.send(1);
   for (counter2=0; counter2<4; counter2++)
   {
     Wire.send(1<<counter);
   }
   Wire.endTransmission();
   delay (250);
 }
 
 while (1)
 {
   Wire.requestFrom(THERM, 2);
   Temperature_H = Wire.receive();
   Temperature_L = Wire.receive();
   
   /* Calculate temperature */
   Cal_temp (Decimal, Temperature_H, Temperature_L, IsPositive);
   
   /* Display temperature on the serial monitor.
      Comment out this line if you don't use serial monitor.*/
   SerialMonitorPrint (Temperature_H, Decimal, IsPositive);
   
   /* Update RGB LED.*/
   UpdateRGB (Temperature_H);
   
   /* Display temperature on the 7-Segment */
   Dis_7SEG (Decimal, Temperature_H, Temperature_L, IsPositive);
   
   delay (1000);        /* Take temperature read every 1 second */
 }
}

/***************************************************************************
Function Name: Cal_temp

Purpose:
  Calculate temperature from raw data.
****************************************************************************/
void Cal_temp (int& Decimal, byte& High, byte& Low, bool& sign)
{
 if ((High&B10000000)==0x80)    /* Check for negative temperature. */
   sign = 0;
 else
   sign = 1;
   
 High = High & B01111111;      /* Remove sign bit */
 Low = Low & B11110000;        /* Remove last 4 bits */
 Low = Low >> 4;
 Decimal = Low;
 Decimal = Decimal * 625;      /* Each bit = 0.0625 degree C */
 
 if (sign == 0)                /* if temperature is negative */
 {
   High = High ^ B01111111;    /* Complement all of the bits, except the MSB */
   Decimal = Decimal ^ 0xFF;   /* Complement all of the bits */
 }  
}

/***************************************************************************
Function Name: Dis_7SEG

Purpose:
  Display number on the 7-segment display.
****************************************************************************/
void Dis_7SEG (int Decimal, byte High, byte Low, bool sign)
{
 byte Digit = 4;                 /* Number of 7-Segment digit */
 byte Number;                    /* Temporary variable hold the number to display */
 
 if (sign == 0)                  /* When the temperature is negative */
 {
   Send7SEG(Digit,0x40);         /* Display "-" sign */
   Digit--;                      /* Decrement number of digit */
 }
 
 if (High > 99)                  /* When the temperature is three digits long */
 {
   Number = High / 100;          /* Get the hundredth digit */
   Send7SEG (Digit,NumberLookup[Number]);     /* Display on the 7-Segment */
   High = High % 100;            /* Remove the hundredth digit from the TempHi */
   Digit--;                      /* Subtract 1 digit */    
 }
 
 if (High > 9)
 {
   Number = High / 10;           /* Get the tenth digit */
   Send7SEG (Digit,NumberLookup[Number]);     /* Display on the 7-Segment */
   High = High % 10;            /* Remove the tenth digit from the TempHi */
   Digit--;                      /* Subtract 1 digit */
 }
 
 Number = High;                  /* Display the last digit */
 Number = NumberLookup [Number];
 if (Digit > 1)                  /* Display "." if it is not the last digit on 7-SEG */
 {
   Number = Number | B10000000;
 }
 Send7SEG (Digit,Number);  
 Digit--;                        /* Subtract 1 digit */
 
 if (Digit > 0)                  /* Display decimal point if there is more space on 7-SEG */
 {
   Number = Decimal / 1000;
   Send7SEG (Digit,NumberLookup[Number]);
   Digit--;
 }

 if (Digit > 0)                 /* Display "c" if there is more space on 7-SEG */
 {
   Send7SEG (Digit,0x58);
   Digit--;
 }
 
 if (Digit > 0)                 /* Clear the rest of the digit */
 {
   Send7SEG (Digit,0x00);    
 }  
}

/***************************************************************************
Function Name: Send7SEG

Purpose:
  Send I2C commands to drive 7-segment display.
****************************************************************************/

void Send7SEG (byte Digit, byte Number)
{
 Wire.beginTransmission(_7SEG);
 Wire.send(Digit);
 Wire.send(Number);
 Wire.endTransmission();
}

/***************************************************************************
Function Name: UpdateRGB

Purpose:
  Update RGB LED according to define HOT and COLD temperature.
****************************************************************************/

void UpdateRGB (byte Temperature_H)
{
 digitalWrite(RED, LOW);
 digitalWrite(GREEN, LOW);
 digitalWrite(BLUE, LOW);        /* Turn off all LEDs. */
 
 if (Temperature_H <= COLD)
 {
   digitalWrite(RED, HIGH);
 }
 else if (Temperature_H >= HOT)
 {
   digitalWrite(RED, HIGH);
 }
 else
 {
   digitalWrite(GREEN, HIGH);
 }
}

/***************************************************************************
Function Name: SerialMonitorPrint

Purpose:
  Print current read temperature to the serial monitor.
****************************************************************************/
void SerialMonitorPrint (byte Temperature_H, int Decimal, bool IsPositive)
{
   Serial.print("The temperature is ");
   if (!IsPositive)
   {
     Serial.print("-");
   }
   Serial.print(Temperature_H, DEC);
   Serial.print(".");
   Serial.print(Decimal, DEC);
   Serial.print(" degree C");
   Serial.print("\n\n");
}  



The serial monitor just report this back:
The temperature is 0.0 degree C

Does it even work with Arduino UNO?

Appreciate some help on this one, thanks :)


johnwasser

There should be no reason for it to NOT work on the Uno.

Does the blue "Power" LED come on?  Can you turn on the RGB LED?  That would be the simplest thing to try.  If that doesn't work, something is probably wrong in hardware.

If that works, see if you can get either the 7-segment display or the thermometer to work over I2C.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Merko


There should be no reason for it to NOT work on the Uno.

Does the blue "Power" LED come on?  Can you turn on the RGB LED?  That would be the simplest thing to try.  If that doesn't work, something is probably wrong in hardware.

If that works, see if you can get either the 7-segment display or the thermometer to work over I2C.

Yes the blue "Power" LED goes on, and the RGB LED also turns Blue (because the code makes it blue if its cold) And since it keep reporting back 0c, it will just stay blue.

I dont get any information on the 7 Segment display itself. Also did a minor change in the code to make it display red instead of blue, which works fine. Just can't get it to read temp and put the info on the display. :|

johnwasser

That's good.  At least the non I2C pins are working. 

It seems odd to me that the schematic for the shield gives two different !2C address for each device.  The example code uses the "Arduino" address.

If you hook an LED between the I2C pins (A0 and A1) and ground do they blink when you try to use the I2C devices?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Merko


That's good.  At least the non I2C pins are working. 

It seems odd to me that the schematic for the shield gives two different !2C address for each device.  The example code uses the "Arduino" address.

If you hook an LED between the I2C pins (A0 and A1) and ground do they blink when you try to use the I2C devices?

As you probably already notice, Arduino is new to me and i'm trying to understand what i'm doing.

What exactly is I2C pins? Is it Analog0 and Analog1 on the Ardunino board?

Did you want me to put a LED on A0 and ground, then A1 and ground to see if the LED blinks? Am i supposed to do that directly on the Arduino board with out the 7segment shield ontop?

Appreciate your help.  :smiley-red:

johnwasser

My mistake: the I2C pins are Analog 4 and Analog 5.

Hook LEDs to them like you would for a digital output.  Then you can see if the I2C bus is being used.  If they flicker the problems is probably somewhere in the 7-segment shield.   I hope the vendor can help you fix whatever is not working.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Merko

Hi thank you for your help. :-)

I tried to hook the LED up with Analog 5. The led had low light, but didn't flicker. When i had the wire into Analog 5 the RGB-leg didn't seem to work. But when i unplug the wire, the RGB-Led went blue. The LED also had low light when i hooked it up on Analog 4, but the RGB-Led worked fine then.

Bougth it for Makershed. not sure if theres any point in trying to send it in. The shipment probably cost more than the unit itself.

Again thank you.

Was this problem ever resolved?

I ask because I'm having a similar problem with a very similar item:
http://www.gravitech.us/i2c47di.html

This appears to be the I2C 7segment display that's used on the temp. shield.

My display doesn't light up either.  Power led on the board lights up, and I get light from an LED when jumped off of A4 or A5 (LED appears dim, so I think it's flickering really fast).

Here's the example code they offer to test it:
Quote

/**********************************************************
Example program I2C-7SEG interface with Arduino.

SETUP:    I2C-7SEG => Arduino
          PIN1 => +5V PIN2 => GND, PIN3 => A4, PIN4 => A5
Note:     The program is written for address 0x70 (Arduino address 0x38).
          This program was tested using Arduino Nano
Document: SAA1064 datasheet
Updated:  July 30, 2008
E-mail:   support@gravitech.us
          Gravitech
(C) Copyright 2008 All Rights Reserved
**********************************************************/

#include <Wire.h>
 
void setup()

  Wire.begin();        // join i2c bus (address optional for master)
  delay(500);

 
void loop()

  const int lookup[10] = {0x3F,0x06,0x5B,0x4F,0x66,
                          0x6D,0x7D,0x07,0x7F,0x6F};
  int Count, Thousands, Hundreds, Tens, Base;
  
  Wire.beginTransmission(0x38);
  Wire.send(0);
  Wire.send(B01000111);
  Wire.endTransmission();
  
  for (Count=0;Count<=9999;Count++)
  {
    Wire.beginTransmission(0x38);
    Wire.send(1);
    Thousands = Count/1000;
    Hundreds = (Count-(Thousands*1000))/100;
    Tens = (Count-((Thousands*1000)+(Hundreds*100)))/10;
    Base = Count-((Thousands*1000)+(Hundreds*100)+(Tens*10));
    Wire.send(lookup[Base]);
    Wire.send(lookup[Tens]);
    Wire.send(lookup[Hundreds]);
    Wire.send(lookup[Thousands]);
    Wire.endTransmission();
    delay(10);
  }




Like the original poster, I'm also very new to all of this.  So if there's something fishy in the code I'm not going to notice it.   I'm also waiting to hear back from Gravitech support.

Any advice will be greatly appreciated!

floresta

#8
Apr 28, 2011, 10:34 pm Last Edit: Apr 30, 2011, 01:56 am by floresta Reason: 1
I can resolve this part:
Quote
It seems odd to me that the schematic for the shield gives two different !2C address for each device.  The example code uses the "Arduino" address.
The "arduino" address is the basic 7-bit I2C of the device.  This is the one that is typically given in a data sheet, and in my limited experience usually hidden pretty well.  In use that address has to be shifted left by one bit so that the I2C protocol can use the least significant bit to represent the data direction (read/write).  This is the "I2C" address as shown in the schematic.

Quote
Yes the blue "Power" LED goes on, and the RGB LED also turns Blue (because the code makes it blue if its cold) And since it keep reporting back 0c, it will just stay blue.
Does the LED color change if you heat/cool the temperature sensor (upper left corner)?


Don

UPDATE:
I have exchanged several emails with Tony at Gravitech support.  My problem was solved by replacing the wire contacts that I had crimped into the through-holes with soldered leads.  It's working perfectly now.

I don't think that would resolve the issue with the shield, though.

Merko


Does the LED color change if you heat/cool the temperature sensor (upper left corner)?


Don

Hello.
No it doesn't.

In the Arduino Software  > Monitor Report > It keep saying this: The temperature is 0.0 degree C - So, since it stays on "0.0 degrees" all the time, it will just stay blue all the time. I tried to change out the blue color with red which works fine. So no idea what can be  wrong. It seems the temerature sensor and the LCD display doesnt work. for some reason.

Go Up