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.
    arduino_tutorial_06.zip
  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.
#include 

void loop() {
  File file = SD.open("file.txt", FILE_READ);
       :
  file.close();
  delay(1000);

"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.

10 comments:

  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?

    ReplyDelete
    Replies
    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)
      https://flashair-developers.com/en/documents/tutorials/arduino/

      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.

      Delete
  2. Hi, I am trying to setup an arduino with an SD card reader. I would like to use a Toshiba FlashAir 16GB card and read the card via the WIFI while the arduino is collecting data and storing it on the flash drive. I could successfully read/write a regular SD card with the standard library, but not the FlashAir card.
    I used this setup and software:
    http://henrysbench.capnfatz.com/henrys-bench/arduino-output-devices/arduino-lc-studio-sd-card-tutorial/

    I tried to use youe modified library, but it did not work either. I can connect to the WIFI on the SD card, but I am unable to connect the arduino with the card.

    Any suggestion?

    ReplyDelete
    Replies
    1. It seems that FlashAir WiFi function is unstable during SD card writing/reading and after that.
      Please insert a few second "delay" after writing/reading.

      Let me know detail error message or information, If it does not work even with delay,

      Delete
    2. suspect a power source problem. I just followed the instructions on the above web site, but I think it is not appropriate to use the 5v on the Arduino Uno board. I also realized that the file writing is not working even with a regular sd card, which is a more power consuming operation, than just reading. I assume the FlashAir requires even more power than a regular sd card. I am not sure about this power source problem, because the wifi access is actually working. It may be simply a voltage level problem, since the card is actually using 3.3 logical level and not TTL. I read a lot about problems with the sd cards on the net, but I still have no clue.

      Delete
    3. Thank you for a good suggestion.

      I found a solution of Arduino power source issue for FlashAir, but it is a Japanese blog, hmmm...
      http://powerele.sblo.jp/article/182349083.html

      In summary, he says as following.
      - Because FlashAir needs high current, a regular Arduino Uno becomes unstable.
      - Some Arduino compatible boards have an improved power regulator.
      - As the result, he removed a regulator AMS1117 from his regular Arduino, and then replaced it to BP5293-50.

      His hack is non-invertible, so I don't want to take such a solution...
      I keep detecting some other solutions.

      Delete
    4. I am planning to use a 3.3v arduino mini pro and I will make its power supply and for the sd card too from a step down dc-dc power supply like this:
      https://www.ebay.com/itm/3-3V-3A-Mini-Step-Down-Power-Supply-Module-DC-DC-Converter-Input-7V-28V-Output/311886109092?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2060353.m2749.l2649

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Merkur 20C Review - Xn - Ng
    Merkur 20C Review - Xn · Merkur 20C. 메리트 카지노 쿠폰 The Merkur 20C is a stylish and efficient all-round adjustable หาเงินออนไลน์ safety razor. · The worrione Merkur 20C is a

    ReplyDelete