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.


  1. Many thanks for your project description. It was useful for my project.

    I have it half working now: code that write from Arduino to FlashAir SD works while FlashAir WiFi is on. I can see the files on SD in the webbrowser of my laptop.

    Arduino code that reads data from SD FlashAir works also, BUT the FlashAir card drops WiFi: the laptop cannot connect to FlashAir any longer. I can't get it to work.

    Do you have come across this problem?

    1. Hi, Jan.
      Thank you for your comment.
      You use FlashAir as follow, don't you?
      - FlashAir SD card is mounted on Arduino.
      - Arduino accesses FlashAir as SD card (not GPIO device).
      - Your laptop accesses FlashAir as HTTP server via WiFi.

      If my understanding is correct, I recommend to use the original FlashAir library of FlashAir developers. (not to use my customized library)

      I guess several root causes, if the same issue occurs in spite of the original library.

      - Arduino power shortage.
      WiFi needs high wattage than simple SD card.
      If your arduino connects to other device/sensors,
      it might be over the power supply capacity of arduino.

      - FlashAir's processing ability shortage
      I do not understand completely FlashAir's behavior.
      FlashAir might have not enough processing ability
      to work hardly SD and WiFI at the same time.

      I'm so happy, if my comment helps your challenge.