Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Using SD cards with ESP8266's.

  1. #1
    Join Date
    Dec 2011
    Location
    UK S80 postcode
    Posts
    1,255
    Post Thanks / Like

    Default Using SD cards with ESP8266's.

    Hi, some quick notes for anyone wanting to use SD cards with their ESP8266.

    The SD card needs 6 connections and a pull-up resistor to function correctly. Two as you would expect are power, 3.3V and Ground (that's handy).
    The others are:
    CS - Chip Select = Ground to enable.
    DI (MOSI) - Data In (Master Out Slave In) = Serial data in (think of it as Rx on the SD card).
    DO (MISO) - Data Out (Master In Slave Out) = Serial data out, needs a 10K pullup (think of it as Tx on the SD card).
    SCLK - Serial CLocK = Clocks the data just like four wire pixels do.

    The ESP8266-01 is the variant that is currently most used by the DIYC community unfortunately this doesn't have enough GPIOs (General Purpose In Out) broken out to be able to use an SD card. Fortunately there are many others, the ESP8266-12 series being the next most common, comes with FCC certification and costs the same. The ESP -12 series breaks out various extra pins, three pins of particular use to us:
    GPIO 14 - HSPI_CLK - Hardware Serial Peripheral Interface bus CLocK = clock in to SD card.
    GPIO 13 - HSPI_MOSI - Hardware Serial Peripheral Interface bus _ Master Out Slave In = data in to SD card (as the SD card is a slave).
    GPIO 12 - HSPI_MISO - Hardware Serial Peripheral Interface bus _ Master In Slave Out = data out from SD card (as the SD card is a slave).
    The one to finish the set off is:
    GPIO 15 - HSPI_CS - Hardware Serial Peripheral Interface bus _ Chip Select. This doesn't work well for us as it has to be 'low' at boot.
    Note: GPIO 15 is one of the important pins that needs to be controlled at boot like GPIO's 0 and 2. Unlike these, GPIO 15 needs to be 'low' for 250mS at boot, the ESP -01's have an onboard resistor to do this the ESP -12 series don’t, so one needs to be provided, 10K is good.

    So, to get an SD card to work:
    Code:
    ESP8266-12 -------> SD card ----------> micro SD card.
    
    Vdd --------------> Pin 4 ------------> Pin 4.
    Gnd --------------> Pin 6 ------------> Pin 6.
    GPIO 14 ----------> Pin 5 ------------> Pin 5.
    GPIO 13 ----------> Pin 2 ------------> Pin 3.
    GPIO 12 ----------> Pin 7 ------------> Pin 7 (also needs a 10K pull-up to Vdd (both SD & micro)).
    GPIO 4 -----------> Pin 1 ------------> Pin 2.
    Note: SD cards have an extra Gnd on Pin 3 that micro SD cards don't have which is why the numbers are different, it is internally connected so there is no need to connect it.

    Finally the sketches - these can be found in the Arduino IDE under the following tabs:
    Code:
    File -> Examples -> SD -> ('Cardinfo' is a good one to start with).
    Note: as we used GPIO 4 for Chip Select all the sketches should run without any changes. If you get an error, that is not the cause.

    The next step for me is to be able to read Xlights files (I sequence with Xlights) and output them via E1.31 to multicast controllers.
    The output is sorted so it just the file reading to sort. Then what? Usefull for testing, wearables or moblie setups, ESPixel sticks that can play from SD with only a sync needed to reduce network trafic and mesh networking to extend ranges, who knows?
    Last edited by Barnabybear; 05-29-2016 at 05:58 PM.

  2. #2
    Join Date
    Jan 2011
    Location
    Falcon, CO
    Posts
    1,001
    Post Thanks / Like

    Default Re: Using SD cards with ESP8266's.

    To read .fseq (Falcon Player/Xlights file format) files from the SD you will need a FAT32 library. Please look at FatFS. It is made for small embedded devices and is easy to port. I am using it for the Falcon controllers. I am very happy with it. The problem with Fat32 libraries is they take several clock cycles to get anything done so throughput will suffer if you are using a slow clock (<50Mhz). A good way to cut down the data read is to allow user to select a smaller range of data to read when the file may have more than needed for that particular controller. As far as the sync signal, the Captain and I are creating a simpler sync packet for the Falcon Player system so embedded controllers can sync like other remote FPP's. It will basically use a UDP packet to discover and sync other FPP's and controllers.
    Last edited by dpitts; 05-29-2016 at 05:46 PM.
    David Pitts
    PixelController, LLC
    PixelController.com

  3. #3
    Join Date
    Feb 2009
    Location
    Plymouth, MN
    Posts
    8,930
    Post Thanks / Like

    Default Re: Using SD cards with ESP8266's.

    I think the ESP module runs native at 80mhz and can run at 160. Pretty speedy little gizmo.

    http://digwdf.com/store/
    The store were you can find blinky-flashy gizmos that you never knew existed!

  4. #4
    Join Date
    Dec 2011
    Location
    Key West, FL
    Posts
    3,609
    Post Thanks / Like

    Default Re: Using SD cards with ESP8266's.

    Quote Originally Posted by Barnabybear View Post
    Hi, some quick notes for anyone wanting to use SD cards with their ESP8266.

    The SD card needs 6 connections and a pull-up resistor to function correctly. Two as you would expect are power, 3.3V and Ground (that's handy).
    The others are:
    CS - Chip Select = Ground to enable.
    DI (MOSI) - Data In (Master Out Slave In) = Serial data in (think of it as Rx on the SD card).
    DO (MISO) - Data Out (Master In Slave Out) = Serial data out, needs a 10K pullup (think of it as Tx on the SD card).
    SCLK - Serial CLocK = Clocks the data just like four wire pixels do.

    The ESP8266-01 is the variant that is currently most used by the DIYC community unfortunately this doesn't have enough GPIOs (General Purpose In Out) broken out to be able to use an SD card. Fortunately there are many others, the ESP8266-12 series being the next most common, comes with FCC certification and costs the same. The ESP -12 series breaks out various extra pins, three pins of particular use to us:
    GPIO 14 - HSPI_CLK - Hardware Serial Peripheral Interface bus CLocK = clock in to SD card.
    GPIO 13 - HSPI_MOSI - Hardware Serial Peripheral Interface bus _ Master Out Slave In = data in to SD card (as the SD card is a slave).
    GPIO 12 - HSPI_MISO - Hardware Serial Peripheral Interface bus _ Master In Slave Out = data out from SD card (as the SD card is a slave).
    The one to finish the set off is:
    GPIO 15 - HSPI_CS - Hardware Serial Peripheral Interface bus _ Chip Select. This doesn't work well for us as it has to be 'low' at boot.
    Note: GPIO 15 is one of the important pins that needs to be controlled at boot like GPIO's 0 and 2. Unlike these, GPIO 15 needs to be 'low' for 250mS at boot, the ESP -01's have an onboard resistor to do this the ESP -12 series don’t, so one needs to be provided, 10K is good.

    So, to get an SD card to work:
    Code:
    ESP8266-12 -------> SD card ----------> micro SD card.
    
    Vdd --------------> Pin 4 ------------> Pin 4.
    Gnd --------------> Pin 6 ------------> Pin 6.
    GPIO 14 ----------> Pin 5 ------------> Pin 5.
    GPIO 13 ----------> Pin 2 ------------> Pin 3.
    GPIO 12 ----------> Pin 7 ------------> Pin 7 (also needs a 10K pull-up to Vdd (both SD & micro)).
    GPIO 4 -----------> Pin 1 ------------> Pin 2.
    Note: SD cards have an extra Gnd on Pin 3 that micro SD cards don't have which is why the numbers are different, it is internally connected so there is no need to connect it.

    Finally the sketches - these can be found in the Arduino IDE under the following tabs:
    Code:
    File -> Examples -> SD -> ('Cardinfo' is a good one to start with).
    Note: as we used GPIO 4 for Chip Select all the sketches should run without any changes. If you get an error, that is not the cause.

    The next step for me is to be able to read Xlights files (I sequence with Xlights) and output them via E1.31 to multicast controllers.
    The output is sorted so it just the file reading to sort. Then what? Usefull for testing, wearables or moblie setups, ESPixel sticks that can play from SD with only a sync needed to reduce network trafic and mesh networking to extend ranges, who knows?
    There is nothing wrong with using GPIO15 for your SD card select.

    Yes it's low at boot (via a pull down) but when you initialize your ESP to enable SPI -- the CS pin will function as expected -- turn HI when no SPI activity occurring.

    By NOT using the built in SPI CS pin -- you have added a lot of manual pin manipulation and timing that will slow your code down greatly.

    Use GPIO15 -- NOT GPIO4 -- you will be much happier.

    Joe
    Link to my DownLoad Site: [B][COLOR=#ff0000][URL]http://www.joehinkle.com/HLS[/URL]

    [/COLOR][/B][IMG]http://joehinkle.com/HLS/HLS%20Logo%20Small.jpg[/IMG]

  5. #5
    Join Date
    Dec 2011
    Location
    Key West, FL
    Posts
    3,609
    Post Thanks / Like

    Default Re: Using SD cards with ESP8266's.

    Removed - double post.
    Last edited by JHinkle; 05-30-2016 at 08:34 AM. Reason: Removed - double post
    Link to my DownLoad Site: [B][COLOR=#ff0000][URL]http://www.joehinkle.com/HLS[/URL]

    [/COLOR][/B][IMG]http://joehinkle.com/HLS/HLS%20Logo%20Small.jpg[/IMG]

  6. #6
    Join Date
    Dec 2011
    Location
    UK S80 postcode
    Posts
    1,255
    Post Thanks / Like

    Default Re: Using SD cards with ESP8266's.

    Hi, @Dave Pitts: I'll check out FatFS, I'm currently using the Arduino inbuilt library which is working OK. The bit I haven't worked out is the format of the .fseq file but that’s this afternoons job. I'll keep an eye out for details of the sync packet details, where are any updates likely to be posted?

    @JHinkle: Yes thinking about things GPIO15 will work. I came at this trying to use the same MOSI & MISO as the flash GPIO 7 and 8 but that caused lots of crashes.

    Anyway as all of my equipment currently has sockets to accept the ESP8266-01 I've had to be a bit creative to continue with development.
    ESP8266-12F_&_SD.jpg
    This is an ESP -12F on a 3D printed adapter to convert to ESP -01 then had the SD card holder tagged on. As a proof of concept it works and suggests that with the aid of a small printed circuit board, that has an ESP -12 on one side and a micro SD card socket on the other side, anything that currently uses an ESP -01 could easily be retrofitted.
    Last edited by Barnabybear; 05-30-2016 at 08:36 AM.

  7. #7
    Join Date
    Dec 2011
    Location
    Key West, FL
    Posts
    3,609
    Post Thanks / Like

    Default Re: Using SD cards with ESP8266's.

    Barn...

    I see you are using the Arduino IDE.

    I'm NOT an Arduino user so the following statement is based on past experience with how MOST Arduino code I have seen is structured.

    MOST Arduino code uses polling and not interrupts. If the code you are using does NOT use interrupts and does NOT use the internal 56 byte built in hardware SPI buffer -- then your SD card interface is running 56 times slower than it needs to.

    Just FYI.

    Joe
    Link to my DownLoad Site: [B][COLOR=#ff0000][URL]http://www.joehinkle.com/HLS[/URL]

    [/COLOR][/B][IMG]http://joehinkle.com/HLS/HLS%20Logo%20Small.jpg[/IMG]

  8. #8
    Join Date
    Jan 2011
    Location
    Falcon, CO
    Posts
    1,001
    Post Thanks / Like

    Default Re: Using SD cards with ESP8266's.

    Falcon Player is an open source project. All source is on github.
    https://github.com/FalconChristmas/fpp
    David Pitts
    PixelController, LLC
    PixelController.com

  9. #9
    Join Date
    Dec 2011
    Location
    Key West, FL
    Posts
    3,609
    Post Thanks / Like

    Default Re: Using SD cards with ESP8266's.

    Barnabybear

    I wasn't real clear on how you can kick up your SPI performance.

    The ESP has a 14 deep 32 bit buffer.

    Instead of polling for each byte (like I suspect your Arduino SPI Library code does) --- you tell the ESP to interrupt when you have the buffer full. Then you perform 14 unsigned long data moves instead of 56 polled byte fetches.

    You will find your data processing is improved by multiple factors of 10.

    If you are attempting to read the SD card AND process pixel data at the same time -- you will need every cycle savings you can muster.

    Joe
    Last edited by JHinkle; 05-30-2016 at 01:46 PM.
    Link to my DownLoad Site: [B][COLOR=#ff0000][URL]http://www.joehinkle.com/HLS[/URL]

    [/COLOR][/B][IMG]http://joehinkle.com/HLS/HLS%20Logo%20Small.jpg[/IMG]

  10. #10
    Join Date
    Dec 2011
    Location
    UK S80 postcode
    Posts
    1,255
    Post Thanks / Like

    Default Re: Using SD cards with ESP8266's.

    Hi, a quick update and thanks Joe, I'm not sure how to do that but I'll look into it as it looks like I'll need to save some time to get a good universe count, thanks.

    I’ve managed to pick the bones out of .fseq files (Xlights - or pseq as it is listed in the header), and the results are good. As you would expect there is a header and then some DMX data. I didn’t realise how much data. I created a new 30 pixel model to test with, did a 30 second sequence at 100mS timing, saved the file and then tried to read it. To my surprise the new data was at 4039 bits of data (bytes) into the file. When I went back and checked as I already had 4038 channels the new model started at channel 4039 (makes sense). It hadn’t crossed my mind that the file would contain data for models even if they where not checked as ‘part of my show’.

    But anyway, the header is 28 bytes long and has all the information I needed to work with the file.
    Data offset = the start of the DMX data (bytes 6 & 7).
    Channels = the number of channels in the file (bytes 10 to 13).
    Steps = the number of frames in the file (bytes 14 to 17).
    Time interval = the refresh timing, in mS (bytes 18 & 19).

    Note: first byte is at 0 and all values are LSB first.

    So, to read the first frame, if I know that the data starts at ‘Data offset’ and the part of interest to me is 4039 data in from the start, I know where to start reading the channels (‘Data offset’ + 4039). I also know that there are ‘Channels’ number of data for each frame, so to read the second frame I need to do the same again but add the ‘Channels’. The second frame is at (‘Data offset’ + 4039 + ‘Channels’), all cool and I can keep doing this until I get to the end of the file. Fortunately I know where the end of the file is because ‘Steps’ = number of frames in the file. So I can read a frame of data ‘Steps’ number of times before stopping or returning to the start. The last bit is the ‘Time interval’ which tells me how quickly to do this.

    I will put up my code for this, but for now:

    Loop ‘Steps’ number of times.
    Read from (‘Data offset’ + 'my first channel (4039)' + (‘Channels’ * number of times we have looped))
    Delay (‘Time interval’)
    If we have looped ‘Steps’ number of times ‘do something’, if not add one to ‘Steps’
    Back to loop start

    I have run a quick test with my very poor coding it appears I can read about 200 universes a second, which means even at 25mS refresh (40 fps) I can read 5 universes. Granted that means I have no time left to output these to the lights but as been suggested there are ways to speed up the read process.

    Another update soon, hopefully with a video.
    Last edited by Barnabybear; 06-01-2016 at 08:28 PM.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •