New Homepage Forums Sensor Shields Data Logger Shield or SD Card Reader

This topic contains 9 replies, has 2 voices, and was last updated by avatar Amr 2 years, 2 months ago. This post has been viewed 620 times

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #85866
    avatarLudwig Koessner
    Participant

    Hello!
    I build a Data Logger with an Arduino Uno. The Logger saves every minute and every 5 cm distance two hydraulikpress parameter.
    The Data are logged in an SD-Shield. Is it possible after finish to read the sd-card and sent with 1Sheeld and phone to another computer?
    I tryed to include the 1Sheeld code in my projekt, but i don’t konw how the best way it would work.
    I hope here is somebody how can show me the right way to finish my projekt.

    Here is my code!

    <pre class=”theme:arduino-ide lang:arduino decode:true ” title=”Datalogger” >

    #include <SD.h>
    #include <SPI.h>
    #include “RTClib.h”
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>

    #define CUSTOM_SETTINGS
    #define INCLUDE_DATA_LOGGER_SHIELD

    /* Include 1Sheeld library. */
    #include <OneSheeld.h>

    #define I2C_ADDR 0x27 // Define I2C Address where the PCF8574A is
    #define BACKLIGHT_PIN 3
    #define En_pin 2
    #define Rw_pin 1
    #define Rs_pin 0
    #define D4_pin 4
    #define D5_pin 5
    #define D6_pin 6
    #define D7_pin 7
    #define outputA 6
    #define outputB 7

    int n = 1;

    int var3 = 0; // counter
    int var1 = 0; // Druckgeber 1 Presszylinder
    int var2 = 0; // Druckgeber 2 Getriebedruck
    int Pressensensor = 0; // Potipin fuer Demo
    int Getriebesensor = 1; // Potipin fuer Demo
    float counter = 0; // float fuer Kommastellen int fuer ganze Zahlen
    float Vortriebsstrecke = 0;

    LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

    RTC_DS1307 rtc;

    //Definiere Prototypen
    void speichernAufSD(void);

    #define outputA 6
    #define outputB 7

    int aState;
    int aLastState;

    const int chipSelect = 4;
    unsigned long timer;
    const unsigned int speicherZyklus = 1000; //Speichern alle 10 Sekunden

    void setup() {

    /* Start communication. */
    OneSheeld.begin();

    Serial.begin(115200);
    pinMode(SS, OUTPUT);
    if (! rtc.begin()) {
    Serial.println(“Couldn’t find RTC”);
    while (1);
    }
    while (!Serial) {
    }
    Serial.print(“Initializing SD card…”);
    if (!SD.begin(chipSelect)) {
    Serial.println(“Card failed, or not present”);
    while (1);
    }
    Serial.println(“card initialized.”);
    if (! rtc.isrunning()) {
    Serial.println(“RTC is NOT running!”);
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
    }
    pinMode(Pressensensor, INPUT);
    pinMode(Getriebesensor, INPUT);
    pinMode(outputA, INPUT);
    pinMode(outputB, INPUT);

    timer = millis(); //Startwert von timer

    lcd.begin (20,4);

    // Switch on the backlight
    lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
    lcd.setBacklight(HIGH);
    lcd.setCursor ( 0, 0 );
    lcd.print(“RBS BOHRDATENLOGGER”);
    lcd.setCursor ( 0, 1 ); // go to the next line
    lcd.print(“Vortrieb m/t:”);
    lcd.setCursor ( 0, 2 ); // go to the next line
    lcd.print(“Vortrieb bar:”);
    lcd.setCursor ( 0, 3 ); // go to the next line
    lcd.print(“Getriebe bar:”);

    }

    void loop(){
    {
    lcd.setCursor ( 15, 1 );
    Vortriebsstrecke = counter * 0.05;
    var1 = analogRead(Pressensensor);
    var1 = map(var1, 0, 1000, 0, 400);
    var2 = analogRead(Getriebesensor);
    var2 = map(var2, 0, 1000, 0, 400);

    lcd.print(Vortriebsstrecke);
    lcd.setCursor ( 15, 2 ); // go to the next line
    lcd.print(var1);
    lcd.print(‘ ‘);
    lcd.setCursor ( 15, 3 );
    lcd.print(var2);
    lcd.print(‘ ‘);

    }

    aState = digitalRead(outputA); // Reads the “current” state of the outputA
    // If the previous and the current state of the outputA are different, that means a Pulse has occured
    if (aState != aLastState)
    {
    // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
    if (digitalRead(outputB) != aState)
    {
    counter ++;
    }// else
    {
    //counter –;
    }
    speichernAufSD();
    aLastState = aState; // Updates the previous state of the outputA with the current state
    }

    //Hier wird nun im Zyklus von “speicherZyklus” das Unterprogramm “speichernAufSD()” aufgerufen
    if (millis() >= timer + speicherZyklus)
    {
    timer = millis();
    speichernAufSD();

    }
    }

    void speichernAufSD()
    {

    DateTime now = rtc.now();

    if (now.day() < 10) {
    Serial.print(‘0’);
    }
    Serial.print(now.day(), DEC);
    Serial.print(‘/’);
    if (now.month() < 10) {
    Serial.print(‘0’);
    }
    Serial.print(now.month(), DEC);
    Serial.print(‘/’);
    Serial.print(now.year(), DEC);
    Serial.print(“, “);
    if (now.hour() < 10) {
    Serial.print(‘0’);
    }
    Serial.print(now.hour(), DEC);
    Serial.print(‘:’);
    if (now.minute() < 10) {
    Serial.print(‘0’);
    }
    Serial.print(now.minute(), DEC);
    Serial.print(‘:’);
    if (now.second() < 10) {
    Serial.print(‘0’);
    }
    Serial.print(now.second(), DEC);
    Serial.print(‘,’);

    Serial.print(var1);
    Serial.print(“, “);
    Serial.print(var2);
    Serial.print(“, “);
    Serial.println(counter * 0.05);

    File dataFile = SD.open(“datalog.txt”, FILE_WRITE);

    // if the file is available, write to it:
    if (dataFile) {

    if (now.day() < 10) {
    dataFile.print(‘0’);
    }
    dataFile.print(now.day(), DEC);
    dataFile.print(‘/’);
    if (now.month() < 10) {
    dataFile.print(‘0’);
    }
    dataFile.print(now.month(), DEC);
    dataFile.print(‘/’);
    dataFile.print(now.year(), DEC);
    dataFile.print(“,”);
    if (now.hour() < 10) {
    dataFile.print(‘0’);
    }
    dataFile.print(now.hour(), DEC);
    dataFile.print(‘:’);
    if (now.minute() < 10) {
    dataFile.print(‘0’);
    }
    dataFile.print(now.minute(), DEC);
    dataFile.print(‘:’);
    if (now.second() < 10) {
    dataFile.print(‘0’);
    }
    dataFile.print(now.second(), DEC);
    dataFile.print(“,”);

    dataFile.print(var1);
    dataFile.print(“, “);
    dataFile.print(var2);
    dataFile.print(“, “);
    dataFile.print(counter * 0.05);
    dataFile.println();

    dataFile.close();
    }
    // if the file isn’t open, pop up an error:
    else {
    Serial.println(“error opening datalog.txt”);
    }
    }

    #85971
    avatarAmr
    Keymaster

    Hi,

    Actually, 1Sheeld Data Logger Shield is used to log your data into your smartphone, not into a computer.
    So, one possible tricky solution if you want to have your data accessible from the computer is to use the Email Shield to send the logged data from your phone to your email. Then, you can access this data by downloading the data file in your email.

    Hope you got it 🙂

    #87091
    avatarLudwig Koessner
    Participant

    Hi,
    Thanks for your answer. I tryed to log my data in my smartphone, but it doesn’t work.
    To sent the data from the phone is no Problem. My qustion was, can i read the sd card after logging
    or how can i log my data in my Smartphone with ” one Line of Code” ???

    Sincerly, Ludwig.

    #87098
    avatarLudwig Koessner
    Participant

    Hi,
    Thanks for your answer. I tryed to log my data in my smartphone, but it doesn’t work.
    To sent the data from the phone is no Problem. My qustion was, can i read the sd card after logging
    or how can i log my data in my Smartphone with ” one Line of Code” ???

    Sincerly, Ludwig.

    #87356
    avatarAmr
    Keymaster

    Hey,

    Have you tried this example of data logger in the 1Sheeld library?
    And yes, you can read the data from the SD card by the Arduino and log it back to the phone by 1Sheeld.

    By the way, don’t use serial.print functions while using 1Sheeld since this will cause a conflict and 1Sheeld functionality won’t work. If you want to monitor your code then you can use the Terminal Shield instead of all the serial statements.

    #88015
    avatarLudwig Koessner
    Participant

    Hello!

    I tried the example of data logger but it didn’t work.

    Now i startet the Terminal Shield and i can see my data on my phone “that’s great”.
    How can i send this to my computer or how can i save my data on my phone.

    #88023
    avatarLudwig Koessner
    Participant

    Hello!

    How can i save my data like csv.
    I tryed to copy my data and sent it with mail, but i got only one line of data.
    I can’t read this in Excel.

    #88179
    avatarAmr
    Keymaster

    Hey,

    You can save your data into the phone in form of excel CSV file by using the DataLogger shield

    But you are saying that the example isn’t working, Soo please make sure that:
    – There are no Serial print statements in the example code you uploaded to the Arduino.
    – You have set the 1Sheeld board to the operating mode after you have downloaded the code. This is done by sliding the switch towards the “SERIAL” or “UART” notation.
    – You have selected the data logger shield from the phone app.

    If it didn’t work after all, then please let me see the code.

    #88192
    avatarLudwig Koessner
    Participant

    Hello!
    In the Terminal on my phone the data look like this:

    ,31/7/2018,17:47:23,64,62,0
    ,31/7/2018,17:47:33,64,62,1 → this is wich it should look like to use it in excel

    i go to copy all and i get this in one line:

    Optional(“””),31/7/2018,17:47:23,64,62, 1 Optional(“””),31/7/2018,17:47:33,64,62, 2 Optional(“””),31/7/2018,17:47:43,64,62,

    from were is this Optional coming and how can i delet this coment.
    Everthing is in one line → how can cut this in manny lines.

    Thanks for yor answer!

    #88219
    avatarAmr
    Keymaster

    Hi,

    One way to fix this is to try to import the CSV file into a google sheet. It will be reordered properly.

    Give it a try and tell me if it worked out 😉

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.