Category

MSP430

Category
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.

Initializing SD card…initialized.
Temp: 34, Time: 03:24:44
Temp: 33, Time: 03:24:45
Temp: 34, Time: 03:24:46
Tem

Initializing SD card…initialized.
Temp: 34, Time: 03:24:50
Temp: 34, Time: 03:24:51
Temp: 33, Time: 03:24:52
Temp: 34, Time: 03:24:53
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.

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 works. You can get more information about the video on the AddOhms Episode page.

[shareable]Pull-Up Resistors can be a difficult topic to understand. That’s why I made this video.[/shareable]

This tutorial 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!

What’s another topic that I need to cover in an AddOhms Tutorial?

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.

  1. This information only applies to limited resource environments like an Arduino, LaunchPad or PIC.
  2. 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.