Software

If this is your first time using the Adafruit Feather M0 board…intermission time! Read our Feather M0 Basic Proto guide to set this up:

Adafruit Feather M0 Basic Proto — Arduino IDE Setup

Newer versions of the Arduino IDE have been released since that guide…1.6.5 and 1.6.7 both seem to work pretty well with the M0 board.

If you have used the Feather M0 before, use the Arduino IDE Boards Manager to check that you’re using the latest Adafruit SAMD Boards support files. (For the Arduino Zero, install the Arduino SAMD Boards package.)

Before continuing, make sure you can compile and upload sketches to the board. Try the basic “Blink” example as a test.

To provide WiFi support and for our code to use certain M0-specific features, it’s necessary to download three libraries. The first of these — WiFi101 — can be found using the Arduino Library Manager interface (Sketch→Include Library→Manage Libraries…). The other two libraries are new and experimental, so they’re not in the Library Manager, you’ll need download and install these manually in your Documents/Arduino/Libraries folder:

Then download and extract the ZIP file containing the code for this project:

In this archive are two folders:

The first, “Arduino,” contains the OPCserver sketch for the Feather board (or Arduino Zero).

The second, “Processing,” contains several Open Pixel Control client demos for use with the Processing programming language. These will run on your main computer (desktop or laptop).

The client/server nomenclature may seem odd…the OPC “server” runs on the tiny Feather board, while OPC “clients” are programs running on a larger and more capable system. All the color and animation decisions are made in the client applications…the server just passes these through to the LEDs.

OPC clients can be written in many programming languages, but we’ll use Processing (a derivative of Java) as it’s free, cross-platform (runs on Windows, Mac and Linux) and is focused on visual arts.

Processing Downloads Page

For now, we recommend downloading the version 2.2.1 release of Processing for your operating system. The 3.X series introduced some significant changes that aren’t always compatible with existing Processing code.

Processing looks a lot like the Arduino IDE (in fact, the Arduino IDE derived from the same code base). This can be confusing because Arduino sketches don’t work in Processing, nor vice versa. Make sure you’re loading sketches into the correct IDE for each.

Edit Arduino Sketch

In the Arduino IDE, open the “OPCserver” sketch. We’ll make some changes before uploading to the board, to configure for your particular hardware and network.

Toward the top of the code, the following lines are of interest. They’re not in one place, but all appear in the first 50 or so lines of the sketch:

#define ADAFRUIT_ATWINC

The above line tells the code to work the Adafruit WiFi hardware. If using an Arduino Zero w/WiFi Shield 101 and Native USB, comment it out. Next, look for…

//#define Serial SerialUSB // Enable if using Arduino Zero 'Native USB' port

The above is commented out by default. Enable this line only if you’re using an Arduino Zero and are connected to the “Native USB” port (rather than the “Programming” port). Then…

#define IP_TYPE IP_STATIC // IP_STATIC | IP_DYNAMIC | IP_BONJOUR

You’ll probably leave this line as-is, which tells the WiFi module to use a static IP address (rather than dynamically assigning an address from your WiFi router). A static address makes it easier for OPC clients to access the device, as it’s always in a known location.

This requires some knowledge of how your WiFi router doles out IP addresses. Most will have a numeric range of IP addresses to assign dynamically…for example, my WiFi router starts issuing dynamic IP addresses at 192.168.0.100 and above. I can assign fixed addresses below that (except for 0 and 1) to specific devices, as long as others aren’t using them.

char       ssid[] = "NETWORK_NAME",   // WiFi credentials
           pass[] = "NETWORK_PASSWORD";

Replace the above two strings with the login credentials for your wireless network. Finally…

IPAddress  ipaddr(192, 168, 0, 60); // Static IP address, if so configured

This is the static IP address to be assigned to the device on your wireless network. As mentioned above, this requires knowledge of your router’s DHCP policy. Most will start with 192.168.0.X, 192.168.1.X, 10.0.0.X or 10.1.1.X — but not all.

Whatever address you use, you’ll need this later for the Processing sketches.

If making multiples, assign each one a unique IP address. Label them to help keep track!

A little further down in the code (around line 100) are these lines:

#define DOTSTAR_BLUEBYTE  0
#define DOTSTAR_GREENBYTE 1
#define DOTSTAR_REDBYTE   2

You probably don't need to edit these. But later, if you find the test examples are producing the wrong colors, you may need to return here and edit these numbers. This is the “native color order” used by the DotStar LEDs…it’s changed at least once in different production runs of these devices. If your LEDs are from a different batch, you’ll need to swap or rearrange some of these numbers (they’ll always be the values 0, 1 and 2, only the order changes).

Upload

Make sure Adafruit Feather M0 (or Arduino Zero if using that board) is selected in the Tools→Board, then upload the code to the board.

If the code doesn’t compile (throws an error):

  • Confirm the right board type and USB port are selected in the Tools menu. Have you installed the correct files for this board using the Boards Manager?
  • Confirm the correct libraries are installed: Adafruit_ASFcore, Adafruit_ZeroDMA and Adafruit_WINC1500 (for Feather M0) or WiFi101 (for Arduino Zero + WiFi Shield 101).
  • There may be problems if both the WiFi101 and Adafruit_WINC1500 libraries are installed. If so, remove the WiFi101 library…the WiFi Shield 101 works fine with the WINC1500 library, you’ll just need to edit some pin numbers (this is commented in the code).
  • Check that you haven’t mangled the syntax on any of the lines edited above. For example…the IP address has commas (not periods) between each value.

If the code compiles but doesn’t upload:

  • If you built the circuit with the DPDT switch, this needs to be in the “RUN” position to upload code.
  • Try uploading again. Or tap reset once or twice on the board, then upload. The M0 boards are a new thing and can be a bit persnickety what with all the different operating systems and USB port types.

Now open the Arduino IDE Serial Monitor.

If you see nothing at all, that’s actually a good sign. Or if you see a “Server listening” message, that’s good too.

If you get an unending series of periods (...), the board isn’t connecting to your wireless network. Confirm that the network name, password and provided IP address are all valid.

If everything checks out, let’s try the examples…

Last updated on Aug 31, 2017 Published on Feb 01, 2016