Yahoo refuse tous les emails du site. Si vous avez une adresse chez un autre prestataire, c'est le moment de l'utiliser
En cas de soucis, n'hésitez pas à aller faire un tour sur la page de contact en bas de page.
Topic "Convertisseur analogique numérique et masse positive"
Flux RSS des posts récents dans ce topic ( Flux Atom)
Bonsoir, depuis quelques temps dèjà, je cherche à obtenir des mesures de tensions à partir d'un régulateur de charge solaire. Mon montage est déjà réalisé ainsi que le code arduino. Le souci, c'est que la masse ou plutôt le commun du régulateur est la tension positive. Les résultats obtenus ne sont pas ceux attendus car j'ai contrôlé au voltmètre la tension en sortie des panneaux sur le régulateur. Y a t-il moyen d'obtenir les bonnes mesures connaissant ce problème de commun positif?
Cordialement, F. M.
Derniére modification le
#76 |
Bonjour,
Sans un schéma pour comprendre le montage de l'arduino et du régulateur, c'est compliqué de donner une quelconque solution
#81 |
et le code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | #include <SD.h>
#include <Wire.h>
#include <SPI.h>
#include "RTClib.h"
#include "Statistic.h"
// A simple data logger for the Arduino analog pins
// how many milliseconds between grabbing data and logging it. 1000 ms is once a second
#define LOG_INTERVAL 5000// mills between entries (reduce to take more/faster data)
#define ECHO_TO_SERIAL 1 // echo data to serial port
// The analog pins that connect to the sensors
const int analogInPinBat = A0; // Analog pin the battery voltage divider is attached to
const int analogInPinPanNeg = A1; //Analog pin the panel negative to ground voltage divider is attached to
//const int analogInPinPanPos = A2; //Analog pin the panel positive to ground voltage divider is attached to
//Ground is provided by the negative battery
const float Vcc = 4.91; // µC Vcc (V)
/*Voltage divider positive panel (Ohm)
const float R1 = 37000;
const float R2 = 13000; */
//Voltage divider negative panel (Ohm)
const float R3 = 37000;
const float R4 = 13000;
//Voltage divider battery (Ohm)
const float R5 = 27000;
const float R6 = 13000;
// the digital pins that connect to the LEDs
#define redLEDpin 2
#define greenLEDpin 3
RTC_DS1307 RTC; // define the Real Time Clock object
// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;
// the logging file
File logfile;
//the statistics
Statistic PanStats;
Statistic BatStats;
void error(char *str)
{
Serial.print("Erreur: ");
Serial.println(str);
// red LED indicates error
digitalWrite(redLEDpin, HIGH);
while(1);
}
void setup(void)
{
Serial.begin(9600);
Serial.println();
PanStats.clear(); //explicitly start clean
BatStats.clear();
// use debugging LEDs
pinMode(redLEDpin, OUTPUT);
pinMode(greenLEDpin, OUTPUT);
/*#if WAIT_TO_START
Serial.println("Type any character to start");
while (!Serial.available());
#endif //WAIT_TO_START
*/
// initialize the SD card
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
error("Card failed, or not present");
}
Serial.println("card initialized.");
//create a new file
char filename[] = "BATPAN00.CSV";
logfile = SD.open(filename, FILE_WRITE);
if (! logfile) {
error("couldnt create file");
}
Serial.print("Logging to: ");
Serial.println(filename);
// connect to RTC
Wire.begin();
if (!RTC.begin()) {
logfile.println("RTC failed");
#if ECHO_TO_SERIAL
Serial.println("RTC failed");
#endif //ECHO_TO_SERIAL
}
logfile.println("millis; date; VPan; VBAt");
logfile.println();
#if ECHO_TO_SERIAL
Serial.println("millis; date; VPan; VBAt");
Serial.println();
#endif //ECHO_TO_SERIAL
// If you want to set the aref to something other than 5v
//analogReference(EXTERNAL);
}
void loop(void)
{
DateTime now;
// delay for the amount of time we want between readings
delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
digitalWrite(greenLEDpin, HIGH);
// log milliseconds since starting
uint32_t m = millis();
#if ECHO_TO_SERIAL
Serial.print(m); // milliseconds since start
Serial.print("; ");
#endif
// fetch the time
now = RTC.now();
// log time in serial console
#if ECHO_TO_SERIAL
Serial.print(now.day(), DEC);
Serial.print("/");
Serial.print(now.month(), DEC);
Serial.print("/");
Serial.print(now.year(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
#endif //ECHO_TO_SERIAL
// read the analog in value:
/* analogRead(analogInPinPanPos);
delay(10);
int sensorValuePanPos = analogRead(analogInPinPanPos);*/
analogRead(analogInPinPanNeg);
delay(10);
int sensorValuePanNeg = analogRead(analogInPinPanNeg);
analogRead(analogInPinBat);
delay(10);
int sensorValueBat = analogRead(analogInPinBat);
/*float v_pinPanPos = Vcc*sensorValuePanPos/1023;
float v_PanPos = v_pinPanPos/(R2/(R1+R2));*/
float v_pinPanNeg = Vcc*sensorValuePanNeg/1023;
float v_PanNeg = v_pinPanNeg/(R4/(R3+R4));
float v_pinBat = Vcc*sensorValueBat/1023;
float v_Bat = v_pinBat/(R6/(R5+R6));
float v_Pan = (v_Bat - v_PanNeg) * ;
#if ECHO_TO_SERIAL
//for debugging
Serial.print("; ");
Serial.print(sensorValuePanPos);
Serial.print("; ");
Serial.print(sensorValuePanNeg);
Serial.print("; ");
Serial.print(sensorValueBat);
/*Serial.print("; ");
Serial.print(v_PanPos);*/
Serial.print("; ");
Serial.print(v_PanNeg);
Serial.print("; ");
Serial.print(v_Pan);
Serial.print("; ");
Serial.println(v_Bat);
#endif //ECHO_TO_SERIAL
delay(100);
digitalWrite(greenLEDpin, LOW);
PanStats.add(v_Pan);
BatStats.add(v_Bat);
if ((PanStats.count() == 120) && (BatStats.count() == 120))
{
// log time
logfile.print(now.day(), DEC);
logfile.print("/");
logfile.print(now.month(), DEC);
logfile.print("/");
logfile.print(now.year(), DEC);
logfile.print(" ");
logfile.print(now.hour(), DEC);
logfile.print(":");
logfile.print(now.minute(), DEC);
logfile.print(":");
logfile.print(now.second(), DEC);
//log data
logfile.print("; ");
logfile.print(PanStats.average(), 2);
logfile.print("; ");
logfile.println(BatStats.average(), 2);
logfile.println();
#if ECHO_TO_SERIAL
Serial.println("=====================================");
Serial.print(" Count: ");
Serial.println(PanStats.count());
Serial.print(" v_Pan Min: ");
Serial.println(PanStats.minimum(),2);
Serial.print(" v_Bat Min: ");
Serial.println(BatStats.minimum(),2);
Serial.print(" v_Pan Max: ");
Serial.println(PanStats.maximum(),2);
Serial.print(" v_Bat Max: ");
Serial.println(BatStats.maximum(),2);
Serial.print(" v_Pan Moyenne: ");
Serial.println(PanStats.average(), 2);
Serial.print(" v_Bat Moyenne: ");
Serial.println(BatStats.average(), 2);
Serial.println("=====================================");
Serial.println();
#endif // ECHO_TO_SERIAL
PanStats.clear();
BatStats.clear();
delay(10);
// blink LED to show we are syncing data to the card & updating FAT!
digitalWrite(redLEDpin, HIGH);
logfile.flush();
delay(500);
digitalWrite(redLEDpin, LOW);
}
}
|
Edit Skywodd : Je me suis permis de modifier ton message pour activer la coloration syntaxique du code
Derniére modification le
#83 |
Un CAN n'est pas un oscilloscope, les masses de chaque canal ne sont pas séparées.
En l'état, l'entrée B doit fonctionner car la masse du microcontrôleur est la même que celle du circuit.
Par contre, l'entrée A doit donner des résultats plus que faux. Je suis même étonné que le microcontrôleur n'est pas pris un coup de chaud.
Je vois que deux solutions possibles : relier les masses des panneaux solaires et de la batterie (si c'est possible) ou utiliser un CAN différentiel comme le MCP3425A0T-E/CH par exemple.