Thursday, April 13, 2017

Temperature and hygrometer with FlashAir + Arduino + Raspberry Pi (2) : Read SD card with using iSDIO

Table of contents.
  1. Read values from sensor
  2. Read from SD card with iSDIO
  3. Send values from arduino to Raspbery Pi
  4. Visualize on Raspberry Pi

Last time we measured temperature and humidity with DHT22.

Before sending measurement results, Modify FlashAir's iSDIO library.

Support FlashAir iSDIO and SD card function both

Following the FlashAir Developers tutorial, you can connect to HTTP using iSDIO with FlashAir.
FlashAir Developers:Arduino tutorial

However, in this tutorial, the SD card access function is killed.
So, we have to enhance the library by our selves.

  1. First, Download the tutorial source code and unzip the archive.
  2. Copy the following files from Arduino's standard SD card library into the unzipped "iSDIO" folder.
    File.cpp, FatStructs.h, SdFatUtil.h, SdFile.cpp, SdVolume.cpp。
    Then, copy SD.cpp and SD.h, and rename them to SDExt.cpp and SDExt.h.

    After that, the iSDIO folder becomes like this.
  3. Open SDExt.h, SdFat.h, SdVolume.h in the iSDIO folder and replace the word "Sd2Card" with "Sd2CardExt".
  4. Open File.cpp and SDExt.cpp in the iSDIO folder and replace "SD.h" with "SDExt.h".
  5. ZIP compress the iSDIO folder.
  6. In the Arduino IDE, select the below menu and load the ZIP file.
    Scketch - Include libraries - Install .ZIP library

I put the modified iSDIO library in GitHub.
GitHub - onthehand - iSDIO

How to use the modified iSDIO.

SD storage access with the iSDIO library.

void loop() {
  File file ="file.txt", FILE_READ);

"SDExt.h" is included instead of "SD.h".
Plus, delay is added after SD card access.
I don't know why, but WiFi connection seems to become unstable just after SD card access.
Other than that the way to use is the same as normal SD.h.

When using FlashAir's WiFi with a modified iSDIO library,
the following points are needed than the tutorial of Flash Air Developers site.
  • Include "SDExt.h" instead of "utility/Sd2CardExt.h".
  • Do not declare "Sd2CardExt card;" as a global variable.
  • Change all "card" object to "SD.card".
    ex) "card.readExtMemory" to "SD.card.readExtMemory".

    Originally, card object of Sd2Card is a member variable of SD class.
    So, after SD class (SDExt class) becomes available, the object should be accessed as a member variable.
    If it accessed directly from out of the class, its behavior becomes unstable.

OK, next time, send sensor data via WiFi.

No comments:

Post a Comment