SparkFun Forums 

Where electronics enthusiasts find answers.

General project discussion area - What have you built with your Micro View

Moderators: marcus@geekammo, Help@GeekAmmo

User avatar
By kgrr
#173852
MicroView -- DS1307 Real Time Clock

Pin 2 SCL -- SCL
Pin 3 SDA -- SDA
Pin 8 GND -- GND
Pin 15 +5V -- +5V

To verify the Real Time Clock chip is correctly hooked-up, run the I2C Scanner sketch. It will show one, two, sometimes three I2C bus addresses in use.

The DS1307 address is 0x68.
Some boards have an EEPROM built on the board The 24C32's address is 0x50.
Some boards also have a DS18B20 one wire interface. Its address is 0x20.

https://codebender.cc/sketch:43470
Last edited by kgrr on Sat Aug 23, 2014 6:04 pm, edited 5 times in total.
User avatar
By kgrr
#173885
I wonder where the clock Widget used in the "Getting Started" http://learn.microview.io/intro/getting-started.html article went to?

Image

...just a thought:

Maybe the Gauge Widget class needs to be refactored to be a round indicator class that has more "child classes" besides gauges. That round indicator class would include dials, clocks, compass roses and pi charts, etc. (these go 360 degrees around instead of 240) Besides different faces, some simply need different pointers (like the compass and pi chart), some may need need multiple pointers like clocks.

For example ...
round indicator has a face and multiple pointers

- a gauge has a 140 degree face marked min value to max value and a single pointer (value)
- a dial has a 360 degree face marked min value to max value and a single pointer (value)
- a compass has a 360 degree face marked N, E, S, W at major ticks at 90 degrees, and minor ticks at 30 deg and a single pointer (degrees)
- a clock has a 360 degree face and three pointers (seconds, minutes and hours)
- a pie chart has a 360 degree face and N pie shaped pointers.
... etc.
User avatar
By kgrr
#173921
Here is a sketch for MicroView that shows the time on the first line and the date on the second line:
Code: Select all
#include <MicroView.h>
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC; // creates an instance of RTC

void setup () {
	Wire.begin();
	RTC.begin();

	if (! RTC.isrunning()) {
		//The following line sets the RTC to the date & time this sketch was compiled
		RTC.adjust(DateTime(__DATE__, __TIME__));
	}

	uView.begin();	// init and start MicroView
	uView.clear(PAGE);	// erase the memory buffer
}

void loop () {
	int i;

	DateTime now = RTC.now();

	uView.setFontType(0); // set font type 1

	uView.setCursor(0,0); // points cursor to first line
	i = now.hour();
	if (i<10) uView.print("0");
	uView.print(i, DEC);
	uView.print(":");
	i = now.minute();
	if (i<10) uView.print("0");
	uView.print(i, DEC);
	uView.print(":");
	i = now.second();
	if (i<10) uView.print("0");
	uView.print(i, DEC);

	uView.setCursor(0,16); // points cursor to second line
	i = now.month();
	if (i<10) uView.print("0");
	uView.print(i, DEC);
	uView.print('/');
	i = now.day();
	if (i<10) uView.print("0");
	uView.print(i, DEC);
    uView.print('/');
	uView.print(now.year(), DEC);
	uView.display();

	delay(600);
}
https://codebender.cc/sketch:44456

Image
Last edited by kgrr on Sat Aug 23, 2014 11:29 am, edited 1 time in total.
User avatar
By kgrr
#174053
This sketch gives Microview an analog face just like the one in the demo.
Code: Select all
#include <MicroView.h>
#include <Wire.h>
#include "RTClib.h"

//Instantiate objects from class definitions
RTC_DS1307 RTC;

void setup () {
	Wire.begin();
    RTC.begin();
 
    if (! RTC.isrunning()) {
        //The following line sets the RTC to the date & time this sketch was compiled
        RTC.adjust(DateTime(__DATE__, __TIME__));
    }
  
    uView.begin();		// init and start MicroView
  
    uView.clear(PAGE);	// erase the display memory buffer
}
 
void loop() {
	int clocksize = 24;

	static uint8_t x0,y0,x1,y1;
	static float radianshour,radiansmin,radianssec,hourx,houry,minx,miny,secx,secy;
	static boolean drawnFirst=false;

	uView.setFontType(0); 		// set font type 0, please see declaration in MicroView.cpp
	uView.setCursor(27,0);		// points cursor to x=27 y=0
	
	// Draw face
	uView.print(12);			
	uView.setCursor(30,uView.getLCDHeight()-uView.getFontHeight());
	uView.print(6);
	uView.setCursor(0,uView.getLCDHeight() /2-(uView.getFontHeight()/2));
	uView.print(9);
	uView.setCursor(uView.getLCDWidth()-uView.getFontWidth(),uView.getLCDHeight()/2-(uView.getFontHeight()/2));
	uView.print(3);
	uView.display();			// display the memory buffer drawn
	
	if (drawnFirst) {
		uView.line(32,24,32+hourx,24+houry,WHITE,XOR);
		uView.line(32,24,32+minx,24+miny,WHITE,XOR);
		uView.line(32,24,32+secx,24+secy,WHITE,XOR);
	} 
	
	// get the time from the clock chip
	DateTime now = RTC.now();
	
	// convert hms into radians
	radianshour = (((now.hour() * 360) / 12) + 270) * (PI / 180);
	radiansmin = (((now.minute() * 360) / 60) + 270) * (PI / 180);
	radianssec = (((now.second() * 360) / 60) + 270) * (PI / 180);
		
       // calculate clock hand endpoints		
	hourx = cos(radianshour) * (clocksize / 2.5);
	houry = sin(radianshour) * (clocksize / 2.5);

	minx = cos(radiansmin) * (clocksize / 1.4);
	miny = sin(radiansmin) * (clocksize / 1.4);

	secx = cos(radianssec) * (clocksize / 1.1);
	secy = sin(radianssec) * (clocksize / 1.1);
			
	// draw the clock face		
	uView.line(32,24,32+hourx,24+houry,WHITE,XOR);
	uView.line(32,24,32+minx,24+miny,WHITE,XOR);
	uView.line(32,24,32+secx,24+secy,WHITE,XOR);
	
	drawnFirst=true;
	uView.display();
			
	drawnFirst=false;
	uView.clear(PAGE);
}
https://codebender.cc/sketch:45433

Image