#22 Using an SD card to log data - and how to improve the reliability!

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 มิ.ย. 2024
  • How to interface an inexpensive SD Card Reader / Writer to your Arduino using an SPI bus - easier than you might think.
    I also describe some simple modifications you can make to improve the reliability of the hardware, and (courtesy of Adafruit) enhance the functionality of the library software.
    If you're logging a temperature, counting the number of bees going into your hive, monitoring the rain level or whatever you need a reliable way of logging that data to an SD card - without coming back a week later to find there is no data written to the card!
    Using an inexpensive, widely available SD module , this video tells you everything you need to know to make your SD logging module as robust as you can without breaking the bank.
    Link to the final code - remember if you get an error with the SD.end you need the new, improved library, as described here:
    Demo Code link: www.dropbox.com/sh/blpdw5mwq5...
    New, improved SD library (courtesy of Adafruit) : github.com/adafruit/SD Just click the download button and extract the SD library into your library folder and delete the original one in the library your Arduino folder (under Program Files (x86)) as this one supersedes it.
    Feel free to add comments or questions below and, as always, Thanks For Watching!
    And my channel is here:
    / ralphbacon
    How can I remember this? Memory tip: "See" Ralph Bacon, geddit?
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 148

  • @thorntontarr2894
    @thorntontarr2894 2 ปีที่แล้ว

    Your attention to data integrity is excellent. Your video is the only one I have found to highlight this aspect of data collection. I will implement including the card insert switch wire you have shown. Well done.

    • @RalphBacon
      @RalphBacon  2 ปีที่แล้ว

      Glad it was helpful!

  • @legosteveb
    @legosteveb 7 ปีที่แล้ว

    Thanks so much for this tutorial. I really enjoyed your professional approach to these videos. The information is a notch above the hobbyist level, yet still very easy to understand, and helps me make my projects more robust. I find that your videos are also very well paced. Thanks again!!!

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Thank you legosteveb! It's always good to get constructive feedback (not to massage my ego but to tell me what I'm doing right - or wrong). Don't feel shy in coming forward with questions or suggestions for future videos on any Arduino-related topic or if I am unclear in existing videos. You'd be surprised how suggestions can make me move a topic or project up the list! Thanks again for the feedback, appreciated.

  • @danielungureanu430
    @danielungureanu430 ปีที่แล้ว

    I lost two days trying to find a solution. My intuition was that it should be an .end function also. So, you put and "end" to my nightmare. Thank you Sir!

    • @RalphBacon
      @RalphBacon  ปีที่แล้ว

      Sorry about your two lost days but I'm happy you got it sorted! Time well spent! 🤷

  • @legosteveb
    @legosteveb 7 ปีที่แล้ว

    On a separate note, I wanted to thank you for literally making my imagination come true. I had seen on other videos issues about ejecting the SD card. I imagined there should be a card present pin, or some inserts/eject pin. Especially when there is that funny clicking sound when you insert the card. Watching your video confirmed my thought experiment. :-) I did not know about the adaFruit library or that I even needed it, because I haven't started adding/writing the code for the SD card yet, but then again that is why I watch your videos.

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Hang on, legosteveb, "other videos"? You mean other people are doing this sort of thing too? Jeez, who knew?. Heh heh! Anyway, glad it helped, I can't believe they didn't add this functionality to the card itself, very short-sighted don't you think (perhaps better makes do add it, who knows)? But now we know how to fix it, ta-da!

  • @kobedde
    @kobedde 6 ปีที่แล้ว +4

    Clearly explained, this makes a lot clear. Nice tip for removing the card. Thanks Ralph!

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      Thanks for your post, Eddy De Schrijver, glad you liked it, good to hear from you.

  • @digihz_data
    @digihz_data 5 ปีที่แล้ว +1

    The pin 5 hack was lovely to find out about. And the adafruit upgrade of the lib.

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว

      Thanks for that, Hans Sandberg, nice to hear from you.

  • @johnrees44..G4EIJ
    @johnrees44..G4EIJ 4 ปีที่แล้ว

    Ralph..Thank you for an amazingly informative video.. As a novice in this technology, It's as though a 'light has come on!'..Thank you..John..Bristol..UK

    • @RalphBacon
      @RalphBacon  4 ปีที่แล้ว

      Glad it was helpful!

  • @porlando12
    @porlando12 6 ปีที่แล้ว

    Very insightful video! Thanks for the great content. Subscribed!

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว +1

      Glad you liked the video (only 99 others - and increasing - for you to watch now!). Thanks very much for subscribing.

  • @douglasthomson2986
    @douglasthomson2986 6 ปีที่แล้ว

    Great stuff. Love it. Very well explained. Thanks.

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      Thanks for that, Douglas Thomson, nice to hear from you.

  • @unglaubichuberlieber8048
    @unglaubichuberlieber8048 5 ปีที่แล้ว

    thank your for your clear detail explanation

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว

      You are most welcome unglaubich uberlieber, I'm glad you like the video. Nice to hear from you.

  • @tuananhbui3844
    @tuananhbui3844 ปีที่แล้ว

    That what i have found for a week ..... Thank you so so much !!!

  • @RalphBacon
    @RalphBacon  8 ปีที่แล้ว

    Demo Code link: www.dropbox.com/sh/blpdw5mwq5p7sv1/AACaqXSsjNwjfPzGbYjFh1DSa?dl=0
    New, improved SD library (courtesy of Adafruit) : github.com/adafruit/SD Just click the download button and extract the SD library into your library folder and delete the original one in the library your Arduino folder (under Program Files (x86)) as this one supersedes it.
    Any issues, comments or queries just post back here!

    • @jimgiffau
      @jimgiffau 6 ปีที่แล้ว

      Hi Ralph, the link is broken can you please provide a working one?

    • @jimgiffau
      @jimgiffau 6 ปีที่แล้ว

      No John and Ralph has not replied either... Sorry

  • @weerobot
    @weerobot 5 ปีที่แล้ว

    Awesome clear video...

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว +1

      Glad you liked it, WeeRobot, thanks for posting.

  • @porlando12
    @porlando12 6 ปีที่แล้ว

    It would be useful to incorporate the built-in LED (pin11) to flash during various SD conditions. For example, set the default 1-second blink for normal data logging, and then incite a rapid flashing sequence when the card is removed, or is not being written to after re-insertion. I'm definitely going to play around with this example to make things easier for data logging in the field!

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      That's the spirit, Philip, get experimenting! That way you learn a whole lot more (even if it doesn't turn out the way you hoped for). But then again, Things turn out best for people who make the best out of the way things turn out. It's true!

  • @lindsaydempsey5683
    @lindsaydempsey5683 3 ปีที่แล้ว

    Brilliant video, thank you, very clear and concise great pace and explanations. I'm new to Arduino and was looking at adding to a project car, and being able to do logging would be extremely useful. Do you have any sage advice for someone looking to integrate a Mega 2560 via CAN with an aftermarket ECU?

    • @RalphBacon
      @RalphBacon  3 ปีที่แล้ว +2

      Glad it was helpful! Unfortunately I'm not familiar with CANBUS but I bet someone has done something, so Google is your best friend in this instance, Lindsay.

  • @simonmasters3295
    @simonmasters3295 6 ปีที่แล้ว

    Thank you Ralph B...you saved my Bacon! ;-)

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      Glad I could help, Simon, thanks for posting (and the pun)!

  • @MrEdwardhartmann
    @MrEdwardhartmann 3 ปีที่แล้ว

    Great video - how can it only have 396 likes after 6 years??? Question - have you used the SD module on an STM32 Blue Pill?

    • @RalphBacon
      @RalphBacon  3 ปีที่แล้ว

      I don't know why either! No, I've never used the SD card, it should run on SPI like others?

  • @robertparenton7470
    @robertparenton7470 2 ปีที่แล้ว

    Thank You!

  • @joeblow2109
    @joeblow2109 6 ปีที่แล้ว

    Hi Ralph, nice video.. but maybe in other videos you could start with a flowchart. and could you run that sketch that is in the arduino (the SDcard driver) to run a sketch like (LED blink) from the SD card?
    Cheers

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      More explanation at the start could be useful, indeed, I will certainly consider it. But running any program from an SD card is not possible with the Arduino, it must be loaded into program memory that is on chip (well, *in* chip, really). External memory, whether SD card or EEPROM is only for data of one sort or another. Thanks for the suggestion Joe.

  • @alibro7512
    @alibro7512 4 ปีที่แล้ว

    Thanks for this really great video, I'm just learning how to use Arduino so still struggling with the programming as I haven't written anything since I had my VIC20 in the early eighties and the differences are huge. I'm slowly working my way through your videos and picking things up as I go.
    Just a thought but how would you put a time stamp beside each number as well as the counter?

    • @RalphBacon
      @RalphBacon  4 ปีที่แล้ว

      Glad it was helpful! The timestamp that you mention, do you mean in the debugging (Serial Monitor) window? There is an option in the Arduino IDE, a checkbox in the Serial Monitor window, "Show timestamp" which does this. Otherwise, there is no way that the Arduino knows what the time is, as it has no wifi nor Real Time Clock to get that information.

    • @alibro7512
      @alibro7512 4 ปีที่แล้ว +1

      @@RalphBacon I was thinking of a time stamp in the txt file but that would require a real time clock module as well so I guess can't be done.
      Thanks for the reply.

    • @RalphBacon
      @RalphBacon  4 ปีที่แล้ว

      It _can_ be done with extra hardware, like a real time clock or wifi access but natively it can't, you are correct.

  • @shingabiss
    @shingabiss ปีที่แล้ว

    Thanks for this, very well done. One thing I added, because the serial monitor wasn't showing anything is:"
    while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
    }

    • @RalphBacon
      @RalphBacon  ปีที่แล้ว

      Ah, yes, that is sometimes needed for some microcontrollers (not the UNO, though).

  • @subishkanna6326
    @subishkanna6326 6 ปีที่แล้ว

    Very useful....thnq

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      Glad you found it useful, Subish.

  • @homoevolutus
    @homoevolutus 6 ปีที่แล้ว

    You flipped the MOSI and MISO acronyms at the 2 minute mark. Great vids. Keep them going!!

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว +1

      Oh, my goodness, you're right I did! Oh well, I hope it is obvious to my viewers that the acronyms are out of sync with the text and make the necessary mental adjustment. Eyes of an eagle, you have there, Dane! But I'm glad you like my videos and thanks for posting (I think)!

  • @oncledan282
    @oncledan282 4 ปีที่แล้ว

    Hi Ralph. Ingenious !! I'll keep this in mind .. but ti's too late for my « WWS » project .. or not. I'll see. LOL
    Take care!

    • @RalphBacon
      @RalphBacon  4 ปีที่แล้ว +1

      I think this trick only works on full sized SD cards, Daniel, which are rarer than hen's teeth these days. But I am only guessing, it may work for the mini SD card readers too.

    • @oncledan8509
      @oncledan8509 4 ปีที่แล้ว

      @@RalphBaconWell, all the better. I just might change the microSD card reader for the standard one .. ans redraw another PCB !! LOL But the SD card remains inserted all the time .. it's only there to keep the last 384 readings for the graphic part to the project. Naaah ! This project has to end somewhere now, does it ! LOLOL ..

  • @TechMan-sl5gf
    @TechMan-sl5gf 7 ปีที่แล้ว

    On one of the projects I have coming up in about a year. I will need to use a SD card. However, because of limitation in Arduino for the task at hand I will be using the CHIP SBC. But I will be using the Arduinos for data collection and sending the data to the CHIP for processing, refinement, storage and display through a web server. The actual number of Arduino cards will be around ten at my last count. But could be much more but no more than 20.

    • @RalphBacon
      @RalphBacon  7 ปีที่แล้ว

      Wow, that sounds like a project to keep you busy for a while! One point to consider when data collecting, is reliability. How do you know that data is actually being collected - or will you find at the end of the day that you have an empty SD card? Perhaps you are collecting it frequently so you will be aware? It all depends on how important the data is, I suppose! thanks for letting us know this and keep us posted when you actually implement as it's always good to hear about Real Life projects.

    • @TechMan-sl5gf
      @TechMan-sl5gf 7 ปีที่แล้ว +1

      The reasons is I don't have the time it would take to check each battery, cell, pack which is still undecided as it should be on a normal PMI (Preventative Maintenance Inspection). So, the originally thought was to monitor each battery, cell, pack on a per minute bases for volts, amps and temp on the solar/wind system. Then I got to the point where I said, alright measure the lot. This will tell me if something is going bad, loss of performance, and lack of equipment. So, more a logical decision can be make before it's an expensive one.

  • @dioutoroo
    @dioutoroo ปีที่แล้ว

    Hi Ralph, thanks for the video. This is great since I am working also in data logging with Arduino. I have a question, can we not directly from the pin but the data that already processed in the loop. E.g., I have incremental encoder data which I already manipulated to get angle, angular velocity etc. Is that possible to write to the SD card? Thanks again

    • @RalphBacon
      @RalphBacon  ปีที่แล้ว +1

      Yes, you can, if I understand you correctly.
      The SD card is "just" another file system, so you can write to it whenever you want. The best way is to write a function that opens the file, writes the data, then closes the file. That way no data gets lost (or corrupted) if your sketch crashes whilst the file is open.

    • @dioutoroo
      @dioutoroo ปีที่แล้ว

      @@RalphBacon Thank you for your answer, Sir. One more question, I watched your other video with TFT LCD Touchscreen. How can I wire the TFT LCD Screen so that its SD Card slot can be utilised to stored data as well? Thanks again

    • @RalphBacon
      @RalphBacon  ปีที่แล้ว

      The SD card on the TFT uses the SPI bus (as does the screen) and the CS pin just brings that "on line" so you write/read whatever. You won't be able to use SD Card Slot and TFT simultaneously, it's whichever is "active" by the CS pin being LOW.

    • @dioutoroo
      @dioutoroo ปีที่แล้ว

      @@RalphBacon I see. Clear now. Thanks, Ralph! Appreciate it

  • @johnrees44..G4EIJ
    @johnrees44..G4EIJ 3 ปีที่แล้ว

    Hello again, Ralph..I have the data logger working perfectly, thank you.. I need to buy some sd cards..Could you tell me what type/s of sd card the reader will accept, please? Will it work with SDHC type cards?.. Thank you..John.. Bristol

    • @RalphBacon
      @RalphBacon  3 ปีที่แล้ว

      I haven't tested this but I would be surprised if this simple SD card reader accepted SDHC card. 32Gb is about the max you can use here. That said, 32Gb is an awful lot of text data. I once had the addresses of every single house in the UK and it was just a few hundred Mb.

    • @johnrees44..G4EIJ
      @johnrees44..G4EIJ 3 ปีที่แล้ว +1

      Thanks for your reply, Ralph...Looking again at the opening frames of the vid, isn't that sd card in the background an sdhc type?
      The capacity wont be an issue here..I had the logger running for several hours, and the file size was amazingly small! Thank you.. John

  • @jimgiffau
    @jimgiffau 6 ปีที่แล้ว

    Hi Ralph, any chance of the code with the pin 5 routine? - The original Dropbox link is broken. I would really appreciate it and so would one of my friends. Thanks Jim.

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      Hey Jim, I've battled with DropBox and have now moved the sketch to a new folder, you can find it here:
      www.dropbox.com/sh/blpdw5mwq5p7sv1/AACaqXSsjNwjfPzGbYjFh1DSa?dl=0
      I've updated the link in the comments too. So sorry I did not spot your comment from about a month ago, I missed it but now I am testing a new tool to keep track of the increasing comments I get on this channel. Anyway, any issues in accessing this do let me know.
      FYI Dropbox removed their "public" folder facility so the old links now fail; I tried to move as many as I could but this one escaped!

    • @jimgiffau
      @jimgiffau 6 ปีที่แล้ว +1

      Thanks Ralph! I now have it.

  • @andykoornneef5221
    @andykoornneef5221 3 หลายเดือนก่อน

    Have you found a module that has that pin set up already? I have a hard time soldering that small a connection and the wire fell off. Thanks

    • @RalphBacon
      @RalphBacon  3 หลายเดือนก่อน

      Unfortunately, unless the seller states that it's already connected you will not be able to rely on it. As the seller probably doesn't even know about this "hack", they probably won't even be able to confirm or deny whether it's been done.
      My best recommendation is to try a "big brand" supplier (Digikey, Mouser, RS Components... et al) as they (a) may have better quality components and (b) may respond to your query. You may end up paying quite a bit more but at least it will be what you want.

  • @viktorhugo8252
    @viktorhugo8252 ปีที่แล้ว

    Cool SD-Card error detection

    • @RalphBacon
      @RalphBacon  ปีที่แล้ว

      Glad you found it useful, Viktor!

  • @gabrielenriquemartinezllan9224
    @gabrielenriquemartinezllan9224 6 ปีที่แล้ว

    Can I use this Arduino library to use SDHC cards (the one used in smarthphones)?

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      It depends on the ability of the SD card reader - read the specs of the device to see whether it can successfully read SDHC cards (or even higher capacity) as I suspect the higher capacity might mean a more expensive SD card reader/writer module.

  • @mrphysh
    @mrphysh 5 ปีที่แล้ว

    Two years later...does a more recent SD library include the SD.end() ....(good video)

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว

      I must admit I haven't used an SD card recently - these days I just store small data fragments in the EEPROM. If you are wanting to do an SD.end() that means you want to do an SD.begin() with a different device (insert a different card)?
      If so, see if this article can help:
      github.com/esp8266/Arduino/blob/master/libraries/SD/src/SD.h
      It might work for the Arduino as well as the ESP8266.

    • @micromouseonline
      @micromouseonline 4 ปีที่แล้ว

      @@RalphBacon I just downloaded Arduino 1.8.10 and the SD library now includes the SD.end() method.

  • @searegarsiregar2533
    @searegarsiregar2533 6 ปีที่แล้ว

    If I want to send data to sd card every 10 minutes once (or 5 minutes or 20 minutes), how to do? thank you

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว

      Well, you could just put in a delay in your program but it all depends on what else you expect the sketch to be doing. Is it doing anything at all or just waiting?

  • @johnrees44..G4EIJ
    @johnrees44..G4EIJ 4 ปีที่แล้ว

    Hi Ralph.. I have another question for you, if you don't mind.. I've made a data logger from your vid, and it works well..But the data strings are being received via serial every two seconds, and they are terminated with 'cr lf'. This is giving me, in the log, a blank line between every line of data.. There is nothing I can do to stop the cr lf being transmitted, so, my question is, do you know of a way to remove the cr lf from the string at the data logger to prevent that line feed? Thank you for your time.. John.. Bristol

    • @RalphBacon
      @RalphBacon  4 ปีที่แล้ว

      If you have access to the individual strings you are writing to the logfile, then you can replace the CR/LF ASCII 13/10 (or 10/13) pair with spaces (ASCII 32). A String (capital S) in Arduino is just an array of char, so you can iterate over the String inspecting each char and when you find the pair replace them. Make sense or did I lose you at (13/10)?

    • @johnrees44..G4EIJ
      @johnrees44..G4EIJ 4 ปีที่แล้ว

      Ralph S Bacon Thank you for your reply.. So, it can be done..I just need to find out how to do it on the net.. Thanks again for your help.. John..Bristol

  • @GSXRcop41
    @GSXRcop41 5 ปีที่แล้ว

    What I would like to do is create a circuit that reads and writes to/from the SD Card, without using an Arduino. To do that, I would need to know what commands through binary the SD Card uses... Where can I find information on that?

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว

      You could (probably) find that information in the SD card's datasheet, Dave. It may be, however, that it merely describes the I2C or SPI commands it expects. I would love to know why you want to write to an SD card _without_ an Arduino or Nano attached - at approximately £2.50 / €3.00 / $3.00 the cost of trying to do this without an Arduino must surely be considered?

    • @GSXRcop41
      @GSXRcop41 5 ปีที่แล้ว

      I like to know the inner workings of things and have an ability to build something with core components. Obviously, most of the time that is impractical and ridiculous. It is more about the satisfaction of accomplishment. As I am learning more electronics and things about them, I like to know how to at least build something up at the base transistors and the like. An idea I had though, came from another video I watched, which explained the operation and communication between a Commodore 64 computer and its disk drive. And, if I could understand the workings of the SD card and the C64 serial port, it would be interesting to build a solid state drive for the C64 that functioned like its original disk drive. As far as the use of an Arduino, I've never used one, but I am early in the learning electronics thing too.

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว

      OK, I applaud your enthusiasm but consider this: writing to an SD card is done via an established protocol, usually SPI. This is a relatively complex set of related signals on 4 wires.
      Before SPI was invented, manufacturers did what you are now suggesting: build a bespoke set of logic circuits to generate the right pulses at exactly the right time. It cost a lot to develop and everyone in the industry was very relieved when the I2C and SPI (among others) protocols were invented.
      If you were building a house you would not consider making your own bricks. You'd get them from a brick company by the pallet load as you have bigger things to consider than how the bricks were actually made and from which exact mixture of sand, clay and lime.
      I'm just suggesting that being able to generate SPI signals without an Arduino or other µController) is an academic exercise these days. You're welcome to try but I don't envy you the task. Why not use an Arduino to get the SD card to play nice and then consider what else that Arduino could do (other than just logging temperature information, for example)? You could achieve your goal of building stuff and get the satisfaction of doing so this way.
      Just suggestin' nothing else!

  • @johnrees44..G4EIJ
    @johnrees44..G4EIJ 4 ปีที่แล้ว

    Ralph..I wonder if you would mind answering a 'feasibility' question for me please..I would like to 'data log' a serial data stream from an electric car over several sessions (Not F1, so not much data, and not fast!)..but between those sessions, power is removed from the car AND the logger.. Is it possible to configure an Aduino/SD reader to cope with this, as there would be no provision for manually closing down the logger before power is cut..and no provision for manually restarting the recorder once power is restored..or...could it be made to work if the logger had an integral battery?.. Your thoughts would be appreciated..Thank you.. John Rees..Bristol

    • @RalphBacon
      @RalphBacon  4 ปีที่แล้ว

      Killing the power to an SD card logger is the greatest cause of SD card corruption, John. You can mitigate this by programming each write within an OPEN and CLOSE statement but that really slows things down.
      What you need is an Arduino shield with an ATTiny85 and a push button that allows it to ask the Arduino to please shut down and tell it when it has shut everything down (and closed the SD card) so it can kill the power.
      Guess what? Watch video #173 for the background and video #176 for the implementation. If you need a board I have the Gerber files (or design files if you want to change it). I designed the PCB to accept either SMD or through-hole components, so it looks more complicated than it is.
      If you get that far (that you think this is the perfect solution) let me know! I'm still amazed at how wonderfully this simple design works (look at the circuit diagram to see how simple it is).
      Using a battery (to answer the second part of your question) is feasible for short durations, assuming you are using a full blown UNO with lots of LEDs and suchlike) but that can die on you too. I have a solution for this too, where the battery voltage is constantly monitored and once it gets too low allows the Arduino to shutdown gracefully before the battery turns off. Video #171.
      So many options!

    • @johnrees44..G4EIJ
      @johnrees44..G4EIJ 4 ปีที่แล้ว

      Ralph S Bacon ..Wow...Many thanks for you time and your reply..I'll have a look at the videos you suggested later ..My first thoughts (as a total, uninformed novice☹️)is that a self contained battery powered unit might suffice..The data to be stored is created during several sessions over the course of a day totalling around five hours or so.. What if the car had a socket feeding the serial out. A small, self contained, dedicated unit with (say) a Nano, an SD module and a battery (no display, leds etc..) could be switched on and plugged into the car at the start of play, and removed and 'gently' switched off at the end of the day. Do you think that's feasible.. or is that a very silly idea☹️? John

    • @RalphBacon
      @RalphBacon  4 ปีที่แล้ว

      It depends on what you mean by "gently switched off", John!
      As long as you ensure the SD card is closed (in code) before power is removed you _should_ be OK! I'd certainly test that hypothesis a few times before I found out the hard way that my day's data was gone! A cheap option would be to have TWO SD card loggers with the data written to both (mirrored). Only you can determine what it would mean to lose a session's data. Irritating, but not the end of the world? Or something that cannot be replicated?
      A single 18650 battery, rated at 2000mAH should run a Nano and SD card (~80mA - 100mA) for a full day. That's running at the 4.2V - 3.3V of such a battery, which I would think would be fine for the SD card (certainly OK for the Nano). You can even get a battery holder for such a battery that will give you exactly 3v3 or 5v from it (see video #116).
      Could be a simple solution!

    • @johnrees44..G4EIJ
      @johnrees44..G4EIJ 4 ปีที่แล้ว +1

      Thank you again, Ralph..
      By 'gently switched off' I meant having the file closed, and the device then being powered down..as you suggest it should be done..maybe with the push of a button...
      Re: loss of data..It would be annoying, but not the end of the World..We usually have recorded radio telemetry from the car, so the data logger would be a backup...and vice versa..
      Thank you for your advice re batteries..and indeed, your advice re everything else!..I now need to watch some more of your videos, and try to put something together☹️..I'm hoping there might already be some examples of the code I will need, out there, ...to take in serial and write it to SD..
      Thank you so much for your time and advice..and your patience.. I look forward to watching more of your videos.. John

  • @billglass5160
    @billglass5160 2 ปีที่แล้ว

    Thanks for this information. Very useful but....I was initally planning to use an SDCard but it requires a lot of Arduino Nano program(40%) and data(49%) memory.I was able to add an external EEPROM AT24C256(32768x8) module to my Sensor prototype. My sensor program and data memory requires 50%,72%. After installing the EEPROM module it uses only 53%,72%.
    I am able to log approx. 28000 characters (2000 14-character strings). This enables me to monitor more than a week of sensor activity (air & water temperature, humidity, pool water level, Internet information, etc.). In addition, if I neglect checking the EEPROM when it is full, I added a circular address mode for the EEPROM. When I DO check it, I always have the most recent week's activity.

    • @RalphBacon
      @RalphBacon  2 ปีที่แล้ว +1

      Sounds like you have a solution there, Bill, just be sure you don't log continuously to the same EEPROM address at it will eventually fail. Some sort of wear-levelling algorithm might be required (others have trod that path before you so plenty of examples out there).

    • @billglass5160
      @billglass5160 2 ปีที่แล้ว +1

      @@RalphBacon Thanx Ralph. Yes, I keep the current string address at 0x7ffe,0x7fff.
      Logging 10 strings every 2hours==>43800 strings/year, 100000 logs in 2.3 years. So writing to these same addresses will start to fail around June, 2024 according to the spec. Interesting problem to study with deadline date aforementioned. Hmm.. "wear-leveling algorithm". Sounds interesting. I was also thinking of automatically changing this string address function of day of the week (or month). Cheers!

    • @billglass5160
      @billglass5160 2 ปีที่แล้ว

      @@RalphBacon Hello Ralph. Thanks to your comment about writing to the same address, I modified my algorithm. I don't store the current log address in the EEPROM anymore. I just log info starting at a flag(0xff) stored in the EEPROM. This flag is at the end of the previously-logged string. OK, it takes a few seconds to find it. But, I only do that once during setup(). I store its EEPROM address in global RAM & update it every log. I'm still in circular mode so this flag just goes 'round in circles. Works fine and avoids changing worn EEPROM modules for around 125 years! I would be more than happy to share my code if you or anyone else is interested. Cheers!

    • @dariovicenzo8139
      @dariovicenzo8139 ปีที่แล้ว

      @@billglass5160 interested here!

    • @billglass5160
      @billglass5160 ปีที่แล้ว

      @@dariovicenzo8139 I can send you this library if you're interested.

  • @nuwanharsha1361
    @nuwanharsha1361 3 ปีที่แล้ว

    Why there are 2 ground pins in this module? Why only one of them is connected to ground in here?Can somebody help me?

    • @RalphBacon
      @RalphBacon  3 ปีที่แล้ว

      There are often multiple ground points on modules, just for convenience. On the ATMega328P chip, however, the GND connections are split: one for analog and one for digital to prevent one half of the processor interfering with the other. They eventually get all connected together.

  • @gigabit7079
    @gigabit7079 ปีที่แล้ว

    But as I understood from other videos, was that this sd card reader can't be used with all pins connected to the arduino because it uses signals on 3.3v, but arduino digital ports use 5 v.
    So, something to bring the voltage to 3.3 should be done to connect it to some of the pins.
    Is that wright?

    • @RalphBacon
      @RalphBacon  ปีที่แล้ว

      The SD card I showed here most definitely was 5v tolerant (maybe it even _needed_ the full 5v, not 3v3, to work) so what makes you think it's not OK?

    • @gigabit7079
      @gigabit7079 ปีที่แล้ว

      ​@@RalphBacon Actually I am just in doubt.
      I'm using it for the first time, and I'm afraid of burning my sd card reader because of other videos showing apparently the same module (standard sd card size) tell a voltage adjustment should be done as the standard sd card reader works with 3.3v level of signal .
      At this link, ( 03:40 ) there is something telling that.
      th-cam.com/video/PQhQfww-qGQ/w-d-xo.html
      And here, another link where the guy shows how to make the voltage divider to use with the standard sd card.
      reader.
      th-cam.com/video/lIG5Yb4pS6Y/w-d-xo.html
      Would be great not having to add a voltage divider to the project, but,
      what is your opinion about it?
      Thanks. 👍🏻👍🏻👍🏻🙂

    • @RalphBacon
      @RalphBacon  ปีที่แล้ว +1

      The SD module that I use (shown here: th-cam.com/video/GQjtG1MeVs4/w-d-xo.html ) will accept 5v input on the pin marked +5 and it has an on-board voltage regulator (that big black blob, an AMS1117) that outputs 3v3.
      This 3v3 output is connected to the SD card reader as well as the header pin marked +3.3 so you are OK to use a μController with either 3v3 or 5v output - just connect it to the correct header pin.
      The link you included above to EduArduino (Portuguese) also uses exactly the same module as me. As he states, the module supports "alimentação de 3.3V ou 5V" so I think we are OK to use either - just use the correct header pin!

    • @gigabit7079
      @gigabit7079 ปีที่แล้ว +1

      ​@@RalphBacon Thank you so much Ralph. 👍🏻👍🏻👍🏻

  • @nexuzinnovation-com
    @nexuzinnovation-com 3 ปีที่แล้ว

    hi Ralph, is there any reference to the MicroSD Card pin that can be used for SDMissing pin ?

    • @RalphBacon
      @RalphBacon  3 ปีที่แล้ว

      I must have found something on the Internet regarding that pin but this video is now 4 years old so I don't have that information any more, sorry.

    • @nexuzinnovation-com
      @nexuzinnovation-com 3 ปีที่แล้ว

      ic, I manage to find MicroSD Card socket pinout diagram but the detection pin is at pin 9, the datasheet at:
      www.sunrom.com/m/3735
      I still cannot find Full SD Card socket pinout diagram and why you selected the 5th pin, if based on card diagram itself as shown below the 5th pin is CLK which I doubted we can interrupt the CLK signal if the 5th pin on the adapter socket really is CLK pin as well.
      www.electroniccircuitsdesign.com/pinout/sd-microsd-card-pinout.html
      However, as most of devices are made in China, so I do found a Full SD Card datasheet as link below, but the detection pin is still at pin 9.
      www.sunrom.com/p/full-sd-card-socket

    • @RalphBacon
      @RalphBacon  3 ปีที่แล้ว

      It sounds like I have a different SD reader to you then.

  • @rexsace7104
    @rexsace7104 4 ปีที่แล้ว

    Hello, I have a question.
    If I want to retrieved the data from the SD card, do I really have to remove it from the module?

    • @RalphBacon
      @RalphBacon  4 ปีที่แล้ว +1

      That's how I do it, Rex, but you don't have to. You can read the data from the SD card and send it up the TX/TX pins, but you would then need a program on your PC/MAC to interpret that. Bound to be many examples out there in the Internet. If the device is remote you could use an nRF24L01+ to transmit the data (32 bytes at a time) too.

    • @rexsace7104
      @rexsace7104 4 ปีที่แล้ว

      By program, do you mean something like TeraTerm, PuTTY, etc or Python, Javascript? and will it still the need of the SD card module?

    • @RalphBacon
      @RalphBacon  4 ปีที่แล้ว +1

      I mean writing a program on your PC/MAC that communicates with your Arduino. Your Arduino then sends back what it reads on the SD card. Your Arduino has to be attached via a USB cable to do this. Alternatively...→
      Alternatively you could consider sending the data into the cloud, as I do in my Home Alone project (see video #154). Basically, your WiFi enabled Arduino uploads the data periodically to the IoT (Internet of Things) cloud. It's amazingly easy to do (and free), and it's how I monitor the data from my Mum's apartment in Germany, from my workshop in the UK. You could get all this working, as a proof-of-concept, in one working day.
      If you need more detailed information, Rex, find my email address in the About tab (from a PC, not your mobile) and we can explore ideas.

    • @rexsace7104
      @rexsace7104 4 ปีที่แล้ว

      I've sent my reply to your email. Thank you

  • @josephtannenbaum8696
    @josephtannenbaum8696 3 ปีที่แล้ว

    Also R1 on this module does not go to cs. Goes to pin 8 & 9

    • @RalphBacon
      @RalphBacon  3 ปีที่แล้ว

      CS would normally be used as the Chip Select pin when using SPI so that makes sense.

  • @joeblow2109
    @joeblow2109 6 ปีที่แล้ว

    Also no one on youtube seems to know that you can enlarge the font in the arduino IDE...... it's always tiny :( ............. Please youtubers) increase your font.
    Just a gripe ;)
    Cheers again.

    • @RalphBacon
      @RalphBacon  6 ปีที่แล้ว +1

      Point taken Joe, although I try and zoom into the relevant bits I guess a bigger font is a much better idea anyway. Thanks for the nudge.

  • @Thingstest-rl8xu
    @Thingstest-rl8xu 5 ปีที่แล้ว

    Good to find better SD library and sketch. Video shows full size card socket with mods but seems that most Micro SD modules for Arduino and Pi have the same issue. Have you tried this with micro cards in standalone module or part of display or other shields?

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว

      True, the mini or micro socket is preferred these days and no, I haven't tried on either of those formats but it could easily be the same fix.

    • @Thingstest-rl8xu
      @Thingstest-rl8xu 5 ปีที่แล้ว

      Looking at more SD breakouts... Some support card detect switch like some Adafruit RobotDyn and SparkFun items but many others do not and can be very hard to add a line because of card socket used. So watch what you buy if you need this output. Other sockets can change how pins work... some micro sockets are pin 10 for card detect but not all. Note that many board say support 5v like in your video but I/O lines are 3.3v with pull up resistors and can fry SD cards or have other problems using 5v SPI without adding level shifting. I have same board because have many full size cards and easier to change them outside. Finding a micro dropped in grass is no fun.

  • @Banzay20
    @Banzay20 5 ปีที่แล้ว

    If I have an I2C sensor (BME280) could I put it on pin A0?

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว

      The short answer is No. The longer answer is Maybe. Read on!
      The standard I2C pins on an Arduino UNO (that is, any board with an ATMega328P chip on it) are A4(SDA) and A5(SCL). These pins are obviously not being used for Analog purposes, but are used as standard GPIO pins 18 & 19.
      You can "bit bang" I2C to make it work on any pin (I do this on ATTiny85s that don't have I2C built in) but it could be a little hit and miss. There are bound to be libraries out there that offer this, possibly to give the Arduino UNO a second I2C channel.
      The question I should have asked is: Why do you want to put a sensor on A0 in the first place?

    • @Banzay20
      @Banzay20 5 ปีที่แล้ว

      @@RalphBaconI want to log (temp, pressure, humidity) on a sd card, and I found a sketch that uses A0 as an sensor input and my programming skills are limited. learn.adafruit.com/adafruit-feather-m0-adalogger/using-the-sd-card
      Im using the Addalogger M0 with an integrated SD slot.
      Most sketches seems to be using analog input when reading temp, pressure.. etc.. So far I could not find a sketch that uses I2C as input for this purpose. So Im looking around for the easiest way to make this possible. I was thinking maybe I can use some sort of built in DAC to achive this..
      Any suggestions are appriciated.

    • @Banzay20
      @Banzay20 5 ปีที่แล้ว

      ​@@RalphBacon forget what I wrote I found some code..

  • @greghill4683
    @greghill4683 5 ปีที่แล้ว

    when i went to verify it, it said "CS not defined" and highlighted line 24, any tips?

    • @greghill4683
      @greghill4683 5 ปีที่แล้ว

      sorry "CS was not declared in this scope" was the exact error message

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว

      I'm looking at the two sketches I wrote for this (way, way back in 2016!) and there's no mention on line 24 of anything CS. The CS line is used in SPI communications so I'm wondering whether the SD.h or SPI.h you are using have changed since then.
      So I've copied the libraries I used when creating the sketch. Use this link to get them (it's a DropBox folder):
      www.dropbox.com/sh/blpdw5mwq5p7sv1/AACaqXSsjNwjfPzGbYjFh1DSa?dl=0
      Place the entire SD folder in your libraries folder for your Arduino workspace.
      Then let me know how you get on.

    • @greghill4683
      @greghill4683 5 ปีที่แล้ว

      @@RalphBacon I uploaded the library and at first it still wasn't working. I dug around in the library's files and later google and found that the pin's are different than in 2016. CS is now called SS so i changed that and it worked. Thanks for the help and the vid.

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว

      Great you got it working, Greg, and thanks for letting me know. I just wonder why author would make such random, breaking change when it would have been simple to keep the CS definition as well as the new SS definition. Sigh. At least it keeps us on our toes!

  • @abbygecali4208
    @abbygecali4208 5 ปีที่แล้ว

    Is Data Logger can retrieve data ? thank you.

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว

      Yes, indeed, Abby, it's very easy to read back the data.
      In fact, the project I am currently working on does just that. It reads back some configuration items but reading plain data would be even simpler.
      The commands you need to investigate are SD.read(), SD.readBytesUntil(), SD.readStringUntil(). The read() will read just one character (byte) at a time so I suspect the "readuntil" functions may be what you need. Good luck.

    • @abbygecali4208
      @abbygecali4208 5 ปีที่แล้ว

      Ralph S Bacon the data logger is used to read data??

  • @josephtannenbaum8696
    @josephtannenbaum8696 3 ปีที่แล้ว

    Module does't detect write protect either.

    • @RalphBacon
      @RalphBacon  3 ปีที่แล้ว

      It might not actively detect but if you try and write to a write-protected SD card it will fail - can you detect the error code that way?

  • @91Cyclops
    @91Cyclops 5 ปีที่แล้ว

    You seem to be connecting the SD module direct to Arduino without a level shifter for the signal lines. Don't SD cards work on 3.3V? I can't see a level shifter on the SD card board, only a voltage regulator.

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว

      That rather large (full sized) SD card I used in the demo was a 5v card. I'm not even sure they are sold any more; who uses full sized SD card these days? The much smaller ones (mini/micro) I use now are 3.3v tolerant only. At the time of making this video I had no smaller ones - and it made the video a bit easier to make anyway without a level shifter. Well spotted.

    • @LuberthDijkman
      @LuberthDijkman 3 ปีที่แล้ว

      @@RalphBacon and everyone
      Blows their 3.3v micro cards
      Set the bits forever

  • @typingcat
    @typingcat 3 ปีที่แล้ว

    The GitHub page says that it is superseded by SdFat which uses FAT16/FAT32/exFAT. I had heard that Microsoft was taking (or robbing) money from Android manufacturers fur using FAT several years ago, and to make sure, I searched Google and it was still not royalty-free (all of them, including exFAT). I don't mind paying a royalty for an excellent piece of work, but FAT series suck and I guess the only reason companies still use them is due to their compatibility with Windows. Installing a file system driver on Windows is not that hard, so I wish they used a different file system, one that is open-source, royalty-free and not locked by a giant monopolistic company.

    • @RalphBacon
      @RalphBacon  3 ปีที่แล้ว

      But the FAT code will still work, right? Just use whatever works for you. Unless you are creating a commercial product there is no need to worry about who owns what licence.

  • @HelmutHassfurther
    @HelmutHassfurther 5 ปีที่แล้ว

    Have made the modification according to the video on the same SD card reader and LOW when card is inserted is given.
    Serial output:
    Setup begins
    SD Card initialisation completed successfully
    ------------------------------
    SD Card not found / responding
    Insert a formatted SD card
    ------------------------------
    looks like only a begin () is possible.
    There is a bug that prevents repeated begin. found this:
    "The SD.h library has an old bug that prevents a second call to begin()."
    // siehe: forum.arduino.cc/index.php?topic=324923.0
    /*boolean SDClass::begin(uint8_t csPin) {
    // Performs the initialisation required by the sdfatlib library.
    // Return true if initialization succeeds, false otherwise.
    if (root.isOpen()) root.close(); //

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว

      There is an updated Serial library that has a Serial.end() function, Helmut, specifically so that multiple Serial.begin() calls could be made. Have a go!

    • @HelmutHassfurther
      @HelmutHassfurther 5 ปีที่แล้ว

      @@RalphBacon thank you for this quick responce
      i had another try after checking that i use the right sd.h:
      Setup begins
      SD Card initialisation completed successfully
      ------------------------------
      SD Card not found / responding
      Insert a formatted SD card
      ------------------------------
      ------------------------------
      SD Card not found / responding
      Insert a formatted SD card
      ------------------------------
      ------------------------------
      SD Card not found / responding
      Insert a formatted SD card
      ------------------------------
      1 data value now 211
      ------------------------------
      SD Card not found / responding
      Insert a formatted SD card
      ------------------------------
      Curiously, there was a 0-byte file called 'sdlog.txt' and 'dataLog.txt'. very strange.
      With another SD card it works fine.

    • @RalphBacon
      @RalphBacon  5 ปีที่แล้ว

      That look as though your SD card is faulty. Perhaps the gold fingers need a good clean? I've had SD cards that just stop working for no reasons that I can think of. And you say another SD card worked OK? That does indicate the first SD card is, in some way, not working properly.

  • @asagk
    @asagk 4 ปีที่แล้ว

    That is sadly a pityfull video, Ralph!
    Closing the file over and over again all the time, while each time the will be writen into the file system blocks what length is the file after appending a single byte. You actually write the card to garbage, since the number of write cycles is very limited on those cards. A better choice might be to keep some amount of data in the atmega328 memory and then write from time to time blocks of data to the card, to reduce wear out of the sd-card. Otherwise you will have to throw away the card already, after writing just a small amount of data.

    • @RalphBacon
      @RalphBacon  4 ปีที่แล้ว

      You say that, Sebastian, but if you are collecting the temperature in a greenhouse every 5 minutes, the last thing you need is the power to go off after 10 reads before you write them to the SD card. I think the SD is more robust than you give it credit - my RasPi runs off an SD card no problem, just a bit slow.

    • @asagk
      @asagk 4 ปีที่แล้ว

      @@RalphBacon If you put your "/tmp", "/usr/tmp" and "/var/tmp" onto sd-card, instead of having it in memory, you will see that within a few month the card is wrecked. The reason is, all cheap flash devices have guaranteed write cycles of about 10.000 to 25.000, and in reality you get away with somewhat like 50.000 physical write cycle for a single cell. So the problem of updating superblocks (unix) or fat base-directory every some seconds is obvious ... it makes the card fail, while writing to the very same cells over and over again. Just to test it, take a very cheap card and do the stuff in the video every some milliseconds and check how many comitted writes (close/reopen) will make the card fail. --- It does not too much really, at a high writing frequency, while unix buffers writes for some time, before the real physical writing (sync) to card will take place. That is what makes a major difference to the plain writing with an arduino, if you do no buffering. So buffering is a good choice. If you fear to see the arduino fail, write the stuff temporarily into some external I²C-EEPROM (some 100.000 to >1 million write cycles) and when you got some data collected, write the whole shebang onto the card. A small and cheap I²C-EEPROM is good enough ( 24LC64 = 1k*8 @ 0.13€, 24LC512=64k*8@ 0.71€ [source:Reichelt]). If the price does not matter, I²C-FRAM that comes with 10^12 read/write cycles is also a choice ( Cypress FM24C16B-G = 2k*8 @ 1,80 € [Reichelt]) for buffering sd-card read/writes.
      So perhaps keep in mind, unix does the buffering internally (file system driver) when writing to an sd-card, that your arduino sketch didn't. Btw. The buffering comes from times when harddisks were slow, and a lift-algorythm was used to minimize hard disk head movements. So the buffering enabled to put writes and reads into a queue sorted for minimizing head movements. The buffering still works very well, since it also gets rid of single byte writes by keeping a copy of the block in file system cache and keeping that until the block sees no more changes and some time has passed by. Then the block is actually written. The only two other situations where blocks are written, even while their content still changing, is when 'shutdown' is announced or 'atrun' via 'cron' take place, since 'atrun' and 'shutdown' perform a number of 'sync' commands to synchonize the mass storage to file system cache contents. So sd-cards tend to last some longer in a rpi for reason of buffering and optimization by reducing the number of physical writes.

    • @asagk
      @asagk 4 ปีที่แล้ว

      @@RalphBacon BTW. You can check 'sync' writes by issuing 'sudo sync' which makes the write-led flicker, indicating that unsynchronized blocks were in the file system cache available for writing while not writen on its own at that point in time. Unix is very nice stuff at things like that!
      ps. If you use an I²C-buffer of 2k*8 and you write a single byte every second, while having a guarantee of let's say 1 million write, you can buffer 2048 million bytes over time, writing at 2k blocks each onto your sd-ccard. That is at least 2gbyte of data written as buffered blocks. with an FRAM the number of bytes is by far larger when it comes to buffering.