{"id":99,"date":"2017-07-09T18:11:03","date_gmt":"2017-07-09T16:11:03","guid":{"rendered":"https:\/\/next-hack.com\/?p=99"},"modified":"2020-06-05T20:17:35","modified_gmt":"2020-06-05T18:17:35","slug":"how-to-play-a-20-fps-video-on-arduino-26-enabling-high-speed-sd-transfers-on-a-1-8-tftsd-module","status":"publish","type":"post","link":"https:\/\/next-hack.com\/index.php\/2017\/07\/09\/how-to-play-a-20-fps-video-on-arduino-26-enabling-high-speed-sd-transfers-on-a-1-8-tftsd-module\/","title":{"rendered":"How to play a 20 fps video on Arduino 2\/6: Enabling high-speed SD transfers on a 1.8\u201d TFT+SD module."},"content":{"rendered":"<h1 class=\"western\"><span lang=\"en-US\">Introduction<\/span><\/h1>\n<p class=\"western\"><span lang=\"en-US\">Hi there!<\/span><\/p>\n<p class=\"western\"><span lang=\"en-US\">This is the second step of our \u201cHow to play a video on Arduino\u201d tutorial!<\/span><\/p>\n<p class=\"western\"><span lang=\"en-US\">For video playback we will need high transfer rates. High transfer rates are also required or desired in many other applications, so this hack might be useful even if you are not going to play a video! The Arduino\u2019s SPI can reach a clock speed of 8MHz. However, such a high speed is not supported by many shields or add-on cards. <\/span><\/p>\n<p class=\"western\"><span lang=\"en-US\">In this hack episode we will show you how to modify the popular 1.8\u201d TFT module with SD card, to enable high speed read\/write transfers.<\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-86\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A0Fig1a.png\" alt=\"TFT Module\" width=\"231\" height=\"192\" \/><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-87 alignright\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A0Fig1b.jpg\" alt=\"TFT Module back side\" width=\"255\" height=\"194\" \/><\/p>\n<hr \/>\n<p class=\"western\"><span lang=\"en-US\">This module is very cheap, and it also features an SD socket, which is handy, because we are going to store our video on the SD card. The SD signals are routed on the left, and you can directly connect them to an Arduino. However, you\u2019ll find that you cannot use a clock frequency higher than 1MHz.<\/span><\/p>\n<p class=\"western\"><span lang=\"en-US\">This is due to the 10-kOhm resistors (R3 through R5) that are in series to SD_CLK, SD_MOSI, SD_CS, to protect the SD Card when you connect the module directly to a 5-V system, such as the Arduino Uno. (see the schematics below. You can find the full schematics <a href=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/QDtech_1.8.pdf\" target=\"_blank\" rel=\"noopener\">QDtech_1.8<\/a><\/span><span lang=\"en-US\">). These resistors make a low-pass filter together with the parasitic stray and SD capacitance. <\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-110 aligncenter\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig2.png\" alt=\"Protection resistor\" width=\"359\" height=\"257\" \/><\/p>\n<hr \/>\n<p class=\"western\"><span lang=\"en-US\">The solution is to short the 10-kOhm resistors or, at least, change their values to 330 Ohm or less. Although it might still work, we do not recommend using higher values than 330 Ohms, as the signal could be too much degraded.<\/span><\/p>\n<p class=\"western\"><span lang=\"en-US\">To test our system we created a simple sketch using the Arduino IDE (you can find the complete source in the links below). We used the FAT Fs of ELM-ChaN ( <\/span><span style=\"color: #0000ff;\"><u><a href=\"http:\/\/elm-chan.org\/fsw\/ff\/00index_e.html\" target=\"_blank\" rel=\"noopener\"><span lang=\"en-US\">http:\/\/elm-chan.org\/fsw\/ff\/00index_e.html<\/span><\/a><\/u><\/span><span lang=\"en-US\"> ), which we adapted for Arduino. The test program performs a read test at 500 kHz, and a read test at 8MHz. The red LED stays on for the whole duration of the tests, and it is turned off once the read operations have been successfully completed. The green LED flashes during transfers, and stays on if the program ended successfully. The blue LED indicates if we are running at high speed (LED on) or low speed (LED off). The program advances to the high-speed phase only if the low-speed phase completes successfully. <\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-111 aligncenter\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig3.png\" alt=\"Test program\" width=\"597\" height=\"252\" \/><\/p>\n<hr \/>\n<p class=\"western\"><span lang=\"en-US\">The following images show the connections required for the test program. <\/span><span style=\"color: #ff0000;\"><span lang=\"en-US\"><b>Important! Do not use this connection after you modified the display module!<\/b><\/span><\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-112 aligncenter\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig4.png\" alt=\"Breadboard example\" width=\"395\" height=\"361\" \/><\/p>\n<hr \/>\n<p class=\"western\"><span lang=\"en-US\">The breadboard image was created with Fritzing (<a href=\"http:\/\/fritzing.org\" target=\"_blank\" rel=\"noopener\">http:\/\/fritzing.org<\/a>).<\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-113 aligncenter\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig5.png\" alt=\"Test schematics\" width=\"453\" height=\"334\" \/><\/p>\n<hr \/>\n<p class=\"western\"><span lang=\"en-US\">As you can see, at 500kHz the SD card works (the blue LED is on, indicating that the system is testing the SD card in high-speed mode, as the low-speed test was successful).<\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-114 aligncenter\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig6.jpg\" alt=\"High speed test failure\" width=\"478\" height=\"269\" \/><\/p>\n<hr \/>\n<p class=\"western\"><span lang=\"en-US\">However, at 8MHz it doesn\u2019t. Playing with the frequency settings we found that at 1MHz works too (depending on the card, even at 1MHz it might not work). At 2 MHz, it doesn\u2019t. <\/span><\/p>\n<p class=\"western\"><span lang=\"en-US\">To better appreciate how the signal is degraded at the various speed, we soldered a wire close to the SD clock input (see image below) and we hooked it up to the oscilloscope. We also wrote a simple program <\/span><span lang=\"en-US\">(download <a href=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/sd-test.zip\" target=\"_blank\" rel=\"noopener\">sd-test<\/a><\/span><span lang=\"en-US\">) that outputs one character (0xFF) to the SPI at different clock frequencies. At 1MHz the signal is already very degraded, and it\u2019s a miracle if the card still works. At 2MHz we aren\u2019t surprised that the SD does not work. <\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-115 aligncenter\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig7.jpg\" alt=\"Clock measuring wire\" width=\"380\" height=\"258\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-116 aligncenter\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig8.jpg\" alt=\"Degraded clock\" width=\"415\" height=\"240\" \/><\/p>\n<hr \/>\n<p class=\"western\"><span lang=\"en-US\">(please note that even though due to the resolution of the scope screen, it seems that the CPU creates a bad square wave at high frequencies, it actually does not: the square wave is good even at 8MHz).<\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-117 aligncenter\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig9.jpg\" alt=\"Degraded clock detail\" width=\"405\" height=\"229\" \/><\/p>\n<hr \/>\n<p class=\"western\"><span lang=\"en-US\">So, let\u2019s modify the module and check if the hack works!<\/span><\/p>\n<h2 class=\"western\"><span lang=\"en-US\">Requirements for this Hack<\/span><\/h2>\n<h3 class=\"western\"><span lang=\"en-US\">Hardware required<\/span><\/h3>\n<ul>\n<li><span lang=\"en-US\">An 1.8\u201d TFT display + SD board or equivalent.<\/span><\/li>\n<li><span lang=\"en-US\">Some wire (or some 0805 0-Ohm to 330-Ohm resistors).<\/span><\/li>\n<li><span lang=\"en-US\">A soldering iron.<\/span><\/li>\n<li><span lang=\"en-US\">Soldering wire.<\/span><\/li>\n<li><span lang=\"en-US\">A 16-pin straight male header (required only if you haven\u2019t it soldered already) <\/span><\/li>\n<li><span style=\"color: #ff0000;\"><span lang=\"en-US\"><b>3x 1-kOhm resistors (for 5 to 3.3V converter).<\/b><\/span><\/span><\/li>\n<li><span style=\"color: #ff0000;\"><span lang=\"en-US\"><b>3x 1.5-kOhm resistors (for 5 to 3.3V converter).<\/b><\/span><\/span><\/li>\n<li><span lang=\"en-US\">Breadboard (to test the hack).<\/span><\/li>\n<li><span lang=\"en-US\">9x jumper wires (to test the hack). <\/span><\/li>\n<li><span lang=\"en-US\">Arduino Uno or similar (to test the hack).<\/span><\/li>\n<li><span lang=\"en-US\">An SD-Card (to test the hack).<\/span><\/li>\n<li><span lang=\"en-US\">An SD card reader on your computer (to program the test file).<\/span><\/li>\n<li><span lang=\"en-US\">One red, one green and one blue LED, with 3x 330 Ohm resistors (to test the hack).<\/span><\/li>\n<\/ul>\n<h3 class=\"western\"><span lang=\"en-US\">Software required (only if you need to test this hack)<\/span><\/h3>\n<ul>\n<li><span lang=\"en-US\">Arduino IDE (or other C\/C++ programming environment of your choice)<\/span><\/li>\n<li><span lang=\"en-US\">This zip containing the sketch and the modified ELM Chan\u2019s FatFS for Arduino. If you wish to learn more about ChaN\u2019s FatFS, visit his website: <\/span><span style=\"color: #0000ff;\"><u><a href=\"http:\/\/elm-chan.org\/fsw\/ff\/00index_e.html\"><span lang=\"en-US\">http:\/\/elm-chan.org\/fsw\/ff\/00index_e.html<\/span><\/a><\/u><\/span><span lang=\"en-US\"> .<\/span><\/li>\n<\/ul>\n<h2 class=\"western\"><span lang=\"en-US\">Procedure<\/span><\/h2>\n<h4 class=\"western\"><span lang=\"en-US\">Step 1:<\/span><\/h4>\n<p class=\"western\"><span lang=\"en-US\">In case your SD+display module does not come with the 16-pin strip line, get one and solder it!<\/span><\/p>\n<h4 class=\"western\"><span lang=\"en-US\">Step 2:<\/span><\/h4>\n<p class=\"western\"><span style=\"color: #ff0000;\"><span lang=\"en-US\"><b>IMPORTANT! AFTER THIS MODIFICATION YOU\u2019LL NEED SOME SORT OF 5V to 3.3V CONVERSION (e.g. a resistor divider, see below!) OTHERWISE YOU MIGHT DESTROY YOUR CARD\/ARDUINO.<\/b><\/span><\/span><\/p>\n<p><span lang=\"en-US\">As said before, you just simply need to change those 10-k Ohm resistors, with anything like:<\/span><\/p>\n<p><span lang=\"en-US\">&#8211; A wire.<\/span><\/p>\n<p><span lang=\"en-US\">&#8211; A 0-Ohm to 330 Ohm resistor (i.e. 100 Ohm would be fine too).<\/span><\/p>\n<p><span lang=\"en-US\">In this example we just shorted out all the 10-kOhm resistors.<\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-102 aligncenter\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig10.jpg\" alt=\"Hacked module\" width=\"415\" height=\"479\" \/><\/p>\n<hr \/>\n<h4 class=\"western\"><span lang=\"en-US\">Step 3:<\/span><\/h4>\n<p class=\"western\"><span lang=\"en-US\">Once again, remember that, if you want to use the SD Card on a 5-V system, you will have to put some sort of 5 to 3.3V conversion in the system! A very easy way is to use a resistor divider: get a 1-k and one 1.5-k resistors, and connect them as shown in the schematics. This will lower the 5V to 3V, preventing any damage to the SD Card, while maintaining the full speed capability.<\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-103 aligncenter\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig11.png\" alt=\"Hacked module test circuit\" width=\"459\" height=\"339\" \/><\/p>\n<hr \/>\n<p><span lang=\"en-US\">For instance, you can prepare the breadboard like the picture below.<\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-104\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig12.png\" alt=\"Hacked module breadboard example\" width=\"337\" height=\"365\" \/><\/p>\n<hr \/>\n<p class=\"western\"><span lang=\"en-US\">The breadboard image was created with Fritzing (<a href=\"http:\/\/fritzing.org\" target=\"_blank\" rel=\"noopener\">http:\/\/fritzing.org<\/a>).<\/span><\/p>\n<p><span lang=\"en-US\">Please note that the breadboard drawings shows the display module wired. We did this to show where the 1.5kOhm resistors are placed. However, in practice, we will put the display as shown in the picture below: remember that there are some resistors under it. Do not push too hard, as you might short out the resistors!<\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-105 aligncenter\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig13.jpg\" alt=\"Hacked module test circuit\" width=\"485\" height=\"273\" \/><\/p>\n<hr \/>\n<h4 class=\"western\"><span lang=\"en-US\">Step 4:<\/span><\/h4>\n<p><span lang=\"en-US\">Install the latest Arduino IDE (if you haven\u2019t it yet) and download this zip <a href=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/sd-test.zip\" target=\"_blank\" rel=\"noopener\">sd-test<\/a><\/span><span lang=\"en-US\">, containing the test program.<\/span><\/p>\n<h4 class=\"western\"><span lang=\"en-US\">Step 5:<\/span><\/h4>\n<p><span lang=\"en-US\">Unzip the file in a place of your choice, and open the \u201cSD-test.ino\u201d sketch.<\/span><\/p>\n<h4 class=\"western\"><span lang=\"en-US\">Step 6:<\/span><\/h4>\n<p><span lang=\"en-US\">Program your arduino. The file contained in the ZIP is already set up for the maximum speed. <\/span><\/p>\n<h4 class=\"western\"><span lang=\"en-US\">Step 7:<\/span><\/h4>\n<p class=\"western\"><span lang=\"en-US\">Create a bmp file with about 1MB in size (do not exceed with the size, otherwise the low-speed test will take forever!), and name it \u201ctest.bmp\u201d. For instance, with a paint program create an empty 640&#215;480 24-bit bitmap and save it on the SD with the name \u201ctest.bmp\u201d. This should create a 900-kB file. (warning: of course nothing will be displayed, as the display is not connected and we did not put the code for it!)<\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-106 aligncenter\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig14.jpg\" alt=\"Creating 900kB bitmap image\" width=\"405\" height=\"231\" \/><\/p>\n<hr \/>\n<h4 class=\"western\"><span lang=\"en-US\">Step 8:<\/span><\/h4>\n<p><span lang=\"en-US\">Insert the SD card in the slot and power up the arduino.<\/span><\/p>\n<p><span lang=\"en-US\">If all is ok, the green LED should flash for a while, then after about 15 seconds the blue led should turn on.<\/span><\/p>\n<p><span lang=\"en-US\">After that, the green LED should flash much faster, and in few seconds both the green and blue led should stay on, and the red LED should turn off.<\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-107\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig15.jpg\" alt=\"High speed test passed\" width=\"1920\" height=\"1080\" \/><\/p>\n<hr \/>\n<p><span lang=\"en-US\">Here\u2019s the monitor output!<\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-108 aligncenter\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig16.jpg\" alt=\"Monitor output\" width=\"532\" height=\"250\" \/><\/p>\n<hr \/>\n<p><span lang=\"en-US\">Finally, in the scope you can notice that now the clock signal is acceptable even at 8MHz! The green LED ON (with the red LED OFF) indicates that the SD mount and file read operations were successful even at high speed.<\/span><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-109 aligncenter\" src=\"https:\/\/next-hack.com\/wp-content\/uploads\/2017\/07\/A1Fig17.jpg\" alt=\"Good clock signal\" width=\"537\" height=\"294\" \/><\/p>\n<hr \/>\n<p>Watch the videos on our youtube channel <a href=\"https:\/\/www.youtube.com\/channel\/UCH6TFYuFH6dt1wj4SCZJ1xA\" target=\"_blank\" rel=\"noopener\">next-hack<\/a>! Subscribe to get all the updates and share with your friends!<\/p>\n<p>Direct link to the video of this episode available <a href=\"https:\/\/youtu.be\/bCSYi-DaXgk\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p><span lang=\"en-US\">In the next week we will show you how to improve even more the read speed! Stay tuned!<\/span><\/p>\n<p>&nbsp;<br \/>\n<iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/a9y7tXNy91Y\" frameborder=\"0\" allowfullscreen><\/iframe><br \/>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Hi there! This is the second step of our \u201cHow to play a video on Arduino\u201d tutorial! For video playback we will need high transfer rates. High transfer rates are also required or desired in many other applications, so&#8230; <a class=\"read-more-button\" href=\"https:\/\/next-hack.com\/index.php\/2017\/07\/09\/how-to-play-a-20-fps-video-on-arduino-26-enabling-high-speed-sd-transfers-on-a-1-8-tftsd-module\/\">(READ MORE)<\/a><\/p>\n","protected":false},"author":1,"featured_media":132,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[29],"tags":[],"class_list":["post-99","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-video-arduino-uno"],"_links":{"self":[{"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/posts\/99"}],"collection":[{"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/comments?post=99"}],"version-history":[{"count":13,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":440,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/posts\/99\/revisions\/440"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/media\/132"}],"wp:attachment":[{"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/media?parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/categories?post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/next-hack.com\/index.php\/wp-json\/wp\/v2\/tags?post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}