Skip to main content

Software

Now that your NodeMCU is connected to your lights, you must set up a development environment on your computer. The DirtyWatts microcontroller uses a tool called PlatformIO to handle uploading the C++ code to the NodeMCU.

To setup your windows/macos/linux device for development:

These are the steps. Setting up your computer to do the work is one of the hard stages, so good luck!

  1. Download and install Git if you don't have it already. You won't be using it directly, but 
  2. Download and install Visual Studio Code (VS Code)VSCode) if you don't have it already.
  3. Open VS Code and install the PlatformIO extension.
  4. Download and extract the DirtyWatts codebase from Questionable-Research-Labs/DirtyWatts.
    • Here is a guide

  5. image.png


  6. Open the DirtyWatts/MicroIndicator folder: 
    • Here is a guide

 

  1. image.png

     


Make changes to fit your device

You are now ready to start making changes to your code!

Open this file  src/config.h , there are some configuration options you might need to change:

#pragma once


#ifdef OUTPUT_NEOPIXEL
    #define NeoPixelPin D1 // D1 on esp8266
    #define NeoPixelCount 30
#endif

#define APIRequestInterval 2000	 // 20 seconds

#define ApiErrorColour 150, 150, 255  // Light Blue

This code is for telling the microcontroller which pin you plugged the data wire into.

See the #define NeoPixelPin D1   This creating a variable (a name) called NeoPixelPin and giving it the value D1. If you plugged your data wire into a different pin, you can use say what it is here. You probably don't need to do that. 

Next see the #define NeoPixelCount 30  This is making another variable (name) called NeoPixelCount. This is for holding the number of pixels in your display. The example has 30 (which is a lot). You will probably have a lot less. Count every single pixel in your display and replace the 30 with your number.

Here, you can change the colour shown when it can't connect to the Dirtywatts Servers and change how often it polls new data.

Upload the code

First, you want to check that PlatformIO can see the device. Plug your NodeMCU via a micro USB cable into your computer; if everything goes right, it will automatically pick it up.

image.png

image.png

If it doesn't show here, then your NodeMCU is detected/recognised by your computer. The first thing to check is to try a new USB cable and port. It needs to be able to carry data which quite a few of the cheap cables can't. You might need to install a driver, so check the bottom of your NodeMCU to see if it wants you to install a driver for a 'CH304g', 'CP2021', etc. As a last step, you can also reflash the firmware.

If your NodeMCU shows up, great! Let's upload and monitor the result using the PROJECT TASKS panel and expand the correct compile target according to the following table:

Development Board Name
Compile Target
ESP8266 ESP-12 NodeMCU (v0.9) nodemcu-neo
ESP8266 ESP-12E NodeMCU (v2) nodemcuv2-neo
ESP8266 ESP-12E NodeMCU (v3) nodemcuv2-neo
ESP32 Development Board esp32-neo

 If you're unsure, you can always try them all! It won't permanently brick your board, but it will fail to upload with possibly weird errors.

When you are ready, run the "Upload and Monitor" task; hopefully, it will start uploading!

image.pngimage.png

Now, you're onto configuring your device!