Monday, November 22, 2021

Make an ESP8266 WiFi Temperature Sensor & Python Flask Backend - Part 4

Last time, we combined our example sketches into a functioning temperature sensor and refactored the backend to receive temperature data. This time, let's get basic plotting working. To do that, we need to:

  • Save temperature data on the backend
  • Implement an API for getting that data
  • Write a client-side JavaScript app to plot the data with Chart.js

Here's our familiar diagram; we'll focus on the items marked with an orange star.

Let's start with saving temperature data... 

Friday, November 19, 2021

Make an ESP8266 WiFi Temperature Sensor & Python Flask Backend - Part 3

In the previous article, I created a rudimentary Flask backend to receive example data from our ESP8266. Here's a further decomposed system diagram to give you a better idea of where we're going. The orange stars indicate our focus for this article.

In a moment, I'll incorporate the HttpPostClient code into the temperature sensor example, send temperature data instead of example data, and refactor the backend API to receive temperature data. The GET API, index.html, and plot.js for plotting the data will be the focus in a future blog post.

So without further ado, I'll combine our example sketches into one...

Monday, November 15, 2021

Make an ESP8266 WiFi Temperature Sensor & Python Flask Backend - Part 2

In the previous article, I used an example sketch to read the temperature sensor, and another example sketch to connect to WiFi and POST data to an API that I still have to write. 

Once I build out this basic example capability, I'll incorporate it into the temperature example and refactor the backend to receive temperature data.

As you can probably guess, next is to write a prototype Flask app, then I'll add the code to receive example data from our ESP8266. Please continue reading...

Thursday, November 11, 2021

Make an ESP8266 WiFi Temperature Sensor & Python Flask Backend - Part 1

Ok, yeah, it's true, I'm a "few" years late to the ESP IoT game. But now that I've finally gotten around to it, I thought it would be fun to start with an Internet of Things (IoT) temperature monitor as I have several use cases in mind:

  • Chest freezer monitor and alarm,
  • Measure temperature differentials between floors in my house,
  • Fish tank temperature monitoring and alerting,
  • Weather monitoring for vegetable garden
  • Template platform for deploying other kinds of sensors

For now, I'm going to prototype a temperature sensor that posts data to an API. I'll showcase several technologies and walk you through the process I use to develop projects like this. 

Here are the requirements I put together for the freezer monitor...

Thursday, October 28, 2021

Tips for Beginners: How to Eat an Elephant

That brand new Arduino of yours isn't going to code itself, is it? If you're a beginner at programming, or even just at Arduino, here's a tip that I know will help you out.

How to Eat an Elephant

If you want to make some cool project, take it a small step at a time. In my robotics classes kids that followed this approach finished faster than the ones who tried to program everything at once. 

Example

Let's say you have a project where you want to use a temperature sensor, an Arduino, and an OLED display to show the temperature. When you press a button, the display changes between Celsius and Fahrenheit.

Don't try to code all that in one shot. Instead, add tiny bits of functionality incrementally and get each new thing working before adding the next. Here is how I would approach such a project.

Step 1

First, make sure you can blink an LED. Why? You're making sure your new board works properly and that you can flash a new program to it.  In addition, the LED can be a debug signal for you in the next step.

Step 2

Next, read the state of a button. Wire up the button to one of your digital inputs with an external pull-up resistor or use INPUT_PULLUP. With a pull-up resistor, the button is pressed when the digital signal is low, and released when the signal is high. Change your blink code so that when the button is pressed, you light up the LED. When it isn't pressed, turn off the LED.

You already know the LED works so if there's a problem, you have fewer things to troubleshoot.

And that's why we started with blinking the LED.

Step 3

We'll work on the OLED display later. We want to work toward displaying the sensor reading so let's use Serial for now. Print a generic "hello world" every second using Serial.println().

In the next steps we can build on that to print out our sensor reading over Serial. Make sure you can see the message in the Arduino IDE Serial Monitor. Once this is working we can work on the sensor

Step 4

Our next step is to read the value from the sensor with analogRead() and print the result using Serial.println() and see if the value makes sense. Is it bouncing all over the place or always stuck at minimum or maximum? If so, troubleshoot. If it seems to hold more or less steady and changes according to temperature (try touching the sensor to raise the temperature), you're probably good to go.

Step 5

Figure out how to convert the value you read previously into Celsius and print that with Serial. You'll need to refer to a datasheet or tutorial for that particular sensor type. 

Step 6

Repeat step 5 but with Celsius.

Step 7

Work on displaying a generic "hello world" on your OLED display. Then try displaying a generic value. It doesn't have to look pretty just yet.

Step 8

Once you have that figured out, display the temperature in C. 

Step 9

Then figure out how to switch between C and F when the button is pressed. 

Step 10

Make the OLED display look prettier. Again break it down. Maybe learn how to display large numbers. Then work on displaying a thermometer graphic. Then work on displaying a bar graph within the thermometer. And so on.

So that's how you eat an elephant. The little bites make sure you don't have too many errors and bugs to deal with at once. It seems like every time I try to do too much at once, I'm the one getting bitten--in the butt.