Components and supplies
Arduino Mega 2560
Arduino Mega Proto Shield
Tools and machines
Dagoma Disco Easy 200
Project description
Code
SunPowerOnly.ino
arduino
Code extracted from the main program of my weather station. Building successful but could hold some useless lines
1#include <SPI.h> 2#include <SD.h> 3#include <Wire.h> 4#define DS1307_I2C_ADDRESS 0x68 5#define dataPin 5 6#define clockPin 4 7 8volatile int top, top60, top10, Count_Rain, topD; 9volatile float SunPower, SunPowerInt, varCompteur; 10 11float SunPowerAvg, temperature, humidity, dewpoint, pressure,SunPowerMin, SunPowerMax, voltage, angle; 12const int chipSelect = 10, LedOnTimeRTC = 20, LedOnTimeWIND = 10; 13byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; 14String File_record = "Test341A", Dir; 15 16//------------------------------------------------------------------------------------------------------------------------ 17void setup () 18{ 19 Serial.begin(9600); 20 21 Serial.print("Version: "); Serial.println(File_record); 22 Serial.println("Initializing SD card..."); 23 if (!SD.begin(chipSelect)) {Serial.println("Card failed, or not present");return;} 24 Serial.println("card initialized."); 25 26 File dataFile = SD.open(File_record, FILE_WRITE); 27 if (dataFile) { dataFile.println("Date ; Heure ; Max Speed ; Average speed ; Rafale ; Direction ; SunPowerAvg; SunPowerMin; SunPowerMax; Rain Level; Temperature ; Humidity ; Dewpoint; Pressure; Lux Avg; Lux Min; Lux Max; Index_day; Index_Hour; glitch; AvgWSFS; MxWSFS; altFOV10; tObjetFOV10; AmbientFOV10; MaxtObjetFOV10; altFOV90; tObjetFOV90; AmbienFOV90; MaxtObjetFOV90; Version; File"); dataFile.close();} 28 29 30 attachInterrupt (digitalPinToInterrupt(18), Flash_RTC , RISING ); // SQW RTC 31 32 33 Wire.begin(); // Join i2c bus for TSL2561 , MPL3115A2 & DS1307 34 Wire.beginTransmission(DS1307_I2C_ADDRESS); 35 Wire.write(0x07); 36 Wire.write(0x10); 37 Wire.endTransmission(); 38 39 TCCR3A = 0b00000001; 40 TCCR3B = 0b00000001; //no prescaling => period 1micro-s 41 TIFR3 = 0b00000001; 42 43 44 // Delai de synchronisation sur la minute pleine------------------------------------------------------------------------ 45 46 do {getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); top = -1;} while(second != 0); 47 48 top10 = 0 ; 49 top60 = 0 ; 50 51} 52 53//------------------------------------------------------------------------------------------------------------------------ 54//------------------------------------------------------------------------------------------------------------------------ 55// BOUCLE PRINCIPALE 56//------------------------------------------------------------------------------------------------------------------------ 57//------------------------------------------------------------------------------------------------------------------------ 58void loop () 59{ 60 61 if (bitRead (TIFR3, 0) == 1) {bitSet (TIFR3, TOV3) ; varCompteur++ ;} 62 63 SunPower = (analogRead(A1) * (5.0 / 1023.0)) * 698; 64 65 if ( top == 600 ) 66 { 67 getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); 68 Serial.print(minute);Serial.print(":");Serial.println(second); 69 SunPowerAvg = SunPowerInt / 600; 70 RECORD(); 71 } 72 73} 74 75 76void Flash_RTC () 77{ 78 79 top = top + 1; 80 top60 = top60 + 1; 81 top10 = top10 +1; 82 83 SunPowerInt = SunPowerInt + SunPower; 84 if (SunPower > SunPowerMax) {SunPowerMax = SunPower;} else {SunPowerMax = SunPowerMax;} 85 if (SunPower < SunPowerMin) {SunPowerMin = SunPower;} else {SunPowerMin = SunPowerMin;} 86 87} 88 89 90byte bcdToDec(byte val) 91{ return ( (val/16*10) + (val%16) );} 92 93void getDateDs1307(byte *second,byte *minute,byte *hour,byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year) //--- 94{ 95 Wire.beginTransmission(DS1307_I2C_ADDRESS); 96 Wire.write(0); 97 Wire.endTransmission(); 98 Wire.requestFrom(DS1307_I2C_ADDRESS, 7); 99 100 *second = (bcdToDec(Wire.read() & 0x7f)); 101 *minute = (bcdToDec(Wire.read())); 102 *hour = (bcdToDec(Wire.read() & 0x3f)); // Need to change this if 12 hour am/pm 103 *dayOfWeek = bcdToDec(Wire.read()); 104 *dayOfMonth = bcdToDec(Wire.read()); 105 *month = bcdToDec(Wire.read()); 106 *year = bcdToDec(Wire.read()); 107} 108 109 110void RECORD() 111 112{ 113 File dataFile = SD.open(File_record, FILE_WRITE); 114 115 Serial.print(hour);Serial.print(":");Serial.print(minute);Serial.print(":");Serial.print(second);Serial.print(" <> "); 116 Serial.print(SunPowerAvg);Serial.print(" <> "); 117 Serial.print(SunPowerMin);Serial.print(" <> "); 118 Serial.print(SunPowerMax);Serial.print(" <> "); 119 Serial.println(File_record); 120 121 if (dataFile) 122 { 123 dataFile.print(dayOfMonth);dataFile.print("/");dataFile.print(month);dataFile.print("/");dataFile.print(year);dataFile.print(" ; "); 124 dataFile.print(hour);dataFile.print(":");dataFile.print(minute);dataFile.print(":");dataFile.print(second);dataFile.print(" ; "); 125 dataFile.print(SunPowerAvg,0) ;dataFile.print(" ; "); 126 dataFile.print(SunPowerMin,0) ;dataFile.print(" ; "); 127 dataFile.print(SunPowerMax,0) ;dataFile.print(" ; "); 128 dataFile.println(File_record );dataFile.close(); 129 } 130 131 132} 133
Downloadable files
Electrical Diagram
Electrical Diagram
Electrical Diagram
Electrical Diagram
Documentation
Technical Drawing
All parts are PLA 3D printing
Technical Drawing
Technical Drawing
All parts are PLA 3D printing
Technical Drawing
Comments
Only logged in users can leave comments