Archive | Arduino

On Wiring up a New Project

I’ve been working on an interactive art project as a favour for a friend of mine that would allow you to push buttons, use rotary encoders, potentiometers and so on in order to control an animated light fixture elsewhere in the room.

These controls would allow you to change:

  • Brightness
  • Display mode
  • Palettes
  • Speed
  • Toggle direction
  • Toggle glitter
  • and so on. . .

To do so, I’m using an ESP8266 enabled FastLED based lantern combined with an ESP32 based control panel. They’re both MQTT enabled, and I’ll be using an Android phone as the wifi hotspot and MQTT broker.

Here’s an email I sent about my progress in wiring and initial coding for the control panel:

I finished wiring up all the pins this morning and . . .

ABSOLUTELY NOTHING WORKED. Wouldn’t even upload to the ESP32. Got out the voltmeter and started measuring:

  1. LED was wired backwards (causing it to not upload), so I removed it temporarily.
  2. Some pins didn’t support internal pullup so I had to do some research and re-wiring.
  3. Didn’t set internal pullup correctly in the code. Found and fixed.
  4. Got digital pins working with basic digitalRead().
  5. Found an ESP32 button library, so I don’t have to worry about de-bouncing.
  6. Got that working with multiple buttons.
  7. Had to rename the analog ports and got the potentiometers working. Values were backwards, but math fixed that.
  8. Had previously successfully tested a rotary encoder library, so I added the code.
  9. One rotary encoder wasn’t working. Swapped wires, was the same encoder. Pins were OK.
  10. Had a rotary encoder soldering issue (solder blob). Fixed that and got both working as well.
  11. Soldered on a new WS2812 LED. Installed FastLED and got that working once I found a compatible pin.
  12. Got some ESP32 network code. It compiled.
  13. Got my old MQTT networking code. It compiled as well.
  14. Have smushed together my wifi/MQTT code with FastLED and the various inputs.
  15. Amazingly, it all still compiled.

Next step will be to start adding MQTT publishing functionality to each of those inputs.

So far so good. This shit takes time to do though. As <other friend> well knows, it can take a LOT of time.

In summary, things typically don’t go as expected, so it can boil down to troubleshooting techniques. Divide and conquer.

Update: The next day, I had the buttons and potentiometer working just peachy. Only problem is, that my mode selector was meant for buttons and I was trying to use a rotary encoder for that. Now have to change code for both the control panel as well as the lantern to accept the values provided by the rotary encoder. Have also got the LED on the control panel to show Red when there’s no network connectivity, Orange when it’s connected, and finally Green when both wifi and MQTT are connected.

Continue Reading

IoT MQTT Panel Pro Device Prefix

As mentioned in my ‘Getting Started’ post, I create separate ‘devices’ for my different Arduino sketches, such as mqtt-LED, mqtt-fire2012xy, mqtt-mesh, and so on. In addition, I may have more than 1 of each type of lantern displaying at the same time. To do so, I will serialize each lantern (it’s in the code) and using a combo box widget, I can then select one or ALL of each device type and publish that to the broker, which will then get picked up by the subscribing device. I’ll then use another widget to send hue, brightness to other information to the selected devices.

In order to support these multiple device types (aka sketches), I’ll add a device prefix to the topic.

For a fire2012 lantern, the published topic can look like this:

  • fire/lantern
  • fire/hue

Continue Reading →

Continue Reading

Some ESP8266 and MQTT Examples

Our first example was outlined in “Getting Started withi ESP8266 and MQTT“. This first example uses a sketch called mqtt-LED-synchronous.ino to blink the internal LED. It waits for the wifi initialization, followed by the MQTT initialization to complete before the continuous loop can run.

The second example is called mqtt-LED and appears similar to the first examples, however while the networking and MQTT code are initializing, the loop is running. In addition, if we temporarily lose MQTT connectivity, the sketch will continue MQTT transmission/reception once communications are re-established.

The third example is called mqtt-JSON and adds JSON data exchange to the previous example, allowing for more detailed information to be exchanged between the control panel and the subscribing device.

mqtt-fire is our first example using the FastLED display library. Controls in this example are a combo box, which is used to select from one or more fire enabled lanterns, while the remaining slider controls support brightness, hue, speed, cooling and sparking.

Continue Reading

Getting Started with ESP8266 and MQTT

Being able to control an Arduino remotely really ups our automation game. In the beginning, it was buttons and potentiometers and from there, we graduated to Infra Red remote control.

With the widespread availability of IoT (Internet of Things) functionality, we now have Internet connectivity to our Arduino compatible microcontrollers. One method is to setup our Arduino as a web server, and Jason Coon’s ESP8266 webserver is a prime example.

Another option is a messaging protocol called MQTT (Message Queuing Telemetry Transport) which provides a lightweight method of controlling IoT devices, and in this case an ESP8266 based microcontroller.

This tutorial goes through the steps of setting up an Android phone and an ESP8266 based WeMOS D1 Mini with MQTT controls to turn the internal LED of the ESP8266 on and off.

Continue Reading →
Continue Reading

Finishing up Arduino Nano development and onto ESP8266

At long last, after having spent far too much time developing routines for an 8 bit microcontroller that runs at 16MHz and with 2K of RAM, I’m now ready to move on to a better one. In the meantime, my routines focused on addressable LED strips and utilized:

  • FastLED display libraryshell
  • InfraRed Remote control library
  • Fast Fourier Transform library
  • TSOP38238  Infra Red Remote Control
  • ADMP401 MEMS microphone
  • WS2812 LED’s
  • APA102 LED’s

My Youtube page contains a lot of demos using this combination and is at: https://www.youtube.com/user/atuline/videos.

My github repository contains the source code for most of those demos and is at: https://github.com/atuline.

Continue Reading

Dusting off the Arduino Cobwebs

As you get older, it takes a bit of time to get back up to speed on things. In this case, I hadn’t been programming the Arduino with the FastLED display library for a few months and I started to get back into it. When I last left, I’d standardized and documented my wiring colours, pinouts and to use either the Arduino Nano or the Pro Micro. So far so good, as it was all nicely laid out for me.

I had a spare Nano kicking around, so I attached it to my USB port, started up the Arduino 1.6.3 IDE and loaded a basic FastLED program. The Nano was recognized as a Com port in the IDE (so I didn’t have clone FTDI issues to contend with), checked the code and started to program it. Despite several attempts, the code never did upload so I put the Nano aside.

Next, I got out a previously used Pro Micro and I immediately encountered driver issues with it. Remembering that I had to use Leonardo drivers, I fiddled around for half an hour with drivers, but never did get it recognized correctly. Let’s toss that aside as well.

Finally, I opened up a brand new Pro Micro, installed it, and saw that it was immediately recognized. At that point, I threw out the Nano and the first Pro Micro (I’m not very sentimental). I then programmed it up, and . . . nothing happened. I re-checked the wiring and the code a couple of times, and again, no LED’s. I then added some debug code for the serial monitor and saw that the Pro Micro was indeed being programmed correctly. I then triple checked the wiring and saw that I’d soldered part of the insulation to the data pin and had no connection. After the insulation was removed and the connection re-soldered, I tried again, but alas, no lights. Things weren’t going well today.

I checked the wiring thoroughly and saw (barely) that the data wire was also sliced halfway down its length, so I cut the wiring below the slice and then soldered that to the Pro Micro. At long last, the LED’s came on as expected and I’m now back (tentatively) in the FastLED environment.

Moral of the story: Check everything. Several times.

Continue Reading

Arduino Christmas Lights

With the recent purchase of an Arduino microcontroller, my interest in electronics was rekindled after many years hiatus. One of my goals back in the day was to create a colour organ where lghts would flash in beat with the music. With the Arduino, I can easily do that and much more, so I set about coming up with a project that made use of modern day LED’s. The result will be Christmas lights that:

Continue Reading →

Continue Reading

Arduino & Bluetooth

Was playing with an HC-06 Bluetooth board today:

http://www.aliexpress.com/store/product/HC-06-Bluetooth-serial-pass-through-module-wireless-serial-communication-from-machine-Wireless-HC06-for-arduino/318950_630840325.html

Was able to successfully pair with this from my phone and send commands via a Bluetooth terminal on the phone to the Arduino, although I found the communications very difficult to maintain. Here’s my brief review of IR vs Bluetooth communications:
Continue Reading →

Continue Reading

Costing a FastLED Display Locally

Here’s an approximate cost breakdown if I were to head into some local electronics stores to purchase components for my portable displays:

Miscellaneous items include zip tie, solder, a few sizes of heat shrink tubing.

Then there’s my labour at a minimum of $40/hr and it takes about 45 minutes to build one.

Oh, did I mention all the time I spent learning/developing the coding and techniques?

Continue Reading