Output a variable in binary/hex to display on 7segment.. no idea! [SOLVED]

hey guys, i've googled around for the past 4 hours or so, and I haven't learned much about what I'm looking for. As of right now all I'm trying to do is use a DS1621 to read temperature, and then output the temperature, in farenheit, on a double - 7seg display.

I've already learned how to use a shift register to count from 0 to 9, but it was not multiplexing... just using an array of hard-written binary values, looping through as it shifts the bytes out for each number. I'm able to get a temperature reading via the serial console of the arduino IDE, but i'm lost as of right now.

yes, i am pretty new to this... but the more i learn, the more i really enjoy making electrons do my bidding.

This is the code I am using for the temperature sensor:

#include <Wire.h>

// Simple DS1621 demo
// -- by Jon McPhalen (www.jonmcphalen.com)
// -- 19 DEC 2007

// SDA pin is Analog4
// SCL pin is Analog5
// DS1621 has A2, A1, and A0 pins connected to GND


#define DEV_ID 0x90 >> 1                    // shift required by wire.h


void setup()
{
 Serial.begin(9600);

 Wire.begin();
 Wire.beginTransmission(DEV_ID);           // connect to DS1621 (#0)
 Wire.send(0xAC);                          // Access Config
 Wire.send(0x02);                          // set for continuous conversion
 Wire.beginTransmission(DEV_ID);           // restart
 Wire.send(0xEE);                          // start conversions
 Wire.endTransmission();
}


void loop()
{
 int tempC = 0;
 int tempF = 0;

 delay(1000);                              // give time for measurement
 Wire.beginTransmission(DEV_ID);
 Wire.send(0xAA);                          // read temperature
 Wire.endTransmission();
 Wire.requestFrom(DEV_ID, 1);              // request one byte from DS1621
 tempC = Wire.receive();                   // get whole degrees reading
 tempF = tempC * 9 / 5 + 32;               // convert to Fahrenheit

 Serial.print(tempC);
 Serial.print(" / ");
 Serial.println(tempF);
}

any guidance, please?! thanks!

DONT GET YOU HOPES UP I HAVE NO ANSWER

sorry just had to comment though. I am soon going to be outputting a temp to a 2 dig 7 seg and thought following would be good. Holly moly that DS1621 is pricey! why not let that arduino do the work for you and go with an LM34/LM35/LM36 temp sens thats what I did. You can get six of um for the price of one DS1621. I havent been brave enough to jump into D inputs yet. Good luck!

bFORTIFIED:
DONT GET YOU HOPES UP I HAVE NO ANSWER

sorry just had to comment though. I am soon going to be outputting a temp to a 2 dig 7 seg and thought following would be good. Holly moly that DS1621 is pricey! why not let that arduino do the work for you and go with an LM34/LM35/LM36 temp sens thats what I did. You can get six of um for the price of one DS1621. I havent been brave enough to jump into D inputs yet. Good luck!

Well, I did sample a few of them from Maxim. I have a bunch of ICs that I've sampled from different manufacturers. I also bought a bunch, too, along with an assortment of electrolytic capacitors, resistors, LEDs, transistors, MOSFETs, copper clad board, and other random things.

Ironically, I pulled this 7 segment from an old CD player... I love junk electronics, for that sole reason :smiley:

I'll keep looking though... it seems all I need to do is turn tF into something that I can interface with a shift register. I wonder if I were to try and add the shift register code I wrote recently to this temperature sensor code, and make it output the temperature variable as a byte to the shift register, and then debug from there... I'm not entirely sure that would be the best route though.

Unless you are short of pins, you don't need any shift registers, you can drive two 7-seg displays in a multiplexed arrangement using 9 Arduino pins (or 10 if you want to drive the decimal points too). You will need a couple of transistors to drive the common anodes or cathodes of the displays.

I've already learned how to use a shift register to count from 0 to 9, but it was not multiplexing... just using an array of hard-written binary values, looping through as it shifts the bytes out for each number

Was this output to the 7 segment displays? If so, you already have all the code you need, even if you don't understand quite how it works.

Have a look at this, it's a bit more of your puzzle.

http://www.thebox.myzen.co.uk/Tutorial/Arrays.html

I appreciate all the responses yall, it helps a lot.. although the specific part I'm stuck on is taking the result from the getTemp function, like the number 77, then transform it to something I can output on the 7 segment display.

would I have to create an array from, say, 55, to 95?
I'm not at my laboratory right now but I done studied the code over and over, and it seems I just need to just convert the result from the temperature conversion from C to F. if I translate it to binary, I'm still clueless as to how would I get a usable output :confused:

would I have to create an array from, say, 55, to 95?

For what? Each segment can only display one of 10 values - for the digits 0 to 9.

Breaking a number like 67 into a tens value, 6, and a ones value, 7, is trivial. Sending the data to show a 6 should be trivial, too.

Explain what it is that you are having trouble with.

PaulS:
For what? Each segment can only display one of 10 values - for the digits 0 to 9.

Breaking a number like 67 into a tens value, 6, and a ones value, 7, is trivial. Sending the data to show a 6 should be trivial, too.

Explain what it is that you are having trouble with.

I should clarify... since I'm back in my laboratory of a room, I have access to all my data and sketches.
You see, in the very last section of the code that I put in the first post, it prints the temperature to the serial monitor...

 Serial.print(tempC);
 Serial.print(" / ");
 Serial.println(tempF);

prints the temperature in Celcuis and Fahrenheit. What I'm wanting to do, is take this number, and have it displayed on a double digit seven-segment display.

Now, I wrote code to use a 74HC595 shift register to drive 1 side of the seven-seg display, and this is what I have:

int latch = 8;
int clock = 12;
int data = 11;

byte numArray[10];
byte dataShift;

void setup() {
  pinMode(latch, OUTPUT);
  pinMode(clock, OUTPUT);
  pinMode(data, OUTPUT);
  
  numArray[0] = B10000001; //0
  numArray[1] = B11110011; //1
  numArray[2] = B01001001; //2
  numArray[3] = B01100001; //3
  numArray[4] = B00110011; //4
  numArray[5] = B00100101; //5
  numArray[6] = B00000101; //6
  numArray[7] = B11110001; //7
  numArray[8] = B00000001; //8
  numArray[9] = B00100001; //9
}
void loop(){
  for (int NTD = 0; NTD < 10; NTD++) {
    dataShift = numArray[NTD];
    digitalWrite(latch, LOW);
    shiftOut(data, clock, MSBFIRST, dataShift);
    digitalWrite(latch, HIGH);
    delay(500);
  }
}

Like I was saying in a previous post... I can maybe merge the two together, and through trial and error, theres a chance I may get it to work. On the other hand, though, I could be walking on a dead end path.

Obviously, I'm very new to this... but I'm making my way around :slight_smile:

and through trial and error, theres a chance I may get it to work

Or you could read the advice given here. It's up to you.

The code in your for loop sends data from numArray[n] to display the value n on a 7 segment display.

Put that code in a function:

void displayOnes(int n)
{
    dataShift = numArray[n];
    digitalWrite(latch, LOW);
    shiftOut(data, clock, MSBFIRST, dataShift);
    digitalWrite(latch, HIGH);
}

Create a similar function for the other 7 segment display:

void displayTens(int n)
{
   // Some code here
}

Then, call the functions:

int temperatureF = 67;
int tens = temperatureF / 10;
int ones = temperatureF % 10;
displayOnes(ones);
displayTens(tens);

Depending on how you have the 7 segment devices connected, the only change between displayOnes() and displayTens() is likely to be to change the data pin. Since you won't output data to both at the same time, you can share clock and latch pins. Even if you use separate data, clock, and latch pins, those are the only things that need to change.

You could make the pin numbers input to the function, so you only need one function, or put the data, clock, and latch pins in arrays (in the same order in each array), and make the array index an input to the one function.

PaulS:
The code in your for loop sends data from numArray[n] to display the value n on a 7 segment display.

Put that code in a function:

Depending on how you have the 7 segment devices connected, the only change between displayOnes() and displayTens() is likely to be to change the data pin. Since you won't output data to both at the same time, you can share clock and latch pins. Even if you use separate data, clock, and latch pins, those are the only things that need to change.

You could make the pin numbers input to the function, so you only need one function, or put the data, clock, and latch pins in arrays (in the same order in each array), and make the array index an input to the one function.

AHHHH now I understand it! I spent hours and hours on the Reference section of the site here, soaking it all in.

Thanks so much Mr. Paul. I'll mess with it later today as I have company and my child is visiting.

Cheers and happy holidays :smiley:

guys, I have some great news. this is an unlocked achievement for me.

I can finally visualize digital circuits, and bit manipulation. thanks to you fine folks, I have a working digital thermometer. I

there you have it!

and heres the code

THANKS AGAIN BROS

Hi, good job on getting this working, I'm in a similar position as you in being a beginner.

Any chance of uploading a circuit schematic for me to look at?

Cheers!