Kyjja |
:hello:
J'ouvre un topic qui va me servir à demander à l'aide régulièrement :D
Objectif : avoir un arduino avec quelques capteurs utiles en rando (humidité, température, intensité lumineuse, UV, pression atmosphérique) avec le GPS et écrire tout ça sur un fichier dans une carte SD, histoire de balancer ça sur un logiciel de carto style QGIS.
Évidemment, je nage complètement, donc le code est un ignoble monstre de Frankenstein avec des bouts de trucs récupérés à droite à gauche, et va devoir évoluer vers un truc fonctionnel :D
Toute aide bienvenue :o
NB : A partir de "//GPS part" c'est du pompage pur et dur, j'ai juste modifié la fréquence de write sur la SD pour passer à 1 minute au lieu de 1 seconde. [:sent mal_homme:1]
- Objectif du moment : définir les pins.
Code :
- /*
-
- ~~~~~~~~Hiking Environmental Data Logger~~~~~~~~
-
- Arduino : MEGA 2560
- GPS : MT3329 SKM53 (5V)
- Light intensity : BH1750 (3.3V)
- UV : ML8511 (3.3V)
- Barometric pressure : BMP180 (3.3V)
- Humidity and Temperature : HTU21D (3.3V)
- SD card module : Generic module. Connection : 5v to 5v, CLK to Pin 13 on your Arduino, DO to pin 12, DI to pin 11, and CS to pin 10
- */
- //Libraries
- #include <TinyGPS.h>
- #include <NewSoftSerial.h>
- #include <Wire.h>
- #include <BH1750.h>
- #include <plotly_streaming.pre.h> // UV
- #include <SFE_BMP180.h>
- #include <SparkFunHTU21D.h>
- #include <SD.h>
- #include <SPI.h>
- #define BUFF_MAX 100 // size of GPS & SD buffers
- #define BH1750_SDA A0
- #define BH1750_SCL A1
- #define ML8511_EN A2
- #define ML8511_OUT A3
- #define BMP180_SDA A4
- #define BMP180_SCL A5
- #define HTU21D_SDA A6
- #define HTU21D_SCL A7
- #define SD_CLK 13
- #define SD_DO 12
- #define SD_DI 11
- #define SD_CS 10
- // GPS part
- /*
- RXD Arduino Pin 3
- TXD Arduino Pin 2
- RST Leave Open ? (Connect to a N/O momentary switch pulled low to reset?)
- NC Leave Open
- GND Ground
- VCC +5
- Make sure you download TinyGPS.h
- */
- unsigned long fix_age;
- SoftwareSerial GPS(2,3);
- TinyGPS gps;
- void gpsdump(TinyGPS &gps);
- bool feedgps();
- void getGPS();
- long lat, lon;
- float LAT, LON;
- void setup(){
- GPS.begin(9600);
- Serial.begin(115200);
- }
- void loop(){
- long lat, lon;
- unsigned long fix_age, time, date, speed, course;
- unsigned long chars;
- unsigned short sentences, failed_checksum;
- // retrieves +/- lat/long in 100000ths of a degree
- getGPS();
- gps.get_position(&lat, &lon, &fix_age);
- Serial.print("Latitude : " );
- Serial.print(LAT/100000,7);
- Serial.print(" :: Longitude : " );
- Serial.println(LON/100000,7);
- }
- void getGPS(){
- bool newdata = false;
- unsigned long start = millis();
- // Every 1 minute we print an update
- while (millis() - start < 60000)
- {
- if (feedgps ()){
- newdata = true;
- }
- }
- if (newdata)
- {
- gpsdump(gps);
- }
- }
- bool feedgps(){
- while (GPS.available())
- {
- if (gps.encode(GPS.read()))
- return true;
- }
- return 0;
- }
- void gpsdump(TinyGPS &gps)
- {
- //byte month, day, hour, minute, second, hundredths;
- gps.get_position(&lat, &lon);
- LAT = lat;
- LON = lon;
- {
- feedgps(); // If we don\'t feed the gps during this long routine, we may drop characters and get checksum errors
- }
- }
- //SD Part
- GPSlog = SD.open("GPS.log", O_CREAT | O_WRITE); // open/append to a file GPS.log
- void loop()
- {
- char inBuffer[BUFF_MAX]; // buffer used to read NMEA lines from GPS
- byte outBuffer[BUFF_MAX]; // buffer used to write NMEA lines to SD card
- int sizeBuffer = 0; // counter of how many chars per line
- GPSlog.write(outBuffer, sizeBuffer); // write GPS NMEA output to SD
- GPSlog.print("\r\n" );
- GPSlog.flush();
- }
|
|