Suggestions for using external flash SPI

@RWB, I will design for either FTP or HTTP so you need to tell me if you will host the files on a web server or not. Otherwise I’ll just use FTP. :wink:

@peekay123 I can do either. Is there a reason to choose one over the other from your point of view?

@RWB, with you hosting the files, the code will look more like what you will ultimately use. Did you have a preference for HTTP or FTP?

@peekay123 I guess HTTP is easiest since it will eliminate the username and password to log in correct.

@RWB, sounds good. Can I assume you’ll host some choice BMPs on a server of yours then? :yum:

@peekay123 Yes I can do that but can you provide a format that this file needs to be in.

Can you provide an example file so I know the format that this should be in since I have no idea what exactly this file should look like or what it should be named for proper operation.

Once I know what you need I’ll upload a few files for testing. :smiley:

@RWB, I’ll create a few BMP files in photopaint and save them as 1-bit depth files (monochrome) and send them to you.

@peekay123 I ask because I’m used to copying the bitmap images into a .H file after running it through a bitmap image to byte data converter software.

So it looks like now we will be able to save all images in regular bitmap file format? If so then that is great :grinning:

@RWB, yes, that’s the idea. :yum:

1 Like

Sweet because those converters caused me image issues quite a few times in the past for unknown reasons.

1 Like

@peekay123 Here are a few hosted bmp files I found on my computer from the past.

The website defaults to HTTPS but when I paste the link using the HPPT it works also so let’s give these image links a shot as see if they work. If they do not I’ll host on another site :grinning:

http://cdn.shopify.com/s/files/1/0072/9612/files/Eco_Friendly.bmp?717468280202512201 

http://cdn.shopify.com/s/files/1/0072/9612/files/EcoFriendly2.bmp?630431577921338315

http://cdn.shopify.com/s/files/1/0072/9612/files/USA7.bmp?12871440921743019762

http://cdn.shopify.com/s/files/1/0072/9612/files/Hud5.bmp?2857250061315454343

@RWB, @Suprazz, quick update. The downloadFile code generously provided by @Suprazz did not work when attempting to download one of the BMPs from the links provided by @RWB. The first part of the response from the server quickly flooded the 128 byte tcp buffer and so the code always failed with an End of header not found error. I didn’t want to spend a lot of time working on the FSM to get it working so instead I used a version of HttpClient with a dynamically allocated response body buffer to download the entire file in one go. This works well and so does writing that buffer using SPIFFS. For the Eco_Friendly.bmp file, it is a full-screen 400x240 image requiring 12K buffer.

Eventually, getting @Suprazz code to work makes more sense in terms of resources but I wanted to focus on the file-to-display code for now. As it stands, I am working on the BMP parsing customized for the SharpMem display. Since each byte of file data represents 8 pixels with an x/y position that may or may not align to the display buffer byte boundaries, I have to use the drawPixel() method for drawing each pixel.

It is possible to add constraints to make things faster. By making a bmp image that has a width which is a multiple of 8 pixels (ie bytes) and by forcing the corner x/y position of the image to a display byte boundary, the image data could be written directly to the buffer instead of via each pixel. Food for thought.

I’ll report back when I make more progress. :wink:

3 Likes

Thanks for all your hard work on this Paul!

I would never been able to figure all that out myself.

I felt like a genius simply because I was able to successfully add code to the CAP1188 capacitive touch library to read and write to new data registers on the chip :grin:

2 Likes

@RWB, got the basics working! All four images are loaded into flash and getting displayed. A full screen image takes abour 520ms to load and display from flash.

However, there remains a few items to work out:

  • Monochrome BMP files are packed so 1 byte = 8 pixels. The width of some images don’t use the full “last” byte and the code doesn’t deal with that right now.
  • The code loads one byte at a time from the flash. It may be faster to load a full row and then convert it to pixels.

As you know, loading images into flash uses a dynamically allocated buffer and is probably overkill. Streaming the data into flash like what @Suprazz does in his code is better. However, his FSM needs tweaking to properly capture the data. BTW, the four files, which include 2 full screen images, take up 36,468 bytes on the flash. :smile:

@peekay123 Sounds great

520ms to load a full-size image is plenty fast :rocket: I assume smaller graphics will load even quicker.

So if the image size is not divisible by eight then currently it will not display right correct?

Is this a brick wall problem or just something that will require some thought to code correctly.

I didn’t think this was going to turn into so much work but if your down to keep moving forward then go for it :smiley:

I plan on upgrading to a same brand and model line 16MB flash chip if it only requires a simple code change to the chips memory size.

Would this 16MB Flash Chip work fine? Same model line: http://www.mouser.com/ProductDetail/ISSI/IS25LP128-JBLE/?qs=sGAEpiMZZMtI%2bQ06EiAoGzgXX1v4VMAS1FJK7rHCmk0%3D

Let me know what you think and thanks for all the effort!

@RWB, got it working with any size image now, even sub-byte-wide images. I’ve optimized the bmp draw code to pull a image row at a time so now the full screen display is now down to 209ms :yum:

I’ll be testing with more images to be sure all is good. Rewriting the file download so it doesn’t use a large file buffer would also be good.

2 Likes

@peekay123

The speed increase is great!

Is the only limit on file download size the total capacity of the Flash memory chip?

1 Like

@RWB, the file download size is currently limited by the RAM buffer size I use for downloading the entire file. By streaming the file to the flash, any size file could be downloaded with the limit being the flash size minus the tiny overhead imposed by SPIFFS.

@RWB, I have the http file loading working without having to allocate a full file RAM buffer. Everything works nicely. One note is that the existing flash library (Adafruit_TinyFlash) can only handle a 1MB chip as it was designed for the ATtiny85.

@peekay123 Man you know how to get the job done :+1:

Good to know that the Adafruit_TinyFlash library has a 1MB limit.

1MB would hold approx 720 - 144x80 Pixel images which is plenty enough to do some cool stuff.

This method of pulling files into flash by using a direct weblink is awesome because it makes the process easy for the non-experts. I can see this method being used to in other projects to pull in color images for LCD’s, and audio files also but that would require more than 1MB of memory.

Would using a larger Flash chip just require a different Flash library that is not nearly as compact as Adafruit’s TinyFlash library? Or is it more complicated than that?

I assume that the Adafruit TinyFlash library is just a whittled down version of the full Flash library to keep the code size small.

Also, with your test code that includes the Memory LCD library how much free memory is left on the Photon?

Great work!