notes on using the arduino ide with the adafruit feather nrf52 bluefruit le

Adafruit Feather nRF52 Bluefruit LE – nRF52832

All of this work is done on my MacBook Pro with macOS Mojave 10.14.6 (I haven’t upgraded beyond Mojave yet because I don’t see the need on the MacBook, and if I need macOS 10.15 it’s installed on my Mac Mini).

First, let’s sort out my (miss) adventures with Arduino IDE. It started a few days ago when I decided to do something with the Feather, a device I’d purchased nearly a year prior. I’d plugged it in several times when it first arrived and I’d used the Arduion IDE’s Serial Monitor (Tools > Serial Monitor) to check it. It shipped with the StandardFirmataBLE sketch compiled and installed, so I was able to see the device’s internal configuration on the Serial Monitor as well as test it with Adafruit’s Bluefruit LE Connect app. I then put it aside and wound up forgetting about it until just recently. Adafruit still sells the device today, which is good.

It was during this restart I noticed that my version of the Arduino IDE was at 1.8.7, but the website had released 1.8.10. So I downloaded the latest IDE software and installed it.

After the IDE updated I updated the Feather’s bootloader software. That went off without a hitch. Then I started to look at the sample sketches for the board that Adafruit provides. Since it already came with the Firmata sketch installed and running, I found the source in the samples and attempted to recompile and upload. That’s when everything went screwy. Here’s an example of the error output.

Arduino: 1.8.10 (Mac OS X), Board: "Adafruit Bluefruit Feather nRF52832, 0.2.13 SoftDevice s132 6.1.1, Level 0 (Release)"

/Users/wbeebe/Git/arduino/libraries/Servo/src/nrf52/Servo.cpp: In member function 'void Servo::writeMicroseconds(int)':
/Users/wbeebe/Git/arduino/libraries/Servo/src/nrf52/Servo.cpp:92:12: error: 'g_APinDescription' was not declared in this scope
  instance=(g_APinDescription[pin].ulPWMChannel & 0xF0)/16;
            ^~~~~~~~~~~~~~~~~
/Users/wbeebe/Git/arduino/libraries/Servo/src/nrf52/Servo.cpp: In member function 'int Servo::readMicroseconds()':
/Users/wbeebe/Git/arduino/libraries/Servo/src/nrf52/Servo.cpp:123:12: error: 'g_APinDescription' was not declared in this scope
  instance=(g_APinDescription[pin].ulPWMChannel & 0xF0)/16;
            ^~~~~~~~~~~~~~~~~
Multiple libraries were found for "Firmata.h"
 Used: /private/var/folders/d9/n152_yx519121c0nlmlds71c0000gn/T/AppTranslocation/2101D1AD-76B6-4A4E-A36D-936C2672D030/d/Arduino.app/Contents/Java/libraries/Firmata
Multiple libraries were found for "Adafruit_LittleFS.h"
 Used: /Users/wbeebe/Library/Arduino15/packages/adafruit/hardware/nrf52/0.14.6/libraries/Adafruit_LittleFS
Multiple libraries were found for "InternalFileSystem.h"
 Used: /Users/wbeebe/Library/Arduino15/packages/adafruit/hardware/nrf52/0.14.6/libraries/InternalFileSytem
Multiple libraries were found for "bluefruit.h"
 Used: /Users/wbeebe/Library/Arduino15/packages/adafruit/hardware/nrf52/0.14.6/libraries/Bluefruit52Lib
Multiple libraries were found for "Servo.h"
 Used: /Users/wbeebe/Git/arduino/libraries/Servo
 Not used: /private/var/folders/d9/n152_yx519121c0nlmlds71c0000gn/T/AppTranslocation/2101D1AD-76B6-4A4E-A36D-936C2672D030/d/Arduino.app/Contents/Java/libraries/Servo
 Not used: /Users/wbeebe/Library/Arduino15/packages/adafruit/hardware/nrf52/0.14.6/libraries/Servo
Multiple libraries were found for "Wire.h"
 Used: /Users/wbeebe/Library/Arduino15/packages/adafruit/hardware/nrf52/0.14.6/libraries/Wire
exit status 1
Error compiling for board Adafruit Bluefruit Feather nRF52832.

Lots of error messages. The key to a solution is line 20, but I’ll get to that. In the meantime I went slumming on the Internet for solutions, none of which really worked, so that don’t bear repeating here. What finally got me out of this mess and allowed the sketch to compile is the removal of the libraries folder pointed to in line 20 (which none of the on-line experts never mentioned). I don’t know what happened except that something got out of sync in the upgrade to Arduino IDE 1.8.10, and that caused a cascade effect in the error messages. When I removed the libraries folder and then reloaded the Adafruit nRF52 specific libraries again, everything was just fine. The libraries folder was recreated by the IDE.

In the mean time I decided to try to run a sketch that simply flashed the LEDs on the Feather board. The listing follows.

#include <Arduino.h>

/**
 * Sketch demonstrates mutli-tasking using the Scheduler.
 * Demo creates a loop2() that runs in 'parallel' with loop().
 * - loop() toggles LED_RED every 1 second
 * - loop2() toggles LED_BLUE every 300 milliseconds
 */

void setup() {
    // whb Nov 2019
    // This must be performed first or else nothing else will work.
    // No, I don't know exactly why.
    //
    Serial.begin(115200);

    // LED_RED & LED_BLUE pins are already initialized outputs.
    // Create loop2() using Scheduler to run in 'parallel' with loop()
    //
    Scheduler.startLoop(loop2);
}

/**
 * Toggle the Red LED every second
 */
void loop() {
    digitalToggle(LED_RED); // Toggle LED 
    delay(1000);            // wait for a second
}

/**
 * Toggle the Blue LED every 300 milliseconds
 */
void loop2() {
    digitalToggle(LED_BLUE); // Toggle LED 
    delay(300);              // wait for a half second  
}

There’s far more comments than code, and that’s after not including the boilerplate block comment at the start of the code. This is from an example sketch provided when you install the Adafruit libraries. So I compiled and uploaded it, and the lights didn’t flash. Ok. I went online to Adafruit’s Feather documentation and copied an even simpler sketch that just flashed the red LED. Again, compiled and uploaded and nothing happened. The red LED just glimmered, like it did while the upload to the Feather was taking place.

I went back and looked at the major Firmata sketch, and at setup specifically, and that’s when the light went off. So I added line 15 above, and bingo, the lights started to flash like they’re supposed to. I played with a number of other sketches like this one. Load them without the Serial.begin() and nothing worked. Add that single line and it worked as advertised.

I also like this sketch because it points to the use of freeRTOS in the code. Keep in mind that the processor in the feather is a 32-bit ARM Cortex M4 processor running at 64MHz with 64K of RAM and 256K of Flash. It’s more than enough for basic embedded work, including freeRTOS. When I think back to the late 1970s and early 1980s I would have given anything to have this back when all that was available were Commodore 64s and Apple ][s and TRS-80s and the original IBM PC. This even blows the original Macintosh away with its 8MHz Motorola 68000. And here it all is now, on a board not much bigger than a stick of chewing gum and all for just $25 instead of the hundreds to thousands back then. Anyway…

The Arduino and its environment are now stable again, and I can build (in C, and possible C++) “sketches” for the Feather. This goes along with my Circuit Playground and my little Adafruit 32U4 powered robot. All of my code is checked into my Github location, https://github.com/wbeebe/arduino

raspberry pi 4b 2gb – more working observations

Arduino IDE configured to communicate with Circuit Playground Express

Working with the Raspberry Pi 4B continues. I installed the Arduino IDE version 1.8.9 (https://www.arduino.cc/en/Main/Software) and was able to quickly start it and have it working with a Circuit Playground Express. I found a sample C++ program on GitHub (https://github.com/adafruit/Adafruit_CircuitPlayground/tree/master/examples/FidgetSpinner) and created a simple project, compiling it, but not uploading it. That will come later. I just wanted to check out the basic installation to see if it worked up to a point, and it all does. My only comment is that when you download the IDE that you choose the ARM 32-bit version. It’s a standard tar file, no compression. Once untarred, then execute install.sh. It will not only place everything where it needs to be, but set up permissions, groups, and add a menu entry under Programming.

The IDE seems fully functional. One aspect of using the IDE natively on the RPi 4B with 2GB is that compiles are noticeably slower than they are on my MacBook Pro. But that’s to be expected, and the time taken is not excessive. Just noticeable.

During this period of testing I’ve also managed to force Raspbian to hit the swap space. Unlike the 1GB RPi 4B, the 2GB version’s use of swap is one to two orders less than the 1GB version with the same application load. Right now I’m seeing 4.5MB out of 2GB of swap being used, or essentially next to nothing.

Finally, I installed two more software packages, Swift for ARM and PowerShell Version 7 Preview 2 for ARM.

In order to install Swift on Raspbian Buster, you neeed to add a reference to the repo, then install Swift from that repo. Those steps are:

curl -s https://packagecloud.io/install/repositories/swift-arm/release/script.deb.sh | sudo bash
sudo apt install swift5=5.0.2-v0.4

Once installed you can run this basic test:

pi@raspberrypi:~ $ swiftc --version
Swift version 5.0.2 (swift-5.0.2-RELEASE)
Target: armv6-unknown-linux-gnueabihf
pi@raspberrypi:~ $

You can read about Swift ARM here: https://swift-arm.com/
Note that you should check to see what the current version of Swift ARM is when you install. I chose 5.0.2-v0.4 because that was what was published in the announcement on the web site.

PowerShell Core for Raspbian Buster is available as a regular tar file here: https://github.com/PowerShell/PowerShell/releases

Once downloaded, create a directory on your login home. In my case I simply created ~/powershell. Step into it and untar the newly downloaded archive into the newly created directory. Once untarred simply run pwsh. For example:

pi@raspberrypi:~/powershell $ ./pwsh 
PowerShell 7.0.0-preview.2
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/powershell
Type 'help' to get help.

PS /home/pi/powershell> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.2
PSEdition                      Core
GitCommitId                    7.0.0-preview.2
OS                             Linux 4.19.58-v7l+ #1245 SMP Fri Jul 12 17:31:45 BST 2019
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS /home/pi/powershell> 

And that’s about it.

One more thing. The Flirc case runs warm, but not excessively so. CPU temperatures seem to run between 45°C and 50°C. I’m still working on a 40-pin ribbon cable connector that will easily fit inside the case over the GPIO header.