Forum: Mikrocontroller und Digitale Elektronik Arduino sketch


von Hamster Hermann (Gast)


Lesenswert?

Hallo Leute ich brauche hilfe bei einem sketch für einen Wetterballon 
Datenlogger.Als erstes habe ich die Libary für den Sensor BMP180 
instaliert
und sann nochmal und nochmal.Resultat: Es funktioniert noch immer nicht.
Hier der sketch:
1
#include <SFE_BMP180.h>
2
3
/*
4
5
6
7
8
 * analog sensors on analog ins 0, 1, 
9
 * SD card attached to SPI bus as follows:
10
 ** MOSI - pin 11
11
 ** MISO - pin 12
12
 ** CLK - pin 13
13
 ** CS - pin 4 (digital assigned via setup)
14
 ** VCC & Ground
15
 -------------------------------------------------------------------
16
 V2- 
17
 Adding RTC support
18
 RTC Connected to VCC and Ground
19
 I2C Connections:
20
 RTC SDA connected to pin Analog 4
21
 RTC SCL connected to pin Analog 5
22
23
Used I2CScanner.ino to find I2C addresses- 0x50 (EEPROM?)  and 0x68 found
24
Used SetRTC.ino to manually set proper date/date on RTC module- This wil set the date/time as soon as serial 
25
 is initiated so set ahead by a minute and wait till time matches then open serial window to set.
26
----------------------------------------------------------------------- 
27
V3-
28
Added Adafruit 992- MPL115A2 Baro/Temp Sensor 5volt 12C device
29
SDA connected to pin Analog 4
30
SCL connected to pin Analog 5
31
Code below should be optimized to avoid multiple I2C calls
32
33
Added Battery Voltage Monitoring:
34
Changed A0 to be used for Bus Voltage monitoring (on board LiPo)
35
Will use voltage divider with 2 10Kohm resistores to monitor the 7.4V supply from battery
36
http://forum.arduino.cc/index.php/topic,13728.0.html
37
Testing- Ran solid 15 hours no issues, 47000 lines recorded, Filesize 2.1MB
38
-----------------------------------------------------------------------
39
V4
40
Added output for altitude in meters (Thanks Jon)
41
http://forum.arduino.cc/index.php?topic=63726.0
42
Used static value of 15 for Temp as using actual temp causes unreliable values indoors 
43
44
------------------------------------------------------------------------
45
V5
46
Added code for LM35 Temp sensor (Will be internal monitoring) on A1 data2 and temp variables
47
Had to do 2 analog reads to debounce the values with a small delay.
48
Added Bluetooth- shortened serial write text to fit phone screen
49
W
50
----------------------------------------------------------------------
51
*/
52
#include <SFE_BMP180>// Support for Sensor BMP180
53
Adafruit_SFE BMP180//Support for BMP 180#include "Wire.h"
54
#define DS1307_ADDRESS 0x68//RTC Support
55
//Eric Note- another address showed up in scan at 0X50 EEPROM?
56
byte zero = 0x00; //workaround for issue #527 RTC Support
57
58
const float referenceVolts = 5.0;        // the default reference on a 5 volt board 
59
const int batteryPin = 0;          // +V from battery is connected to analog pin 0
60
const float sea_press = 1013.25;//added for altitude calc
61
float alt=0;//added for altitude calc
62
63
#include <SD.h>
64
File myFile; //SD
65
const int chipSelect=4; // set chipselect pin to 4 for SD
66
//int dat1=A0;//set data pin
67
int dat2=1;//define pin0 connect with LM35
68
float temp=0;
69
//int data1=0;
70
int data2=0;
71
int i=0;
72
boolean present=0;// SD Card available & usable
73
void setup()
74
{
75
76
  Wire.begin(); 
77
  Serial.begin(9600);
78
  mpl115a2.begin();// Baro Sensor Adafruit 992- MPL115A2
79
  //pinMode(dat1,INPUT);
80
  pinMode(dat2,INPUT);
81
  checkSD();
82
  // Write column headers for Excel CSV
83
  myFile = SD.open("datalog.csv", FILE_WRITE);
84
  if(myFile)
85
  {
86
    //Prints headers to file
87
    myFile.print("Time"); // Prints Date and Time header
88
    myFile.print(",");
89
    myFile.print("line#");// prints line number Header for troubleshooting etc
90
    myFile.print(",");
91
    myFile.print("BusVoltage");
92
    myFile.print(",");
93
    myFile.print("IntTemp");
94
    myFile.print(",");
95
    myFile.print("Pressure");
96
    myFile.print(",");
97
    myFile.print("ExtTemp");
98
    myFile.print(",");
99
    myFile.println("Alt(m)");
100
    myFile.close();
101
102
  }
103
}
104
void loop()
105
{
106
  int val = analogRead(batteryPin);  // read the value from the A0 battery monitoring pin with voltage divider
107
  float volts = (val / 511.0) * referenceVolts ; // divide val by (1023/2)because the resistors divide the voltage in half
108
109
  float pressureKPA = 0, temperatureC = 0; //Adafruit 992- MPL115A2
110
  if(present==1)
111
  {
112
    pressureKPA = mpl115a2.getPressure();//get pressure Adafruit 992- MPL115A2
113
    temperatureC = mpl115a2.getTemperature(); //Adafruit 992- MPL115A2
114
    printDate(); //Runs the print date subroutine below
115
    i++;
116
    //data1=analogRead(dat1);
117
  analogRead(1);// added to take initial read to stabilize the ADC
118
  delay(10);// Delay to stabilize the ADC
119
  temp = analogRead(1) * 5000L / 1024L  / 10;// Temperature calculation formula
120
    //data2=analogRead(dat2); //used for Ext Temp sensor TBD
121
    //temp= data2 * 4.9 / 10 ; // Temperature calculation formula
122
    Serial.print(" BusV:");
123
    Serial.print(volts);
124
    Serial.print(" ITemp:");
125
    Serial.print(temp);
126
     Serial.print(" Press:");
127
    Serial.print(pressureKPA, 4);
128
    Serial.print(" ExTemp:");
129
    Serial.print(temperatureC, 1);
130
    alt= ((pow((sea_press / (pressureKPA *10)), 1/5.257) - 1.0) * (15 + 273.15)) / 0.0065;//rough altitude equation in meters can use real temp instead of 15
131
    Serial.print(" Alt:");
132
    Serial.println(alt);
133
    writeSD();
134
  }
135
  delay(1000);
136
  }
137
138
byte decToBcd(byte val){     //Eric-      needed for RTC variable stuff
139
// Convert normal decimal numbers to binary coded decimal
140
  return ( (val/10*16) + (val%10) );
141
}
142
143
byte bcdToDec(byte val)  {    //Eric-      needed for RTC variable stuff
144
// Convert binary coded decimal to normal decimal numbers
145
  return ( (val/16*10) + (val%16) );
146
}
147
148
void checkSD()
149
{
150
  Serial.print("check SD card");
151
  if (!SD.begin(chipSelect)) {
152
    Serial.println("Card failed");
153
    // don't do anything more:
154
    return;
155
  }
156
  Serial.println("SD card OK");
157
  present=1;
158
  delay(2000);
159
}
160
161
void writeSD()
162
{
163
  myFile = SD.open("datalog.csv", FILE_WRITE);
164
  if(myFile)
165
  {
166
    int val = analogRead(batteryPin);  // read the value from the A0 battery monitoring pin with voltage divider
167
  float volts = (val / 511.0) * referenceVolts ; // divide val by (1023/2)because the resistors divide the voltage in half
168
    // Reset the register pointer
169
  Wire.beginTransmission(DS1307_ADDRESS);
170
  Wire.write(zero);
171
  Wire.endTransmission();
172
173
  Wire.requestFrom(DS1307_ADDRESS, 7);
174
175
  int second = bcdToDec(Wire.read());
176
  int minute = bcdToDec(Wire.read());
177
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
178
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
179
  int monthDay = bcdToDec(Wire.read());
180
  int month = bcdToDec(Wire.read());
181
  int year = bcdToDec(Wire.read());
182
float pressureKPA = mpl115a2.getPressure();//get pressure Adafruit 992- MPL115A2- these are redundant calls to I2c but I dont want to fix
183
float temperatureC = mpl115a2.getTemperature();//get temp Adafruit 992- MPL115A2- these are redundant calls to I2c but I dont want to fix
184
185
  //Print RTC values to SD
186
  myFile.print(month);
187
  myFile.print("/");
188
  myFile.print(monthDay);
189
  myFile.print("/");
190
  myFile.print(year);
191
  myFile.print(" ");
192
  myFile.print(hour);
193
  myFile.print(":");
194
  myFile.print(minute);
195
  myFile.print(":");
196
  myFile.print(second);
197
  //myFile.print(":");
198
  myFile.print(",");
199
  //End Print RTC values
200
    myFile.print(i);
201
    myFile.print(",");
202
    myFile.print(volts);
203
    myFile.print(",");
204
    myFile.print(temp);
205
    myFile.print(",");
206
    myFile.print(pressureKPA, 4);
207
    myFile.print(",");
208
    myFile.print(temperatureC, 1);
209
    myFile.print(",");
210
    myFile.println(alt);
211
    myFile.close();
212
213
  }
214
}
215
216
  void printDate()// Only used to print to serial and not needed for logging purposes
217
  {
218
  Wire.beginTransmission(DS1307_ADDRESS);
219
  Wire.write(zero);
220
  Wire.endTransmission();
221
222
  Wire.requestFrom(DS1307_ADDRESS, 7);
223
224
  int second = bcdToDec(Wire.read());
225
  int minute = bcdToDec(Wire.read());
226
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
227
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
228
  int monthDay = bcdToDec(Wire.read());
229
  int month = bcdToDec(Wire.read());
230
  int year = bcdToDec(Wire.read());
231
232
  //print the date EG   3/1/11 23:59:59
233
  Serial.print(month);
234
  Serial.print("/");
235
  Serial.print(monthDay);
236
  Serial.print("/");
237
  Serial.print(year);
238
  Serial.print(" ");
239
  Serial.print(hour);
240
  Serial.print(":");
241
  Serial.print(minute);
242
  Serial.print(":");
243
  Serial.print(second);
244
245
}

--

Längeren Sourcecode nicht im Text einfügen, sondern als Dateianhang


Wenn es Dir schon schwerfällt, die Bedienungsanleitung zu lesen und zu 
verstehen, dann wende doch wenigstens den einfacheren Teil davon an - 
die [ c ]  [ /c ] -Tags, damit Dein Sourcecodegeschreibsel wenigstens 
etwas lesbarer wird.

-rufus

: Bearbeitet durch User
von Wunderer (Gast)


Lesenswert?

Ist das mit dem
> Längeren Sourcecode nicht im Text einfügen, sondern als Dateianhang
oder dem Syntax Highlighting echt so schwer?

von STK500-Besitzer (Gast)


Lesenswert?

dein "present" ist 0 und bleibt es auch

Zumindest lese ich das aus deinem Krautundrüben-Code

von Lothar M. (Firma: Titel) (lkmiller) (Moderator) Benutzerseite


Lesenswert?

Hamster Hermann schrieb:
> Resultat: Es funktioniert noch immer nicht.
WAS funktioniert nicht? Oder anders: WAS erwartest du WARUM und WAS 
passiert stattdessen?

BTW: die Berechnung der Spannung aus den AD Wert ist falsch...
> float volts = (val / 511.0) * referenceVolts;
Da muss 512.0 stehen. Mit 511.0 hat die Gerade eine falsche Steigung und 
somit einen systematischen Fehler von 0,2%

: Bearbeitet durch Moderator
von G. H. (schufti)


Lesenswert?

naja, dann solltest du die Brille aufsetzen.
Denn in checkSD() besteht jedenfalls die Möglichkeit, dass es 1 wird.

aber "geht nicht" ist halt etwas zu wenig wenn man sich Hilfe erwartet.
Offenbar wurde auch ausser planlos eine library wiederholt zu 
installieren ja kein Versuch einer Problemlösung gestartet ....

von Tom Thomsen (Gast)


Lesenswert?

Hamster Hermann schrieb:
> Als erstes habe ich die Libary für den Sensor BMP180
> instaliert und sann nochmal und nochmal.

Mit dem Kopf gegen die Wand zu rennen, hilft in solchen Fällen wenig.
Was hat das mit dem MPL115A2 denn auf sich?

von Ballonplatzer (Gast)


Lesenswert?


von Hamster Hermann (Gast)


Lesenswert?

Tut mir leid Herr Balolonplatzer das sie den Begriff open source nicht 
verstanden haben.

https://de.wikipedia.org/wiki/Open_Source

danke.

von Hamster Hermann (Gast)


Lesenswert?

Danke für die schnellen Antworten es tut mir leid das ich mich so 
undeutlich ausgedrückt habe also mein genaues Problem ist das er immmer 
wieder die folgende Fehlermeldung anzeigt



Arduino: 1.6.0 (Windows 8), Platine: "Arduino Uno"

DatenloggerBMP180.ino:58:50: fatal error: SFE_BMP180: No such file or 
directory
compilation terminated.
Fehler beim Kompilieren.

  Und genau das ist mein Problem außerdem ist der sketch nicht "geklaut"
  denn man kann keinen open source sketch "klauen" da er ja open source 
was so viel heißt  wie das jeder damit privat machen kann was er 
will.Das ist ja auch der sinn von open source.

von Ballonplatzer (Gast)


Lesenswert?

Mein Kommentar bezog sich nicht darauf, ob Du die software kopieren 
darfst ... sondern eher darauf, dass Du gar nicht weißt, was Du tust.

Antworte lieber darauf:

Lothar M. schrieb:
> WAS funktioniert nicht? Oder anders: WAS erwartest du WARUM und WAS
> passiert stattdessen?

von Waldmeisterbrausenmeister (Gast)


Lesenswert?

Hamster Hermann schrieb:
> DatenloggerBMP180.ino:58:50: fatal error: SFE_BMP180: No such file or
> directory

#include <SFE_BMP180>

Und, gibt es die Datei irgendwo?

von Hamster Hermann (Gast)


Lesenswert?

Ich weiß serwohl was ich tue und außerdem kann mir mal lieber einer 
helfen statt nur zu motzen

von Ulrich F. (Gast)


Lesenswert?

Hamster Hermann schrieb:
> Ich weiß serwohl was ich tue und außerdem kann mir mal lieber
> einer
> helfen statt nur zu motzen

Gerne!
Installiere die Lib, und dann geht das!

von holger (Gast)


Lesenswert?

>#include <SFE_BMP180>
>
>Und, gibt es die Datei irgendwo?


Oder die?

#include <SFE_BMP180´.h>

von holger (Gast)


Lesenswert?

>#include <SFE_BMP180´.h>

Natürlich so:

#include <SFE_BMP180.h>

von Mike A. (Gast)


Lesenswert?

Hamster Hermann schrieb:
> SFE_BMP180: No such file or directory

Hamster Hermann schrieb:
> Ich weiß serwohl was ich tue

sicher?

von Hamster Hermann (Gast)


Lesenswert?

Ja

von Hamster Hermann (Gast)


Lesenswert?

Danke ulrich

von G. H. (schufti)


Lesenswert?

Und das
#include <Wire.h>
Gehört auch wieder in eine eigene Zeile, sonst gibts Probleme mit dem 
Temp-sensor

: Bearbeitet durch User
von Eric (Gast)


Lesenswert?

Actually you removed the attribution which is a "party-foul" when people 
like myself share code.  As well you added the extra include which isn't 
there in the original code :)

Advise triple checking your libraries are installed correctly.  Failing 
that- use an older IDE to compile- the newer ones do not like that many 
comments and fail sometimes (personal experience)

If you run into troubles there is also a forum on the original site 
(mkme.org) which is geared to helping with such things :)

Best of luck!

Cheers
Eric

von Jörg W. (dl8dtl) (Moderator) Benutzerseite


Lesenswert?

Hamster Hermann schrieb:
> Tut mir leid Herr Balolonplatzer das sie den Begriff open source nicht
> verstanden haben.

Eric schrieb:
> Actually you removed the attribution which is a "party-foul" when people
> like myself share code.  As well you added the extra include which isn't
> there in the original code :)

Ich denke, eher du hast den Begriff nicht verstanden, Hermann.

Und die Netiquette offenbar auch nicht.  Problem nicht ordentlich
formuliert, keine brauchbare Formatierung, dann gleich noch einen
zweiten Thread dazu gestartet – Freunde, die dir bereitwillig helfen
möchten, machst du dir mit solchen Manieren jedenfalls keine.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.