Tag

arduino

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

Whenever someone sends me some code that doesn’t work, there are a few common Arduino programming mistakes that I check. Some of these mistakes I make myself.  In most cases my code will compile just fine. Sometimes, these mistakes won’t generate any compiler error.

When my Arduino code is acting up, these are the first things I check. Here are my 5 common Arduino programming mistakes, I use to debug non-working code.

Almost all microcontroller (and microprocessor) development systems use some form of a bootloader. Often called firmware, mistakenly, the Arduino bootloader is one example. Since it is a rather popular platform, let’s use it as an example. Let’s talk about what a bootloader does and how it works.

When a microcontroller turns on, it only knows how to do one thing.  Typically, that one thing is to run an instruction found at a specific memory location. Often this location address 0x0000, but not always. Usually, this memory location will contain a jump instruction to another place in memory, which is the start of the user program. The bootloader, however, exists in a slightly separate memory space from the user program.

On power-up or reset, a bootloader is a section of program memory that runs before the main code runs. It can be used to setup the microcontroller or provide limited ability to update the main program’s code.

A couple of months ago podcast I listen to interviewed an embedded engineer. Eventually, the topic of Arduino came up, and all three people on the show let of sighs of disgust. This lead to me to start thinking about why do engineers hate Arduino?

On this particular show, they said Arduino had too many abstraction layers to be useful. All three members of the panel agreed that direct hardware access was critical to success in embedded designs.

On the same episode, the same people talking, the topic changed to using a new chip or sensor. Then this comment was made: “I won’t design for a chip with no high-level software API and detailed examples.” (I’m paraphrasing to protect the innocent.) Everyone on the episode agreed.

Wow. Just what is Arduino then? One view is that it’s a well-documented board, with a high-level API, and lots of detailed examples. But somehow, these features on other platforms is desirable? So why do did these engineers hate Arduino so much when it is what they said every vendor should offer?

Are they haters? Are they trolls? Or are they just engineers who show a behavior common to humans. Let’s take a look at why engineers hate Arduino using other examples and concepts from psychology.