Communicating with an Arduino

Noodl can connect to external hardware using MQTT, a standardized protocol that's commonly used in IoT solutions. MQTT is a lightweight protocol where multiple clients communicate via a broker.

This guide will go through how to use Noodl to control a NeoPixel Ring, connected to an Arduino MKR1000. It can also be used as a reference on how to connect other types of devices that can communicate with MQTT, the steps in Noodl are the same.

Noodl will use MQTT for all messages that are sent and received with the Send Message and Receive Message nodes. This includes communication between multiple devices running Noodl and is not limited to external hardware.

Creating the Noodl project

Start by creating a new project, or download the finished project. Add the Ui Kit from the library by adding it from the library list.

Add three sliders from the library in Noodl and create a Send Message node. Add the sliders to a Stack Layout and set the Max Value of the sliders to 255. The Ardunio will be able to set the color of the NeoPixel using three values between 0 (no light) and 255 (maximum brightness), one value for red, green and blue. These three colors can be combined to achieve almost any color.

Select the Send Message node and set the Topic to neopixel/color and add three ports to the payload - red, green and blue. Enable Send on Change so messages are sent when inputs are changed, and enable Rate Limit and set it to at 10 messages / second.

If Rate Limit is disabled, Noodl will send around 60 messages per second when adjusting a slider. This is a bit too fast for the rest of the system to process and will introduce delays. Around 10 seems resonable, but feel free to experiment.

Connect the first slider to red, the second to green and the third to blue.

By default Noodl will send MQTT messages with the payload encoded as stringified JSON. A message with red, green and blue set to 10, 20, and 30, will encode the payload as {"red":10,"green":20,"blue":30}. CSV is also supported and is a bit more efficent since it's less verbose. It would encode the payload like this: "10,20,30". The order of the values are sent in the order the payload is added to the Send Message node.

The next step is to write the code for the Arduino MKR1000. We'll connect to Noodl's broker, subscribe to the neopixel/color topic, parse the payload, and send the color to the NeoPixel ring.

Download the Noodl project

Writing the Arduino code

The Ardunio code consists of the following steps:

  1. Connect to Wifi
  2. Connect to Noodl's MQTT broker
  3. Subscribe to the topic neopixel/color
  4. Wait for an incoming message
  5. Parse the payload as JSON and send the color to the NeoPixel ring

Download the code for the Ardunio

You need to install the following libraries:

Instructions on how to install libraries can be found here.

Tip: If you get the error "No device found" when trying to upload your code, press the reset button twice and try again.

Message Tracker

Noodl comes with a MQTT visualization that you can access in the application menu through Debug -> Open Message Tracker. It shows all connected devices and the messages being sent, which is great for debugging and understanding what's happening in a Noodl project.

Sign up to noodl newsletter

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.