MQTT Introduction and Tutorial Part One

Message Brokers and why your IoT device should use them.

MQTT is an easy way for Internet of Things (IoT) devices to communicate with each other. This light-weight protocol can be used with a simple 8-bit Arduino to a Raspberry Pi to a multi-core PC to Amazon Web Services. It is that versatile.

This MQTT Tutorial is broken into two parts. Part one is an MQTT Introduction. You’ll understand how publish/subscribe message brokering works. Next week, Part two will be a tutorial on using MQTT to communicate between a PC, Raspberry Pi, and ESP8266.

Continue Reading »

Arduino Data Logger: Serial Monitor Alternatives

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

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 »

Multiple MQTT Topics with Arduino PubSubClient

Adding a few more subscriptions is pretty easy.

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 »

MQTT Tutorial for Raspberry Pi, Arduino, and ESP8266

Send MQTT messages between 3 different platforms

This week’s MQTT Tutorial connects a Raspberry Pi, ESP8266 (or Arduino), and a PC together. Remember last week’s post provided an overview of message brokers and MQTT. We learned that MQTT is a hub and spoke protocol for sending messages between IoT devices. Clients can subscribe or publish messages to a central server, called a broker.

Now it’s time to connect our IoT devices together!

Continue Reading »

Hands-on with Arduino Create and Arduino IoT

Arduino and Genuino have a new platform for your IoT projects

This past weekend Arduino fans celebrated Arduino and Genuino Day 2016. In classrooms, maker spaces, and impromptu meet-ups around the world enginerds got together to learn and create with Arduino. At the Jacobs Institute for Design Innovation on Berkeley’s Campus, I first heard that Arduino Create had been launched.

In addition to hands-on learning workshops, there was a display of Arduino/Genuino projects by students. In the afternoon, three Arduino co-founders gave a short talk. David Mellis spoke on Machine Learning. Tom Igoe did his first talk on Technology and Humanities. Lastly, Massimo Banzi talked about IoT.

Arduino Day, Mellis, Igoe, Banzi

Arduino Day, Mellis, Igoe, Banzi

Massimo’s IoT discussion related to the earlier announcement that day of Arduino Create. This new platform has a web-based IDE, Arduino Project Hub, and Arduino IoT.

Excited about the announcements, I spent some time with the hackster.io powered Arduino Project Hub and the Arduino IoT.  Here’s my hands-on with Arduino Create.

Continue Reading »

2016 Great Year for Enginerds

Top Tutorials from BaldEngineer.com

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 »

Seems like everyone has a project related to the Internet of Things (IoT) these days. Even I have been bitten by the bug. Understanding new terms like broker, MQTT, subscriber, and publisher can be daunting at first.

This IoT Protocols Landscape Slideshare from Paolo Patierno is an excellent overview of IoT related protocols.

Comments (0) | | Posted in Slides
Disclosure of Material Connection: Some of the links in the post above are “affiliate links.” This means if you click on the link and purchase the item, I will receive an affiliate commission. Regardless, I only recommend products or services I use personally and believe will add value to my readers. I am disclosing this in accordance with the Federal Trade Commission’s 16 CFR, Part 255: “Guides Concerning the Use of Endorsements and Testimonials in Advertising.”

Arduino to ESP8266, 5 reasons to switch

Move over Uno, there's a new board on my bench

A couple of weeks ago I posted four things to know about the ESP8266 before using one. The biggest surprise from that post is people seem to think I do not like the ESP8266! This idea is not the case; the ESP8266 is awesome. I like them so much that my Adafruit Feather HUZZAH with ESP8266 has become my go-to Arduino board.

Wait what? James uses something other than Arduino? Yes, I do! I have many different boards and have used most of them for one task or another.

However, when it came to day-to-day “make something quickly” type work, I relied on my Uno. But not anymore. Here are the 5 reasons the ESP8266 is my go-to Arduino board.

Continue Reading »

2017’s Best Bald Engineer Tutorials, Articles, and Reviews

The popular tutorials, links, and videos fans watched most.

As 2017 comes to a close, I looked back to see what readers made the most popular. It was an exciting year. The Arduino family came back together, Adafruit trolled the internet with rumors of a RadioShack buy out, and for me, I changed jobs.

Project wise I got my RetroPie SNES build completed, using an old Super Famicom case. This case is one I bought in Japan for 500 yen (about $5.) This work also led me to discuss voltage divider circuits. And I looked at a couple of scopes.

In case you missed it, here is what you as a reader found interesting over the past year.

Continue Reading »

Hologram.io connects Adafruit FONA

Send MQTT over cellular to an IoT Dashboard

While the buzzword “IoT “is relatively new, there has been a long time “internet of things” in operation. Those devices are called the far less sexy term “M2M” or machine-to-machine. These devices, around since the 90s, contain a microprocessor, some sensors, sometimes electromechanical hardware, and a cellular radio. These M2M devices were (and still are!) the early “Internet of Things.” Thanks to Hologram.io, you can join this new/old trend for free.

I decided it was time to up my IoT game with a GPRS, or 2G, data radio. In this post, I show the hardware I am using to create a 2G-based GPS tracker. It includes a Teensy 3.2 (Arduino) connected to a SIM808 Module (FONA) using a Hologram.io Developer SIM. It transmits GPS coordinates to an Adafruit.io Dashboard, which displays them on a map.

This post is not going to be a tidy tutorial. Instead, it is all the steps (and notes) I went through. I will cover:

  1. Hardware pieces I am using
  2. How to verify SIM808 (FONA) module is connected through Hologram via Serial Commands
  3. How to send HTTP/POST requests (including SSL) with the SIM808 (FONA)
  4. My (brute force) changes to the Adafruit FONA Library
  5. Code for sending MQTT payload (GPS Coords) to a dafruit.io dashboard

When done, you will be able to build something like a battery powered GPS Tracker, that updates over cellular. If you are in a rush, grab all the code from the FONA GPS Tracker Github Project.

Continue Reading »

Pi Cap Hands On Review

My first impressions of a Raspberry Pi capacitive touch hat

The Pi Cap adds capacitive touch buttons to your Raspberry Pi. Bare Conductive was kind enough to send me one. I do not have a project in mind right now, so here are my first impressions.

What is the Pi Cap?

Arduino tends to call daughter cards shields, while the Raspberry Pi community calls them hats. The Pi Cap is a hat. It plugs into the GPIO header of a Raspberry Pi and provides 13 capacitive touch pads. There is a traditional push button, an LED, and a prototyping area. While the Pi Cap does consume all of the GPIO pins, several are broken out near the GPIO header.

Continue Reading »

Adafruit Temperature Sensor Comparison

10 Options, which one is right for you?

Getting back to my IoT projects, I decided to pick up a temperature sensor. While looking through the Adafruit breakout boards, I found they offered nine different digital temperature sensors! This list is in addition to the analog TMP36 temperature sensor, so that’s ten. I needed an Adafruit Temperature Sensor comparison.

With so many options, I quickly found myself getting lost between the various modules. The 10 I found all measured temperature and provided an I2C interface. Except for the MCP9808 board, they all made at least one other type of measurement. The MCP9808 is the cheapest digital temperature sensor breakout that Adafruit offers, and also the most accurate.

I couldn’t find a comparison in my quick search, so I built my own comparison table. Here’s my chart for an Adafruit Temperature Sensor comparison of their breakout boards.

adafruit temperature sensor comparison chart

Updated: 2016-JUL-27

Continue Reading »

Sending simple serial commands to an Arduino

Don't send words when characters will do

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 »