1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-10-27 05:51:51 +01:00

initial commit microcontroller unit (mcu) arduino sketch for the custom bluetooth scale.

This commit is contained in:
OliE
2014-12-13 16:54:05 +01:00
parent 45081b8f09
commit 9711f35e4f
36 changed files with 4875 additions and 0 deletions

View File

@@ -0,0 +1,132 @@
/*----------------------------------------------------------------------*
* Display the date and time from a DS3231 or DS3232 RTC every second. *
* Display the temperature once per minute. (The DS3231 does a *
* temperature conversion once every 64 seconds. This is also the *
* default for the DS3232.) *
* *
* Set the date and time by entering the following on the Arduino *
* serial monitor: *
* year,month,day,hour,minute,second, *
* *
* Where *
* year can be two or four digits, *
* month is 1-12, *
* day is 1-31, *
* hour is 0-23, and *
* minute and second are 0-59. *
* *
* Entering the final comma delimiter (after "second") will avoid a *
* one-second timeout and will allow the RTC to be set more accurately. *
* *
* No validity checking is done, invalid values or incomplete syntax *
* in the input will result in an incorrect RTC setting. *
* *
* Jack Christensen 08Aug2013 *
* *
* Tested with Arduino 1.0.5, Arduino Uno, DS3231/Chronodot, DS3232. *
* *
* This work is licensed under the Creative Commons Attribution- *
* ShareAlike 3.0 Unported License. To view a copy of this license, *
* visit http://creativecommons.org/licenses/by-sa/3.0/ or send a *
* letter to Creative Commons, 171 Second Street, Suite 300, *
* San Francisco, California, 94105, USA. *
*----------------------------------------------------------------------*/
#include <DS3232RTC.h> //http://github.com/JChristensen/DS3232RTC
#include <Streaming.h> //http://arduiniana.org/libraries/streaming/
#include <Time.h> //http://playground.arduino.cc/Code/Time
#include <Wire.h> //http://arduino.cc/en/Reference/Wire
void setup(void)
{
Serial.begin(115200);
//setSyncProvider() causes the Time library to synchronize with the
//external RTC by calling RTC.get() every five minutes by default.
setSyncProvider(RTC.get);
Serial << F("RTC Sync");
if (timeStatus() != timeSet) Serial << F(" FAIL!");
Serial << endl;
}
void loop(void)
{
static time_t tLast;
time_t t;
tmElements_t tm;
//check for input to set the RTC, minimum length is 12, i.e. yy,m,d,h,m,s
if (Serial.available() >= 12) {
//note that the tmElements_t Year member is an offset from 1970,
//but the RTC wants the last two digits of the calendar year.
//use the convenience macros from Time.h to do the conversions.
int y = Serial.parseInt();
if (y >= 100 && y < 1000)
Serial << F("Error: Year must be two digits or four digits!") << endl;
else {
if (y >= 1000)
tm.Year = CalendarYrToTm(y);
else //(y < 100)
tm.Year = y2kYearToTm(y);
tm.Month = Serial.parseInt();
tm.Day = Serial.parseInt();
tm.Hour = Serial.parseInt();
tm.Minute = Serial.parseInt();
tm.Second = Serial.parseInt();
t = makeTime(tm);
RTC.set(t); //use the time_t value to ensure correct weekday is set
setTime(t);
Serial << F("RTC set to: ");
printDateTime(t);
Serial << endl;
//dump any extraneous input
while (Serial.available() > 0) Serial.read();
}
}
t = now();
if (t != tLast) {
tLast = t;
printDateTime(t);
if (second(t) == 0) {
float c = RTC.temperature() / 4.;
float f = c * 9. / 5. + 32.;
Serial << F(" ") << c << F(" C ") << f << F(" F");
}
Serial << endl;
}
}
//print date and time to Serial
void printDateTime(time_t t)
{
printDate(t);
Serial << ' ';
printTime(t);
}
//print time to Serial
void printTime(time_t t)
{
printI00(hour(t), ':');
printI00(minute(t), ':');
printI00(second(t), ' ');
}
//print date to Serial
void printDate(time_t t)
{
printI00(day(t), 0);
Serial << monthShortStr(month(t)) << _DEC(year(t));
}
//Print an integer in "00" format (with leading zero),
//followed by a delimiter character to Serial.
//Input value assumed to be between 0 and 99.
void printI00(int val, char delim)
{
if (val < 10) Serial << '0';
Serial << _DEC(val);
if (delim > 0) Serial << delim;
return;
}

View File

@@ -0,0 +1,50 @@
/*
* TimeRTC.pde
* Example code illustrating Time library with Real Time Clock.
* This example is identical to the example provided with the Time Library,
* only the #include statement has been changed to include the DS3232RTC library.
*/
#include <DS3232RTC.h> //http://github.com/JChristensen/DS3232RTC
#include <Time.h> //http://www.arduino.cc/playground/Code/Time
#include <Wire.h> //http://arduino.cc/en/Reference/Wire (included with Arduino IDE)
void setup(void)
{
Serial.begin(9600);
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus() != timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
}
void loop(void)
{
digitalClockDisplay();
delay(1000);
}
void digitalClockDisplay(void)
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(' ');
Serial.print(day());
Serial.print(' ');
Serial.print(month());
Serial.print(' ');
Serial.print(year());
Serial.println();
}
void printDigits(int digits)
{
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(':');
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}

View File

@@ -0,0 +1,88 @@
/*----------------------------------------------------------------------*
* Digital clock display using a DS3231/32 Real-Time Clock *
* and an ATtiny45/85 with a 1MHz system clock. *
* Also seems to work with a DS1307 which is fairly similar but the *
* DS3232RTC library doesn't officially support it. *
* *
* Tested with Arduino 1.0.5. Also Arduino-Tiny Core, TinyISP, and *
* TinyDebugKnockBang from http://code.google.com/p/arduino-tiny/ *
* *
* Run TinyISP on an ATmega microcontroller that does not have an LED *
* connected to pin 13 (SCK). The LED causes problems because the SPI *
* pins are also the I2C pins on the ATtiny. Connect MISO, MOSI, SCK *
* on the ATmega to the corresponding pins on the ATtiny through 220Ω *
* resistors for safety. Use 4.7K pullup resistors on the ATtiny *
* I2C bus. *
* *
* Jack Christensen 21Aug2013 *
* *
* This work is licensed under the Creative Commons Attribution- *
* ShareAlike 3.0 Unported License. To view a copy of this license, *
* visit http://creativecommons.org/licenses/by-sa/3.0/ or send a *
* letter to Creative Commons, 171 Second Street, Suite 300, *
* San Francisco, California, 94105, USA. *
*----------------------------------------------------------------------*/
#include <DS3232RTC.h> //http://github.com/JChristensen/DS3232RTC
#include <Time.h> //http://playground.arduino.cc/Code/Time
#include <TinyDebugKnockBang.h> //http://code.google.com/p/arduino-tiny/
#include <TinyWireM.h> //http://playground.arduino.cc/Code/USIi2c
void setup(void)
{
Debug.begin(250000);
//setSyncProvider() causes the Time library to synchronize with the
//external RTC by calling RTC.get() every five minutes by default.
setSyncProvider(RTC.get);
Debug.print(F("RTC Sync"));
if (timeStatus() != timeSet) Debug.print(F(" FAIL!"));
Debug.println();
}
void loop(void)
{
static time_t tLast;
time_t t = now();
if (t != tLast) {
tLast = t;
printDateTime(t);
Debug.println();
}
}
//print date and time to Serial
void printDateTime(time_t t)
{
printDate(t);
Debug.print(' ');
printTime(t);
}
//print time to Serial
void printTime(time_t t)
{
printI00(hour(t), ':');
printI00(minute(t), ':');
printI00(second(t), ' ');
}
//print date to Serial
void printDate(time_t t)
{
printI00(day(t), 0);
Debug.print(monthShortStr(month(t)));
Debug.print(year(t), DEC);
}
//Print an integer in "00" format (with leading zero),
//followed by a delimiter character to Serial.
//Input value assumed to be between 0 and 99.
void printI00(int val, char delim)
{
if (val < 10) Debug.print('0');
Debug.print(val, DEC);;
if (delim > 0) Debug.print(delim);
return;
}