Components and supplies
NEO 6M GPS MODULE
Pushbutton (single pole momentary 6m square)
15 way 0.1 inch sockets
4 way 0.1 inch pin strip
Arduino Nano R3
BI DIRECTIONAL LEVEL SHIFTER
4K7 resistors
Stripboard 24 strips * 37 columns
5 way 0.1 inch socket
6 way 0.1 inch sockets
I2C LCD BACKPACK
4 way 0.1 inch socket
LCD 16*2 DISPLAY
DS3231 clock module
Project description
Code
Set DS3231 code file
arduino
1// Date and time functions using a DS3231 RTC connected via I2C and Wire lib 2#include <Wire.h> 3#include "RTClib.h"//Aadafruit version 1.2.0 on my machine 4 5RTC_DS3231 RTC; 6 7char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 8const int days_string_length =12; 9 10//end of clock stuff 11 12//for lcd display 13//#include <Wire.h>//has already been included (above) 14// Get the LCD I2C Library here: 15// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads 16#include <LiquidCrystal_I2C.h> 17//Note the unusual address of 0x3F most lcd's use address of 0x27 so if you see nothing try altering that first 18LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address 19//end of for lcd display 20 21//for button 22#define button 9 23 24// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver 25// 26// This code shows how to listen to the GPS module in an interrupt 27// which allows the program to have more 'freedom' - just parse 28// when a new NMEA sentence is available! Then access data when 29// desired. 30// 31// Tested and works great with the Adafruit Ultimate GPS module 32// using MTK33x9 chipset 33// ------> http://www.adafruit.com/products/746 34// Pick one up today at the Adafruit electronics shop 35// and help support open source hardware & software! -ada 36 37#include <Adafruit_GPS.h> 38#include <SoftwareSerial.h> 39 40// If you're using a GPS module: 41// Connect the GPS Power pin to 5V 42// Connect the GPS Ground pin to ground 43// If using software serial (sketch example default): 44// Connect the GPS TX (transmit) pin to Digital 3 45// Connect the GPS RX (receive) pin to Digital 2 46// If using hardware serial (e.g. Arduino Mega): 47// Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3 48// Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3 49 50// If you're using the Adafruit GPS shield, change 51// SoftwareSerial mySerial(3, 2); -> SoftwareSerial mySerial(8, 7); 52// and make sure the switch is set to SoftSerial 53 54// If using software serial, keep this line enabled 55// (you can change the pin numbers to match your wiring): 56SoftwareSerial mySerial(3, 2); 57 58// If using hardware serial (e.g. Arduino Mega), comment out the 59// above SoftwareSerial line, and enable this line instead 60// (you can change the Serial number to match your wiring): 61 62//HardwareSerial mySerial = Serial1; 63 64 65Adafruit_GPS GPS(&mySerial); 66 67 68// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console 69// Set to 'true' if you want to debug and listen to the raw GPS sentences. 70#define GPSECHO false //--------->turned off 71 72// this keeps track of whether we're using the interrupt 73// off by default! 74boolean usingInterrupt = false; 75void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy 76 77void setup() 78{ 79 80 // connect at 115200 so we can read the GPS fast enough and echo without dropping chars 81 // also spit it out 82 Serial.begin(115200); 83 Serial.println("Adafruit GPS library basic test!"); 84 85 // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800 86 GPS.begin(9600); 87 88 // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude 89 GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); 90 // uncomment this line to turn on only the "minimum recommended" data 91 //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY); 92 // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since 93 // the parser doesn't care about other sentences at this time 94 95 // Set the update rate 96 GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate 97 // For the parsing code to work nicely and have time to sort thru the data, and 98 // print it out we don't suggest using anything higher than 1 Hz 99 100 // Request updates on antenna status, comment out to keep quiet 101 GPS.sendCommand(PGCMD_ANTENNA); 102 103 // the nice thing about this code is you can have a timer0 interrupt go off 104 // every 1 millisecond, and read data from the GPS for you. that makes the 105 // loop code a heck of a lot easier! 106 useInterrupt(true); 107 108 delay(1000); 109 // Ask for firmware version 110 mySerial.println(PMTK_Q_RELEASE); 111 112 113 //start lcd 114 lcd.begin(16,2); 115 lcd.backlight(); 116 lcd.clear(); 117 118 //setup button 119 pinMode(button,INPUT_PULLUP); 120 121 122} 123 124 125// Interrupt is called once a millisecond, looks for any new GPS data, and stores it 126SIGNAL(TIMER0_COMPA_vect) { 127 char c = GPS.read(); 128 // if you want to debug, this is a good time to do it! 129#ifdef UDR0 130 if (GPSECHO) 131 if (c) UDR0 = c; 132 // writing direct to UDR0 is much much faster than Serial.print 133 // but only one character can be written at a time. 134#endif 135} 136 137void useInterrupt(boolean v) { 138 if (v) { 139 // Timer0 is already used for millis() - we'll just interrupt somewhere 140 // in the middle and call the "Compare A" function above 141 OCR0A = 0xAF; 142 TIMSK0 |= _BV(OCIE0A); 143 usingInterrupt = true; 144 } else { 145 // do not call the interrupt function COMPA anymore 146 TIMSK0 &= ~_BV(OCIE0A); 147 usingInterrupt = false; 148 } 149} 150 151uint32_t timer = millis(); 152void loop() // run over and over again 153{ 154 // in case you are not using the interrupt above, you'll 155 // need to 'hand query' the GPS, not suggested :( 156 if (! usingInterrupt) { 157 // read data from the GPS in the 'main loop' 158 char c = GPS.read(); 159 // if you want to debug, this is a good time to do it! 160 if (GPSECHO) 161 if (c) Serial.print(c); 162 } 163 164 // if a sentence is received, we can check the checksum, parse it... 165 if (GPS.newNMEAreceived()) { 166 // a tricky thing here is if we print the NMEA sentence, or data 167 // we end up not listening and catching other sentences! 168 // so be very wary if using OUTPUT_ALLDATA and trytng to print out data 169 //Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false 170 171 if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false 172 return; // we can fail to parse a sentence in which case we should just wait for another 173 } 174 175 // if millis() or timer wraps around, we'll just reset it 176 if (timer > millis()) timer = millis(); 177 178static bool second_time_round=false; 179 180 // approximately every 2 seconds or so, print out the current stats 181 //if (millis() - timer > 2000) { 182 // timer = millis(); // reset the timer 183 184 //Write data to clock if button pressed - button normally held high by internal pullup 185 if(!digitalRead(button)){ 186 187//Note: RTClib does not explicitly set day of the week register on DS3231. 188//Instead when you use dayOfTheWeek() the day is calculated by a formula based on the date. 189//Sunday is taken to be zero. 190//(based on my reading of the library header and ccp files) 191 192 //set rtc 193 RTC.adjust(DateTime(GPS.year, GPS.month, GPS.day, GPS.hour, GPS.minute, GPS.seconds)); 194 195 196 //lcd 197 lcd.clear(); 198 lcd.setCursor(2,0); 199 lcd.print("Pressed set"); 200 delay(5000); 201 lcd.clear(); 202 203 } 204 205 DateTime now = RTC.now(); 206 207 lcd.setCursor(4,0); 208 lcd.print(now.year(), DEC); 209 lcd.print('/'); 210 lcd.print(now.month(), DEC); 211 lcd.print('/'); 212 lcd.print(now.day(), DEC); 213 lcd.print(' '); 214 lcd.setCursor(4,1); 215 lcd.print(now.hour(), DEC); 216 lcd.print(':'); 217 lcd.print(now.minute(), DEC); 218 lcd.print(':'); 219 lcd.print(now.second(), DEC); 220 lcd.print(" "); 221 222} 223 224
Set DS3231 code file
arduino
1// Date and time functions using a DS3231 RTC connected via I2C and Wire 2 lib 3#include <Wire.h> 4#include "RTClib.h"//Aadafruit version 1.2.0 on my 5 machine 6 7RTC_DS3231 RTC; 8 9char daysOfTheWeek[7][12] = {"Sunday", "Monday", 10 "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 11const int 12 days_string_length =12; 13 14//end of clock stuff 15 16//for lcd display 17//#include 18 <Wire.h>//has already been included (above) 19// Get the LCD I2C Library here: 20 21// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads 22#include 23 <LiquidCrystal_I2C.h> 24//Note the unusual address of 0x3F most lcd's use address 25 of 0x27 so if you see nothing try altering that first 26LiquidCrystal_I2C lcd(0x3F, 27 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address 28//end of for lcd 29 display 30 31//for button 32#define button 9 33 34// Test code for Adafruit 35 GPS modules using MTK3329/MTK3339 driver 36// 37// This code shows how to listen 38 to the GPS module in an interrupt 39// which allows the program to have more 'freedom' 40 - just parse 41// when a new NMEA sentence is available! Then access data when 42// 43 desired. 44// 45// Tested and works great with the Adafruit Ultimate GPS module 46// 47 using MTK33x9 chipset 48// ------> http://www.adafruit.com/products/746 49// 50 Pick one up today at the Adafruit electronics shop 51// and help support open 52 source hardware & software! -ada 53 54#include <Adafruit_GPS.h> 55#include <SoftwareSerial.h> 56 57// 58 If you're using a GPS module: 59// Connect the GPS Power pin to 5V 60// Connect 61 the GPS Ground pin to ground 62// If using software serial (sketch example default): 63// 64 Connect the GPS TX (transmit) pin to Digital 3 65// Connect the GPS RX (receive) 66 pin to Digital 2 67// If using hardware serial (e.g. Arduino Mega): 68// Connect 69 the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3 70// Connect the GPS RX 71 (receive) pin to matching TX1, TX2 or TX3 72 73// If you're using the Adafruit 74 GPS shield, change 75// SoftwareSerial mySerial(3, 2); -> SoftwareSerial mySerial(8, 76 7); 77// and make sure the switch is set to SoftSerial 78 79// If using software 80 serial, keep this line enabled 81// (you can change the pin numbers to match your 82 wiring): 83SoftwareSerial mySerial(3, 2); 84 85// If using hardware serial (e.g. 86 Arduino Mega), comment out the 87// above SoftwareSerial line, and enable this 88 line instead 89// (you can change the Serial number to match your wiring): 90 91//HardwareSerial 92 mySerial = Serial1; 93 94 95Adafruit_GPS GPS(&mySerial); 96 97 98// Set GPSECHO 99 to 'false' to turn off echoing the GPS data to the Serial console 100// Set to 'true' 101 if you want to debug and listen to the raw GPS sentences. 102#define GPSECHO false 103 //--------->turned off 104 105// this keeps track of whether we're using the interrupt 106// 107 off by default! 108boolean usingInterrupt = false; 109void useInterrupt(boolean); 110 // Func prototype keeps Arduino 0023 happy 111 112void setup() 113{ 114 115 116 // connect at 115200 so we can read the GPS fast enough and echo without dropping 117 chars 118 // also spit it out 119 Serial.begin(115200); 120 Serial.println("Adafruit 121 GPS library basic test!"); 122 123 // 9600 NMEA is the default baud rate for Adafruit 124 MTK GPS's- some use 4800 125 GPS.begin(9600); 126 127 // uncomment this line 128 to turn on RMC (recommended minimum) and GGA (fix data) including altitude 129 GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); 130 131 // uncomment this line to turn on only the "minimum recommended" data 132 //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY); 133 134 // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA 135 since 136 // the parser doesn't care about other sentences at this time 137 138 139 // Set the update rate 140 GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 141 Hz update rate 142 // For the parsing code to work nicely and have time to sort 143 thru the data, and 144 // print it out we don't suggest using anything higher than 145 1 Hz 146 147 // Request updates on antenna status, comment out to keep quiet 148 149 GPS.sendCommand(PGCMD_ANTENNA); 150 151 // the nice thing about this code is 152 you can have a timer0 interrupt go off 153 // every 1 millisecond, and read data 154 from the GPS for you. that makes the 155 // loop code a heck of a lot easier! 156 157 useInterrupt(true); 158 159 delay(1000); 160 // Ask for firmware version 161 162 mySerial.println(PMTK_Q_RELEASE); 163 164 165 //start lcd 166 lcd.begin(16,2); 167 168 lcd.backlight(); 169 lcd.clear(); 170 171 //setup button 172 pinMode(button,INPUT_PULLUP); 173 174 175 176} 177 178 179// Interrupt is called once a millisecond, looks for any new 180 GPS data, and stores it 181SIGNAL(TIMER0_COMPA_vect) { 182 char c = GPS.read(); 183 184 // if you want to debug, this is a good time to do it! 185#ifdef UDR0 186 if 187 (GPSECHO) 188 if (c) UDR0 = c; 189 // writing direct to UDR0 is much much 190 faster than Serial.print 191 // but only one character can be written at a time. 192 193#endif 194} 195 196void useInterrupt(boolean v) { 197 if (v) { 198 // Timer0 199 is already used for millis() - we'll just interrupt somewhere 200 // in the middle 201 and call the "Compare A" function above 202 OCR0A = 0xAF; 203 TIMSK0 |= 204 _BV(OCIE0A); 205 usingInterrupt = true; 206 } else { 207 // do not call the 208 interrupt function COMPA anymore 209 TIMSK0 &= ~_BV(OCIE0A); 210 usingInterrupt 211 = false; 212 } 213} 214 215uint32_t timer = millis(); 216void loop() // 217 run over and over again 218{ 219 // in case you are not using the interrupt above, 220 you'll 221 // need to 'hand query' the GPS, not suggested :( 222 if (! usingInterrupt) 223 { 224 // read data from the GPS in the 'main loop' 225 char c = GPS.read(); 226 227 // if you want to debug, this is a good time to do it! 228 if (GPSECHO) 229 230 if (c) Serial.print(c); 231 } 232 233 // if a sentence is received, 234 we can check the checksum, parse it... 235 if (GPS.newNMEAreceived()) { 236 // 237 a tricky thing here is if we print the NMEA sentence, or data 238 // we end up 239 not listening and catching other sentences! 240 // so be very wary if using 241 OUTPUT_ALLDATA and trytng to print out data 242 //Serial.println(GPS.lastNMEA()); 243 // this also sets the newNMEAreceived() flag to false 244 245 if (!GPS.parse(GPS.lastNMEA())) 246 // this also sets the newNMEAreceived() flag to false 247 return; // we 248 can fail to parse a sentence in which case we should just wait for another 249 } 250 251 252 // if millis() or timer wraps around, we'll just reset it 253 if (timer > millis()) 254 timer = millis(); 255 256static bool second_time_round=false; 257 258 // approximately 259 every 2 seconds or so, print out the current stats 260 //if (millis() - timer > 261 2000) { 262 // timer = millis(); // reset the timer 263 264 //Write data to 265 clock if button pressed - button normally held high by internal pullup 266 if(!digitalRead(button)){ 267 268//Note: 269 RTClib does not explicitly set day of the week register on DS3231. 270//Instead 271 when you use dayOfTheWeek() the day is calculated by a formula based on the date. 272 273//Sunday is taken to be zero. 274//(based on my reading of the library header 275 and ccp files) 276 277 //set rtc 278 RTC.adjust(DateTime(GPS.year, 279 GPS.month, GPS.day, GPS.hour, GPS.minute, GPS.seconds)); 280 281 282 283 //lcd 284 lcd.clear(); 285 lcd.setCursor(2,0); 286 287 lcd.print("Pressed set"); 288 delay(5000); 289 lcd.clear(); 290 291 292 } 293 294 DateTime now = RTC.now(); 295 296 lcd.setCursor(4,0); 297 298 lcd.print(now.year(), DEC); 299 lcd.print('/'); 300 lcd.print(now.month(), 301 DEC); 302 lcd.print('/'); 303 lcd.print(now.day(), DEC); 304 lcd.print(' 305 '); 306 lcd.setCursor(4,1); 307 lcd.print(now.hour(), DEC); 308 lcd.print(':'); 309 310 lcd.print(now.minute(), DEC); 311 lcd.print(':'); 312 lcd.print(now.second(), 313 DEC); 314 lcd.print(" "); 315 316} 317 318
Downloadable files
Stripboard diagram
Stripboard diagram
Wiring Diagram
Wiring Diagram
Stripboard diagram
Stripboard diagram
Comments
Only logged in users can leave comments
glennedi
0 Followers
•0 Projects
0