Difference between revisions of "Programming Power Fail Logger with Arduino IDE"

From media_wiki
Jump to: navigation, search
Line 4: Line 4:
 
'''Setting up the ATMega328 chip'''
 
'''Setting up the ATMega328 chip'''
 
   Plug the USBTiny Programmer into the AVR-ISP 6 pin header J7.
 
   Plug the USBTiny Programmer into the AVR-ISP 6 pin header J7.
 +
  Using AVRDUDE Validate the USBTiny is communicating with the Power Fail Module Microcontroller
 +
 
 +
  '''avrdude -c usbtiny -p m328p -v'''
 +
 
 
   The Microcontroller is set to 1HMz and needs to changed to '''16 MHz Default'''
 
   The Microcontroller is set to 1HMz and needs to changed to '''16 MHz Default'''
 
   Using AVRDude enter the follow command to set the fuse bits on the Microcontroller.
 
   Using AVRDude enter the follow command to set the fuse bits on the Microcontroller.

Revision as of 18:57, 25 May 2021

DS3231.PNG


Setting up the ATMega328 chip

 Plug the USBTiny Programmer into the AVR-ISP 6 pin header J7.
 Using AVRDUDE Validate the USBTiny is communicating with the Power Fail Module Microcontroller
 
 avrdude -c usbtiny -p m328p -v
 
 The Microcontroller is set to 1HMz and needs to changed to 16 MHz Default
 Using AVRDude enter the follow command to set the fuse bits on the Microcontroller.
 
 
 avrdude -p m328p -c usbtiny -v -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efuse:w:0xFF:m  
 
 For more information about using AVRDude refer back to this link 
 ==AVRDUDE Class==

Setting up the DS3231 RTC

 DS3231 RTC Datasheet: https://datasheets.maximintegrated.com/en/ds/DS3231.pdf
 Insert a coin cell battery into DS3231. Either CR2032 or LI2032 coin cell battery will work.
 Insert DS3231 module into the Power Logger PCB at J5. 

To Set the date and time use the follow program and paste in the Arduino IDE.

 //This code can be found here:https://github.com/rodan/ds3231
 #include <Wire.h>
 #include <ds3231.h>
 struct ts t; 
 void setup() {
 Serial.begin(9600);
 Wire.begin();
 DS3231_init(DS3231_CONTROL_INTCN);
 /*----------------------------------------------------------------------------
 In order to synchronise your clock module, insert timetable values below !
 ----------------------------------------------------------------------------*/
 t.hour=20; 
 t.min=40;
 t.sec=0;
 t.mday=11;
 t.mon=4;
 t.year=2021;
 DS3231_set(t); //Comment out after setting RTC with time & date
 }

 void loop() {
 DS3231_get(&t);
 Serial.print("Date : ");
 Serial.print(t.mon);
 Serial.print("/");
 Serial.print(t.mday);
 Serial.print("/");
 Serial.print(t.year);
 Serial.print("\t Hour : ");
 Serial.print(t.hour);
 Serial.print(":");
 Serial.println(t.min);
 Serial.print(":");
 Serial.println(t.sec);
 delay(60000);
 }
 void print2digits(int number){
 if (number >= 0 && number < 10) {
   Serial.write ('0');
 }
 Serial.print(number);
 } 

Connect the USBTinyISP to the AVR-ISP-6 pin header J7 on the Power Fail Logger PCB .
In the Arduino IDE click on Tools Tab - Select Programmer then select USBTinyISP.
In the Arduino IDE click on Sketch Tab - Select Upload Using Programmer
Program should download.


Power Fail Logger by Microrusty