weixin_39926040
2020-11-27 02:50 阅读 6

How to access files from a USB stick? Any examples?

Hello,

Congratulations! Great job!

I found a sample code that allows you to upload and download files to an SD card (webserver): https://github.com/G6EJD/ESP32-8266-FIle-Upload (Demo video: https://www.youtube.com/watch?v=1OkEXeRbq_M )

I wish I could do this with a USB stick.

I've noticed that common Arduino boards have poor memory, but would it be possible with ESP8266, or maybe with ESP32?

Is there any possibility of leaving the access to the files in a more transparent way, or similar to the access to the SD card?

The reason for this search is the need to update files from the SD card that is on an mp3 player with the DFplayer Mini. 2

The DFplayer mini has a USB port that can operate as a Host (to read files from a USB stick) or can also operate as a device, so that the PC can access the files from the SD card (and there is also a possibility to use the DFplayer Mini as sound card, but I believe the "clones" do not have this support) usb pc

I accessed the USB port of the DFplayer Mini by Windows 7 and also by Linux (Raspbian - Raspberry Pi). A mass storage device appears in Windows (XY5200 system). And in Linux it is possible to access the DFplayer Mini as a common USB stick, it appears as a partition "/ dev / sda1" (attached image). rpi

The Raspberry Pi problem is the instability of the system in relation to data corruption (of your own Operating System), especially when there is a power outage.

Would it be possible to provide a compileable example (.ino) with NodeMCU (ESP8266) or ESP32?

该提问来源于开源项目:felis/USB_Host_Shield_2.0

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

20条回答 默认 最新

  • weixin_39859394 weixin_39859394 2020-11-27 02:50

    There is a sample project called testusbhostFAT under the example directory. It isn't pretty but certainly has a lot of information you need.

    Unfortunately you need to do the web server part yourself, which doesn't look that hard from the example code you mentioned.

    点赞 评论 复制链接分享
  • weixin_39926040 weixin_39926040 2020-11-27 02:50

    Hello, thanks for the tip, I kept working here and found another way, I managed to switch access to the SD card between the DFPlayer Mini and ESP8266, so I can already use the code I quoted above "ESP32-8266-FILE-Upload" with few changes.

    点赞 评论 复制链接分享
  • weixin_39926040 weixin_39926040 2020-11-27 02:50

    But it would be great to have a sample file access code, similar to what the SDFat library already offers. Would standardization be possible?

    点赞 评论 复制链接分享
  • weixin_39926040 weixin_39926040 2020-11-27 02:50

    DFPlayer Mini SD card being accessed by ESP8266: server

    If one wants to do this: I simply used 2 micro AXICOM relays to toggle the SPI connections, it is interesting that the DFPlayer Mini operates with the Chip Select from the floating card, it is not used.

    点赞 评论 复制链接分享
  • weixin_39722563 weixin_39722563 2020-11-27 02:50

    excellent work. since last month i was looking for a way to accessing the files on DFPlayer. Arduino community has given up on it https://forum.arduino.cc/index.php?topic=614117.0. But, you being odd one out. can you please share the code and schematic i.e. 2 micro AXICOM relays to toggle the SPI connections. your contribution will be highly regarded by the community.

    点赞 评论 复制链接分享
  • weixin_39926040 weixin_39926040 2020-11-27 02:50

    Hello,

    The code is pretty much the same as the link above (https://github.com/G6EJD/ESP32-8266-FIle-Upload).

    The only secret on the hardware side is the power of the SD card. (Can use a MOSFET, I had success with AO3401, also with BC328 but is less efficient).

    Pull-up resistors* to the SD card are recommended, to avoid random errors. Relay connections only disconnect the SD card from one circuit (DFPlayer), and connect to another circuit (ESP8266) as if it were a manual operation. On the DFPlayer side does not need to add pull-up resistors.

    You may need to turn off DFPlayer before connecting it to the SD card (only 3 communication pins, MOSI, MISO, SCK) and power the SD card at the same time. (Please, see if in your DFPlayer the CS pin is also floating, as it was in mine). You may need to send some command to force DFPlayer to operate the SD card again (DFPlayer usually recognizes SD card automatically after inserting in circuit).

    Each time you switch between ESP8266 and DFPlayer, the SD card needs to be initialized. In DFPlayer, you may need just cycle the power.

    For ESP8266 need to connect the 4 wires (MOSI, MISO, SCK, SS). Initializing the library after powering up the SD card, be careful to properly power up the SD card so that it does not lock (SD card does not accept to be booted by library, or does not accept write).

    Maybe the power up sequence is described in the SD specification, I didn't have time to look much, but I haven't found anything yet about it. Just found a datasheet that reports about 250ms of power up time, this power up time should already be included in library initialization (SDFat.h).

    I've been testing this sequence (code) below to disable (and reactivate later without the SDFat library reporting error) to save battery power, I noticed that a delay (100us) had to be added before powering up the SD card so that the control pins are properly polarized.

    Note: This code below was tested on STM32F103CBT6, BluePill as the SPI port needed to be remapped (SPI Clock: 35MHz). Please, try modifying the power-up sequence for different SD cards to test if it can be considered as a standard sequence.

    C++
    #include <spi.h>
    #include "SdFat.h"
    
    void setup() {
      // put your setup code here, to run once:
    
      SD_powerOff(); // If the SPI port has been automatically initialized, it forces disabling
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      SD_powerOn();
      // put your SD code here:
    
      if (!sd.begin(chipSelect, SD_SCK_MHZ(35))) {
        //sd.initErrorHalt();
      }
    
      SD_powerOff(); // when you no longer use the SD card
    
      Delay(1000); // Sleep function is better than delay function, to save energy
    
    }
    
    void SD_powerOn() {
      digitalWrite(chipSelect, HIGH);
      digitalWrite(PB5, HIGH); // MOSI
      digitalWrite(PB4, HIGH); // MISO
      digitalWrite(PB3, HIGH); // SCK
      pinMode(chipSelect, OUTPUT);
      pinMode(PB5, OUTPUT);
      pinMode(PB4, INPUT);
      pinMode(PB3, OUTPUT);
    
      delayMicroseconds(100);
    
      digitalWrite(SD_PWR, LOW);
      pinMode(SD_PWR, OUTPUT);
    }
    
    void SD_powerOff() {
      pinMode(PB3, INPUT);
      pinMode(PB4, INPUT);
      pinMode(PB5, INPUT);
      pinMode(chipSelect, INPUT);
      digitalWrite(SD_PWR, HIGH);
      pinMode(SD_PWR, INPUT);
    }
    </spi.h>

    *(Illustrative image of MOSFET and pull-up resistors)

    SD card Power

    点赞 评论 复制链接分享
  • weixin_39722563 weixin_39722563 2020-11-27 02:50

    Thank you for taking time out and providing the to the point code and detailed diagram. i came across your thread on electronic exchange. surely, you have spent lot of time on this projec.

    reference: https://electronics.stackexchange.com/questions/83263/micro-sd-card-power-circuit-failure

    Question: What is DET_A amd DET_B? Short Answer: detects the card and see whether card is writeable. long answer: In the original SD card, the write protect and Card Detect are provided by the card connector, not the card itself (admitted, both signals are switched by the SD card's mechanics). The Micro SD card connector has no such provisions (saving some extra space). So Write protect: forget it. Easiest is to redefine the WriteProtect to a constant. For the Card detect: Either provide some way to confirm the presence of the card (via whatever means extra available to you/your app) OR rewrite the initialisation such that it tries to open the card, and just retries the next time in case of failure. Depending on the hardware, some sockets have a card detect (CD) signal, which usually just makes connection to ground when a card is inserted.

    http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0425f/Schdbdfhh.html https://forum.arduino.cc/index.php?topic=128025.0 https://electronics.stackexchange.com/questions/207335/what-is-the-way-to-detect-sd-card-insertion-removal https://electronics.stackexchange.com/questions/206019/what-does-switch-pin-do-on-a-microsd-connector https://www.microchip.com/forums/m474331.aspx

    Micro-SD (Transflash) Card Pinout for SPI Mode

    MicroSD Transflash pinout

    SPI Mode Pin Name Description 1 NC not connected 2 CS Chip Select/Slave Select (SS) 3 DI Master Out/Slave In (MOSI) 4 VDD Supply voltage 5 CLK Clock (SCK) 6 VSS Supply voltage ground 7 DO Master In/Slave Out (MISO) 8 RSV Reserved

    10 (DET A) | CARDIN | Card insertion detect 11 (DET B) | WPROT | Write protect status

    You have seriously debugged the code in smallest of details and thanks for the complete and exhaustive explanation.

    i will reproduce your solution with different SD cards and come back soon.

    How to use MMC: http://elm-chan.org/docs/mmc/mmc_e.html

    Extras: Inspired by your code + illustration diagram i did some more search on internet, and came across a solution with arduino and "expensive mp3 module" and tristate buffers and bidirectional switches. But, your solution is simplest one and most intuitive.

    Just for reference: Explaination: http://www.vwlowen.co.uk/arduino/mp3-player-2/home-mp3-player.htm video: https://www.youtube.com/watch?v=WYUum27jYKw code: http://www.vwlowen.co.uk/arduino/mp3-player-2/page3.htm

    some SD card refernce: http://www.dejazzer.com/ee379/lecture_notes/lec12_sd_card.pdf https://openlabpro.com/guide/interfacing-microcontrollers-with-sd-card/

    when SDcard is attached to PCB i.e. filters , EMI , clock, pullup and impedence considerations https://www.acmesystems.it/pcb_microsd

    点赞 评论 复制链接分享
  • weixin_39926040 weixin_39926040 2020-11-27 02:50

    ESP8266 is very limited, try searching for ESP32

    DIY 10 Player Game Console [ESP32, Arduino, Audio Video]: https://www.youtube.com/watch?v=VvkpKVtYKmk

    点赞 评论 复制链接分享
  • weixin_39722563 weixin_39722563 2020-11-27 02:50

    I am using ESP32. i have a similar problem like yours. i have to download the new words file (english words) from internet (cloud) and store them in sdcard.

    i send a word sentence to the esp32 and if no new words are found in this sentence then SP32 will play sentence words from local SDcard else it will request for the new words from cloud and then it will be stored in the SDcard for next time. simply, It acts as a cache.

    sentence is usually 10-12 words long. I can download this from internet on each request as wav file. but, can i play it directly through DAC on ESP32?

    点赞 评论 复制链接分享
  • weixin_39926040 weixin_39926040 2020-11-27 02:50

    I found it using Google, see if it helps:

    Make your ESP32 talk, playing WAV files on your ESP32, digital sound DAC ADC: https://www.youtube.com/watch?v=gxpHDUHcBMk

    点赞 评论 复制链接分享
  • weixin_39722563 weixin_39722563 2020-11-27 02:50

    yes i have tried ESP32 talk and it is working.

    i researched some more on your guidelines and found a library that can read MP3 from SDcard and from HTTPStream and play it on ESP32 using a single $0.05 NPN 2N3904 transistor and optionally adding a 220uF cap from USB5V to GND

    Refernce: Library: Arduino library to play MOD, WAV, FLAC, MIDI, RTTTL, MP3, and AAC files on I2S DACs or with a software emulated delta-sigma DAC on the ESP8266 and ESP32 https://github.com/earlephilhower/ESP8266Audio#software-i2s-delta-sigma-dac-ie-playing-music-with-a-single-transistor-and-speaker

    Example: https://libraries.io/github/roguh/ESP8266Audio

    点赞 评论 复制链接分享
  • weixin_39722563 weixin_39722563 2020-11-27 02:50

    ESP8266Audio is taking too much space Sketch uses 840666 bytes (64%) of program storage space. Maximum is 1310720 bytes. Global variables use 39484 bytes (12%) of dynamic memory, leaving 288196 bytes for local variables. Maximum is 327680 bytes.

    //https://vk.com/wall-80234063_2336 //http://forum.amperka.ru/threads/%D0%98%D0%BD%D1%82%D0%B5%D1%80%D0%BD%D0%B5%D1%82-%D1%80%D0%B0%D0%B4%D0%B8%D0%BE%D0%BF%D1%80%D0%B8%D0%B5%D0%BC%D0%BD%D0%B8%D0%BA-%D0%BD%D0%B0-esp32.15262/page-6 //http://192.155.89.84/chris/M5Stack-MultiApp-Advanced/blob/665540a83bc4b2318440080cc81f41fbf161c3ce/src/Apps/WebRadio.h //https://github.com/earlephilhower/ESP8266Audio/issues/13 //https://www.hackster.io/julianfschroeter/stream-your-audio-on-the-esp32-2e4661

    include

    include

    //#ifdef ESP32 // #include //#else // #include //#endif

    include "AudioFileSourceICYStream.h"

    include "AudioFileSourceBuffer.h"

    include "AudioGeneratorMP3.h"

    include "AudioOutputI2SNoDAC.h"

    // To run, set your ESP8266 build to 160MHz, update the SSID info, and upload.

    // Enter your WiFi setup here: const char SSID = "dlink"; const char PASSWORD = "-------";

    // Randomly picked URL const char *URL="http://philae.shoutca.st:8446/stream/1/";

    AudioGeneratorMP3 mp3; AudioFileSourceICYStream file; AudioFileSourceBuffer buff; AudioOutputI2SNoDAC out;

    // Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc. void MDCallback(void cbData, const char type, bool isUnicode, const char string) { const char ptr = reinterpret_cast(cbData); (void) isUnicode; // Punt this ball for now // Note that the type and string may be in PROGMEM, so copy them to RAM for printf char s1[32], s2[64]; strncpy_P(s1, type, sizeof(s1)); s1[sizeof(s1)-1]=0; strncpy_P(s2, string, sizeof(s2)); s2[sizeof(s2)-1]=0; Serial.printf("METADATA(%s) '%s' = '%s'\n", ptr, s1, s2); Serial.flush(); }

    // Called when there's a warning or error (like a buffer underflow or decode hiccup) void StatusCallback(void cbData, int code, const char string) { const char *ptr = reinterpret_cast(cbData); // Note that the string may be in PROGMEM, so copy it to RAM for printf char s1[64]; strncpy_P(s1, string, sizeof(s1)); s1[sizeof(s1)-1]=0; Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1); Serial.flush(); }

    void setup() {

    Serial.begin(115200); delay(1000); Serial.println("Connecting to WiFi");

    WiFi.disconnect(); WiFi.softAPdisconnect(true); WiFi.mode(WIFI_STA);

    WiFi.begin(SSID, PASSWORD);

    // Try forever while (WiFi.status() != WL_CONNECTED) { Serial.println("...Connecting to WiFi"); delay(1000); } Serial.println("Connected");

    audioLogger = &Serial; file = new AudioFileSourceICYStream(URL); file->RegisterMetadataCB(MDCallback, (void)"ICY"); buff = new AudioFileSourceBuffer(file, 51024); // change it ir the librart on which it depends //i.e SPIRAM or change the streaming link that can present slowly n slow buffers // bibber buffer more stable buff->RegisterStatusCB(StatusCallback, (void)"buffer"); out = new AudioOutputI2SNoDAC(); mp3 = new AudioGeneratorMP3(); mp3->RegisterStatusCB(StatusCallback, (void)"mp3"); mp3->begin(buff, out); }

    void loop() { static int lastms = 0;

    if (mp3->isRunning()) { if (millis()-lastms > 1000) { lastms = millis(); Serial.printf("Running for %d ms...\n", lastms); Serial.flush(); } if (!mp3->loop()) mp3->stop(); } else { Serial.printf("MP3 done\n"); delay(1000); } }

    点赞 评论 复制链接分享
  • weixin_39722563 weixin_39722563 2020-11-27 02:50

    why don't you write an article on hackster.io or hackaday.io?

    example of similar project: https://hackaday.io/project/165020-instabeat-le-mp3-player#menu-description

    can you share the picture of your project?

    question: how have you attached the tri state buffer / MOSFET on DFPlayer?

    i have tried almost all the methods available for producing MP3 from ESP32. But, you DFplayer hacked method comes too be the best choice; i.e. value/ price. its low cost and high quality mp3 out. Don't have to put strain (low CPU intensive and low memory intensive) on ESP32, as it works through RX TX ( Not through external I2S - DAC or internal DAC ). its easy to code and easy to understand.

    ![dfplayer schema](https://user-images.githubusercontent.com/17583722/67093265-a676c480-f1ca-11e9-9769-fd8cc18b898a.jpg DFplayer diagram https://i.stack.imgur.com/QwcLV.jpg

    点赞 评论 复制链接分享
  • weixin_39722563 weixin_39722563 2020-11-27 02:50

    i have found some additional content that may be useful in making an article and videos for hackster or hackaday. it includes internal schematic diagram and attaching to USB video.

    Reference: video: https://www.youtube.com/watch?v=n8pCJTTYzZo Schematic: page:18-19 https://www.elechouse.com/elechouse/images/product/MP3%20Sound%20Mini%20SD%20Card%20Module/MP3%20Mini%20SD%20Card%20Module.pdf circuit images: https://www.mikrocontroller.net/attachment/241766/DSC08740.jpg some more videos: https://www.youtube.com/watch?v=hCRpr2SnBac https://www.youtube.com/watch?v=m_qBmrf9Ulw

    点赞 评论 复制链接分享
  • weixin_39722563 weixin_39722563 2020-11-27 02:50

    select either SDcard or Flash circuit: https://robu.in/wp-content/uploads/2017/04/Mini-SD-Card-MP3-Sound-Module-For-PIC-Arduino-WTV020-SD-ROBU.IN_.pdf

    点赞 评论 复制链接分享
  • weixin_39722563 weixin_39722563 2020-11-27 02:50

    similar module, and similar problem. you may like to answer the thread https://arduino.stackexchange.com/questions/63550/can-i-use-wtv020-sound-module-as-sd-card-reader

    点赞 评论 复制链接分享
  • weixin_39722563 weixin_39722563 2020-11-27 02:50

    easyEDA SDcard and arduino and DFplayer diagram: https://easyeda.com/Kurisu/Shield_WTV020_SD_copy-3effb6dec0e740d0a733be37ce3d7ab1

    点赞 评论 复制链接分享
  • weixin_39722563 weixin_39722563 2020-11-27 02:50

    DFPlayer schematic diagram http://domoticx.com/wp-content/uploads/2018/12/DFPlayer-mini-module-schema.jpg

    点赞 评论 复制链接分享
  • weixin_39627751 weixin_39627751 2020-11-27 02:50

    DFPlayer Mini SD card being accessed by ESP8266: server

    If one wants to do this: I simply used 2 micro AXICOM relays to toggle the SPI connections, it is interesting that the DFPlayer Mini operates with the Chip Select from the floating card, it is not used.

    Hi, please can I have the schematics of your connexion? I am working hard to connect ESP32 to DFPLAYER.

    点赞 评论 复制链接分享
  • weixin_39926040 weixin_39926040 2020-11-27 02:50

    DFPlayer Mini SD card being accessed by ESP8266: server

    If one wants to do this: I simply used 2 micro AXICOM relays to toggle the SPI connections, it is interesting that the DFPlayer Mini operates with the Chip Select from the floating card, it is not used.

    Hi, the connections between the SD card and the DFplayer are made on the PCB board of the DFplayer module, and are not available to users. To access these connections, I removed the SD card connector from the PCB board and used an external connector. Without the SD card connector, it is easier to solder wires on the DFplayer PCB board.

    DFplayer mini

    点赞 评论 复制链接分享

相关推荐