The Arduino serial monitor is usable when you want to watch data from an Arduino. However, it does not have a built-in method for saving the data. Here are some ideas if you want to build an Arduino data logger with or without a PC.
Important note on Arduino Data Logger examples
With all of these examples, please remember that whenever you open the Arduino’s serial port, the board will reset. So if your log file shows “Initializing SD card…” with a few data lines in between, it is because there is a reset happening.
In that code you can see data logging started and then restarted. What happened is that after programming, the board starts logging. Then when you open the Serial Monitor, the data logger restarts.
To solve this issue, either disable auto-reset, add a 3-4 second delay at the start of setup(), wait for a character to be received, or wait for a button press. That will give you time to open the Serial Monitor.
Continue Reading »
The latest AddOhms looks at why you need a pull-up resistor when using push-buttons. This video goes into what happens when you leave a pin floating, what a floating pin means, and how the pull-up actually works. You can get more information about the video on the AddOhms Episode page.
This is the 2nd time I’ve made a video on pull-ups. Despite being a single resistor, it can be a difficult topic for new hardware designers to understand. The pull-up video was the first video tutorial I ever made. In fact, the YouTube version uses YouTube’s “stabilization” algorithm, which gives the video a very warped feel.
AddOhms #15 shows improvements in skill over the past couple of years!
Question: What’s another topic that I need to cover in an AddOhms Tutorial? You can leave a comment by clicking here.
Making the move to millis()-based code can be daunting. You have to rethink your logic, implement flags, program a state machine — and more importantly, start using millis(). Generally in forums and on IRC people will just point to the “blink without delay” example, hoping the commented code is enough for a new user. It’s not enough.
I have a growing list of millis()-based tasks posted in my millis() cookbook. But sometimes that those examples might be too simple or not close enough to your project’s end target. That got me thinking about different ways to help explain how millis() works. I thought “wow, you need to understand every line of an example” which leads me to: line-by-line.
Flag variables are great, and totally not evil, when you just have two states: ON or OFF. What about when you have multiple states? Is there an option better than creating multiple flag variables?
The C-language has a declaration type just for this purpose. It is called an enumeration, or enum.
Setting up a state machine with enum is a surprisingly simple. Arduino and embedded programmers should use them!
All you need to do is create descriptive tag names, and let the compiler assign them an integer value. Unlike a #define which is just a macro replacement, the compiler treats an enum as your personal variable type.
This behavior comes in handy when you’re creating states for a state machine. I show how to create a simple state machine with enum, to blink an LED with millis(), in this post.
Getting programming questions answered on the internet can be problematic. Programmers love to have opinions, stick to those ideas, and express them to you even when their opinion has nothing to do with your question(s).
Not only am I going to explain how to use flag variables in your code, I am going to encourage their use—which most programmers avoid.
However, this advice comes with two caveats.
This information only applies to limited resource environments like an Arduino, LaunchPad or PIC.
Use flag variables very carefully when you do use them.
The following flag variable usage examples are Arduino-centric but apply to any microcontroller platform, including the Energia project for TI Launchpads.