Skip to content

Instantly share code, notes, and snippets.

@purp
Last active May 18, 2020 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save purp/6de56882e29ae91946908cd940d1ec51 to your computer and use it in GitHub Desktop.
Save purp/6de56882e29ae91946908cd940d1ec51 to your computer and use it in GitHub Desktop.
Playing with an AdaFruit Feathers on Mac OS

Being a collection of digital scribbles on my adventures with Adafruit and Mac OS, with many diversions into the nature of serial ports, &c., which may be useful to the less patient practitioner

Because gist file order is ASCIIbetical:

  • notes on individual Feathers are in files with no prefix
  • notes on FeatherWings and other boards are prefixed with ~ to push them below the Feather notes
  • general notes are prefixed with ! to keep them near the top

Adafruit Feather HUZZAH ESP8266 Note: all cardinal directions here (e.g. north, southeast, etc.) refer to the board in this orientation and assume "north" is "up" towards the top of this pic

Handy reference pinout pic

Detailed pics and pinout explanations

Summary

I got this board to play with, particularly for the ESP8266 platform. I played with it while waiting for some other CircuitPython gear to arrive. Learned a bit of NodeMCU Lua, and a bit of Arduino IDE. Bricked it, reflashed to NodeMCU, and am setting it aside for a while.

Basic Setup

Needed: micro USB cable, breadboard, Adafruit Feather board

  1. Plug HUZZAH Feather into breadboard for its own protection and your future fun times
  2. Connect micro USB cable from Mac to Feather. Red and blue LEDs will flash to show the Feather has powered up and reset.
  3. OPTIONAL: Press the reset button just southeast of the micro USB port and watch the red and blue LEDs flash some more. This is good practice for later.
  4. OPTIONAL: Ground the RST pin (bottom, furthest left) for a moment and watch the red and blue LEDs flash some more. Congratulations, you don't need no steenkin' switches!
  5. Install CP2104 driver as on adafruit page. I'm not sure if this is actually required if you're using CoolTerm but I'd already installed it, so I'll include it here.
  6. OPTIONAL (but highly recommended): Install HomeBrew if you don't already have it installed. It'll make some things much easier, I promise.

Using NodeMCU Lua

NodeMCU was developed specifically for the ESP8266, so if you'll be playing with ESP8266 boards a lot it probably pays to get comfy in it. It was a board of convenience for me, so I'll make more investment later.

NodeMCU Docs Programming in Lua, 1st Ed (note: currently in 5th edition, 1st edition is free online)

Connecting to the HUZZAH Feather using CoolTerm

Adafruit NodeMCU Lua/terminal tutorial page

  1. Install coolterm via HomeBrew: brew cask install coolterm or download from Roger Meier's Freeware Site
  2. Open CoolTerm and configure it roughly as in this blog post
    1. Be sure your Feather is connected to your Mac via a real (not "charging only") micro USB cable
    2. Click Options
    3. Click "Re-Scan Serial Ports"
    4. Set Port dropdown to "usbserial-blahblah" (note: My serial port was named SLAB_USBtoUART)
    5. Set Baudrate to 9600
    6. Click Terminal (left side)
    7. Check the "Handle BS and Del Character," without which I can't use backspace[1].
    8. Click OK
  3. Connect to the board by clicking the "Connect" button
  4. Hit the reset button on your Feather.
  5. If you're connected, you should see something like: NodeMCU init message with very normal init.lua error

Connecting to the HUZZAH Feather using terminal and screen

Notes to come once I've gone down this road.

Reflashing back to NodeMCU

Notes to come once I've gone down this road. Meanwhile, you can maybe use NodeMCU devkit, the Windows emulator WINE as in this blog post, or the instructions from the NodeMCU docs

You can choose to use their cloud build facilities; I decided to go the whole way and install a full build toolchain. That was dumb (see second failed attempt, below), so I went back to using the cloud build.

  1. Configure and build using NodeMCU-Build.com
    1. Load the page
    2. Enter your email. I suffixed mine with +nodemcu (e.g. you**+nodemcu**@example.com) because I'm needlessly paranoid about email lists getting out there, and it's nice to be able to filter or spam-trap them.
    3. Configure which modules you want. I went wild the first time, and the build system sent me to a shame page for enabling too many. In the end, I enabled adc, bit, file, gpio, http, i2c, net, node, rtcfifo, rtcmem, rtctime, sjson, sntp, tmr, uart, wifi, tls
    4. Click the Build button
    5. See the confirmation email in your inbox
    6. OPTIONAL: Donate while waiting by clicking the Donation button
    7. See the "Build Complete" email arrive
    8. Download the float and integer firmware .bin files linked in the email
    9. Download the latest NodeMCU-pyflasher DMG file
    10. Open the DMG and copy the application to the Applications folder
    11. Find the app in the Applications folder and ctrl-click (aka right click) to choose Open. This avoids MacOS refusing to open it because it's not a signed app from a known developer.
    12. Configure to pull the firmware you want, etc.
    13. Click the "Flash NodeMCU" button

Note: I tried the integer.bin first and got garbage prompts on reset. This smelled like baud mismatch, so I upped the CoolTerm config to 115200 and reset again, et voila! — a misspent youth playing with modems finally pays off!

Since my purpose was to play with CircuitPython,

Notes from first failed attempt

  1. Install a sha1sum tool; I did brew install md5sha1sum
  2. Build the NodeMCU firmware (summarizing NodeMCU build docs)
    1. Download source from NodeMCU releases
    2. Unzip/untar the source and cd into the directory
    3. make clean && make because it wouldn't be the first time someone left a dangling object file around in a release

This failed with the following error:

 extracting: ESP8266_NONOS_SDK-e4434aa730e78c63040ace360493aef420ec267c/third_party/include/user_config.h
PRUNE libmain.a libc.a
/Users/purp/.nvm/versions/node/v10.16.3/bin:/usr/local/Cellar/pyenv-virtualenv/1.1.3/shims:/Users/purp/.pyenv/shims:/Users/purp/.pyenv/bin:/Users/purp/.rbenv/shims:/Users/purp/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/purp/work/nodemcu-firmware-3.0-master_20190907/tools/toolchains/esp8266-linux-x86_64-20181106.0/bin
make: xtensa-lx106-elf-ar: No such file or directory
make: *** [/Users/purp/work/nodemcu-firmware-3.0-master_20190907/sdk/.pruned-3.0-e4434aa] Error 1
make: Leaving directory `/Users/purp/work/nodemcu-firmware-3.0-master_20190907'

I need the extensa tools, so now we go hard.

Notes from second failed attempt

You can choose to use their docker build facilities; I decided to go the whole way and install a full build toolchain.

  1. Install build toolchain (summarizing Espressif docs)
    1. cd ~/work
    2. OPTIONAL: export IDF_TOOLS_PATH=~/work/espressif to change where the Espressif IDF tools will be installed/found ... I added this to my ~/.profile so it's set in all
    3. brew install cmake ninja dfu-util
    4. git clone --recursive https://github.com/espressif/esp-idf.git
    5. cd esp-idf && ./install.sh

Once I was this far in and discovered that it didn't in fact install the missing xtensa-lx106-elf-ar but instead xtensa-esp32-elf-ar it became clear I was in over my head (or at least would spend more time learning arcane spells than playing with the board) so I stopped, leaving everything installed to maybe look at another time. If I do, I should start here and here and maybe dig deeper at this.

Using the Arduino IDE

NOTE: THIS WILL REMOVE NodeMCU ... if that bothers you, read on. Arduino IDE essentially compiles your code ("sketch") and uploads it to the firmware of the Feather. This means your code will run immediately upon power up, which is handy; it also means that playing around iteratively is a compile-upload-autoreset process that takes ~20 seconds for trivial examples like the blink test. If you don't mind learning and writing Lua, that provides more immediate gratification. However, the Arduino IDE path has more instant support and better tools, so I'm going this way for a while.

Additional note: I played, reached a config with code that didn't emit, and realized I was going to have to learn all about Arduino IDE and how to debug with it ... which isn't why I came here, so I stopped and reflashed with NodeMCU to leave the board in a happy state for later play. That took a bit, but is now done and relatively documented above.

Adafruit tutorial page

  1. If you didn't install the CP2104 driver in the Basic Setup section, you'll want to do that now using the instructions from the adafruit page. Go ahead, I'll wait. It takes a while as it has to reindex all drivers afterwards.
  2. Install the Arduino IDE using HomeBrew. brew cask install arduino
  3. Open the "Arduino" app
  4. Add the esp8266 community package to the Boards Manager
    1. Open "Preferences"
    2. Add http://arduino.esp8266.com/stable/package_esp8266com_index.json to "Additional Boards Manager URLs" near bottom of the Preferences dialog
    3. OPTIONAL: Change Sketchbook location if you prefer it elsewhere; it defaults to ~/Documents/Arduino
  5. Add the esp8266 board package
    1. Open Tools -> Board: (ignore the name)" -> Boards Manager
    2. Scroll all the way to the bottom where you'll see "esp8266"
    3. Hover over that entry and you'll see a version menu that defaults to the latest version and an "Install" button
    4. Click the Install button. Wait a long time for the packages and tools to install.
    5. Close the Boards Manager
    6. Quit and restart the Arduino app? (based on "When you've restarted" and the fact that the app initializes packages at startup. Don't know if this is required or not)
  6. Configure the board
    1. Go to "Tools -> Board: (ignore name)" and choose "Adafruit Feather HUZZAH ESP8266"
    2. Click the Tools menu again, and you should see all the board config params in the menu
    3. Check that CPU Frequency is "80 MHz"
    4. Set port to "/dev/cu.SLAB_USBtoUART"
    5. OPTIONAL: Set Upload Speed to something between 115200 and 921600. The article mentions that they had successes and failures at 921Kbaud, so I chose to leave it at the default 115200 for my first flash. Then I realized how this all works and set it to 921Kbaud.

Troubleshooting

My upload fails complaining that there's no python3 but I can type python3 in a terminal and it works. WTF? I had this problem, and couldn't google my way to a solid solution. I use pyenv which puts python3 in /usr/local/bin; additionally, the pyenv shims in ~/.pyenv/shims/ are first in my $PATH. So this is clearly a path problem.

It turns out that esp8266 installs tools in ~/Library/Arduino15/packages/esp8266/tools/, including an unhelpful python script called (!) ~/Library/Arduino15/packages/esp8266/tools/python3/3.7.2-post1/python3 that looks like this:

#!/usr/bin/env python3
import os
import sys

args = ["env", "python3"] + sys.argv[1:];
os.execv("/usr/bin/env", args)

Couldn't figure out how to manipulate $PATH so I gave up, and did:

cd ~/Library/Arduino15/packages/esp8266/tools/python3/3.7.2-post1
mv python3 python3.py
ln -s /usr/local/bin/python3 .

Maybe one day I'll return to this, figure out the path or pyenv incompatibility, and submit a PR. Closest related issue I could find was this one.

Using the Arduino CLI

To come, when I'm smart enough to know how to use it.

TODOs for Future Me (or Current You?)

Which points out the undiscovered country, providing areas as yet unexplored for the intrepid adventurer

HUZZAH ESP8266

  • Explore the wifi functionality more than just connect and suck down a page
  • See how long a battery lasts if you wake, collect metrics ~1x/minute, check for threshold, and send data periodically (and check in periodically as well)

Using NodeMCU

Using Arduino IDE

  • Look at arduino-cli package in Homebrew
  • Explore Adafruit BusIO examples for i2c goodness
  • Maybe debug VEML7700 badness and lack of any serial monitor bits at all?

in which we experiment with getting a lux sensor working correctly

Using Arduino

Adafruit tutorial page

required: Arduino IDE fully set up for your Feather

  1. Install VEML770 and BusIO libraries
    1. Select Sketch -> Include Library -> Manage Libraries...
    2. Filter to adafruit veml7700 and click install
    3. Filter to adafruit busio and click install
  2. Load the VEML7700 example (File -> Examples -> Adafruit VEML7700 -> veml7700_test)
  3. Open Serial Monitor (Tools -> Serial Monitor or cmd-shift-M)
  4. Upload the code and play with lighting on the sensor

note: this didn't work with my initial HUZZAH setup, which didn't bother me as I was more interested in CircuitPython so I stopped here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment