Hello.
I have an Arduino Due connected to both a DS1631 12-bit temperature sensor(I2C) and a MAX7219 8-Digit 7-segment LED Display Driver(SPI) and I want to collect measures from the DS1631 which is done by a library returning a type float value.
I have searched online without being able to find a solution to this and I really can't figure out this my self, I want at least 1 decimal value displayed but all I have been able to come up with is this which only displays a rounded value between 00 and 99.
Notes:
I simply collect the supposedly float value into a int and write the first and second hole numbers out to the display, the weird IF statement in the loop() is there because the I2C wires are long and runs next to a lot of motors which causes the I2C bus to fail in some way(simply my unsubstantiated theory) resulting in the display getting stuck reading "00".
/* Desktop LED light temperature monitor sketch.
* This code uses a DS1631 12-bit output temperature sensor mounted to the heatsink
* of a DIY LED desktop light to monitor it's temperature and display that temperature
* in °C on a 8 digit 7-segment display.
*
* DS1631 wiring:
* Connect DS1631 SDA pin to Arduino Due pin D20 (SDA)
* Connect DS1631 SCL pin to Arduino Due pin D21 (SCL)
*
* MAX7219 wiring:
* Connect MAX7219 DIN pin to Arduino Due pin D4
* Connect MAX7219 CS/LOAD pin to Arduino Due pin D3
* Connect MAX7219 CLK pin to Arduino Due pin D2
*/
#include <Wire.h>
#include <DS1631.h>
#include <LedControl.h>
#define DIN 4
#define CS 3
#define CLK 2
DS1631 sensor(0); // initialize DS1631 object, with bus address equal to pins A2,A1,A0 all tied to ground.
LedControl _7segment = LedControl(DIN, CLK, CS, 1);
void setup()
{
Wire.begin(); // open the I2C bus.
sensor.writeConfig(0b00001101); // Sets configuration of DS1631 as 12-bit, 1-shot mode.
_7segment.shutdown(0, false); // turn on display.
_7segment.setIntensity(0, 5); // 5(max 15) = brightest.
_7segment.setDigit(0, 0, 0, false); // Initialize 1st digit from the right.
_7segment.setDigit(0, 1, 0, false); // Initialize 2nd digit from the right.
/* these digits are currently not used:
_7segment.setDigit(0, 2, 0, false);
_7segment.setDigit(0, 3, 0, false);
_7segment.setDigit(0, 4, 0, true);
_7segment.setDigit(0, 5, 0, false);
_7segment.setDigit(0, 6, 0, false);
_7segment.setDigit(0, 7, 0, false);
*/
}
void loop()
{
int temp = sensor.readTempOneShot(); // Start a conversion and store the resulting data.
// This IF statement solves the problem of the display getting stuck showing "00".
if (temp)
{
_7segment.setDigit(0, 0, (temp % 10), false); // write the lowest decimal digit to the 7-segments most-right digit.
_7segment.setDigit(0, 1, (temp / 10), false); // write the highest decimal digit to the next 7-segment digit.
}
else
{
Wire.endTransmission(0); // Close down the I2C bus.
Wire.begin(); // re-open the I2C bus.
}
}
But I am not happy with this, I want to display the value of °C to be displayed with at least 1 decimal value, preferably 2(I'm not sure I want 2 decimals but I would like to see what it looks like on the display, but 1 decimal is fine).
Does anyone know of a way to accomplish this?
I have been thinking about this for a week now and I simply can't manage to imagine a solution.
I really appreciate any and all inputs on this.