Detect short and long button press using millis

Different actions based on how long the user presses a button

detect short long button press using millis

To detect a short and long button press using millis can give your project more functionality without adding more buttons. In this line-by-line example, I show how to react to a user pressing a button for a short period (100ms) or a long period (over 500ms). My example changes the blink rate of an LED on short presses. A long button press turns off the LED.

In the code, I make use of a struct so that a single variable can be used to track multiple parameters. The benefit of this method is that adding multiple buttons is easy. You could create an array of these tyepdef’d variables.

Download At GitHub

Continue Reading »

7805 on a SNES Motherboard

When I made the AddOhms Tutorial on Linear Regulators, I made a comment about the 7805. I said it may be one of the most important Integrated Circuits (ICs) ever made. That’s a bold statement. The 555, 805,  or 7400 might all qualify for such a distinction. My feeling about the 7805’s importance is because it is a chip that is still popular today. It is used, or at least was used, in so many applications. And it is the heart of many 5V digital systems.

Including the Nintendo Super Famicom (and I assume the US SuperNES).

This picture is from an SFC I disassembled to repurpose the case. While taking it apart, the 7805 caught my attention because it was attached to a shield as a heat sink. Also, I find it fascinating that it is one of 3 or 4 through-hole components on the entire system. As you can see from the picture, it needs some cleaning. I might post more pictures later.

Best Sorting Resistors Method 

At least, according to me.

sorting resistors method

When you buy a grab bag of components, you might need to tackle sorting resistors. Here’s how I sorted some bags of random resistor assortments last week.

Objectives

Then method I use for sorting resistors achieves these objectives:

  1. Fewer Bins. It doesn’t take long to create a large matrix of resistor values. My resistor sorting method is relatively compact.
  2. Quick to find. When I’m building up a circuit, I don’t want to spend time sorting through a pile. Once I know the value I need, I find a single package and then look for a single color band.
  3. Works with 4-band and 5-band resistors. Let me be upfront: I *hate* 5-band resistor color codes. While the 5th ring is supposed to be slightly offset, or wider, or a different type of color; it doesn’t matter. It’s nearly impossible to tell read a 5-band resistor color code when they are in a pile. However, using my method for sorting resistors, it doesn’t matter if I’m looking at a 4-band or 5-band resistor. I can immediately identify the resistor value.

Based on #3 alone, you might be wondering what is the fantastic method (and how much will it cost to get it!) Here’s the basics of my method for sorting resistors. (For FREE!)

Continue Reading »

Arduino Data Logger: Serial Monitor Alternatives

Forget the serial monitor, here's 5 other ways to do Arduino data logging

arduino data logger options

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.

Continue Reading »

Sending simple serial commands to an Arduino

Don't send words when characters will do

sending simple serial commands arduino

Sending simple serial commands to an Arduino is the easiest way to communicate between an Arduino and a computer. The computer could be a PC, a Raspberry Pi, or any device that communicates with serial.

By sending and “decoding” a single character it is easy to add a simple debug menu or even serial menu. Plus, it is easy to extend.

Single Character vs. Full Words

The mistake I see many people make is that they try to send full-text strings as serial commands. For example, to turn on a LED, I have seen (silly) commands like “RED LED ON” or “RED LED OFF.” While you could use something like strcmp(), as I showed on the Multiple MQTT Topics example, that tends to be overkill for most serial commands.

Humans like words, computers like binary. Just send one character over serial.

switch (variable) {
  case ‘a’:
	// A Stuff

  case ‘b’:
  case ‘c’:
	// B and C Stuff
  break;
}

Continue Reading »

Multiple MQTT Topics with Arduino PubSubClient

Adding a few more subscriptions is pretty easy.

multiple mqtt topics

In my Arduino MQTT Examples, I kept things simple by only subscribing to a single topic. One of the strengths of MQTT is that a device can subscribe (or publish) to multiple topics. The broker will sort things out. Even though my first example only showed one, it is straight forward to get the Arduino PubSubClient library to subscribe to Multiple MQTT topics.

The quick answer is that you need to look at the MQTT response to find out which topic sent the payload.

tl;dr version

If you’re looking for a quick answer, here’s the magic code we’ll add to the callback() function.

void callback(char* topic, byte* payload, unsigned int length) {
if (strcmp(topic,"pir1Status")==0)
  // whatever you want for this topic
}

Keep reading for a more detailed explanation of how to Subscribe to Multiple MQTT topics with Arduino’s PubSubClient. Obviously, this code will work on Arduino boards with a TCP/IP interface and, of course, the ESP8266 based boards.

Continue Reading »

It is commonly known that ceramic capacitors change capacitance with applied voltage. What isn’t always as well known is how strong this effect can be and why it occurs. At KEMET we’ve put together a technical video that answers that question.

What is Ask An FAE?

Ask An FAE is a new video series we launched at my day job, KEMET. An FAE is a field application engineer. These engineers are very common in the electronics industry. Companies like KEMET, where I work, have FAEs who meet with customers to answer technical (and very detailed) questions about how to use their products. In UBM’s Mind of an Engineer survey, FAEs were ranked as one of the top information sources for design engineers.

At KEMET we decide to use FAEs to answer the questions. While I’m not an FAE today, I was in the past and happy to kick off the series with our CEO.

Check out KEMET’s Ask An FAE

2016 Great Year for Enginerds

Top Tutorials from BaldEngineer.com

baldengineer-2016-review

While many want to call 2016 the worst year ever, I feel that is an entirely undeserved title. It certainly could have been a better year, but it wasn’t the worst that I can remember. For the engineering community, both professional and hobbyist, it seems to have been a fantastic year. My gauge for this feeling is the activity on baldengineer.com. In 2016, I saw almost half a million sessions contributing over 1.2 million page views. (That’s 98% more people looking at 313% more tutorials compared to 2015.)

Here’s a breakdown of the most visited pages (tutorials) on the site.

Overall Top 5 Tutorials for 2016

First up is a simple list with the most views, across all content.

  1. MQTT Tutorial for Raspberry Pi, Arduino, and ESP8266
  2. Raspberry Pi GUI Tutorial
  3. millis() Tutorial: Arduino Multitasking
  4. Arduino, how do you reset mills()?
  5. Top 4 transistors for your kit

Continue Reading »

ArcAttack is a band that performs at the Bay Area Maker Fare, among other places. They feature massive signing Telsa coils. (Here’s a video I show when I saw ArcAttack in 2013.) Singing Telsa coils are awesome. Everyone knows that. Which is why I found when Dianna Cowern, the Physics Girl, visited the band ArcAttack, electromagnets are just as cool. In addition to talking about their music, ArcAttack’s Joe does something amazing. He splits an aluminum soda can with just an electromagnet.

There are a few other neat tricks and some slow-motion stuff too. Near the end, he compresses a quarter with the scariest magnet setup I’ve ever seen. This video is definitely worth watching if you like anything related to Tesla coils–or electricity!

Wolfenstein 3D on Gameboy Color

http://www.happydaze.se
23-OCT-2016

Wolfenstein 3D defined the FPS genre in a way no one could have predicted. Just like the Gameboy defined portable gaming in a way no one could have predicted. Cartridge based computing and gaming offered something that disk (or disc?) based media never could: additional hardware.

The most famous example of additional hardware is the “SuperFX” chip that debuted with the SNES game Starfox. (It was in used in others in addition to a successor.) Most NES cartridges had other hardware too: mappers, sound generators, additional ram, etc. (more…)