HowTo: Downgrade Scosche Rhythm+ Firmware

REVISED 20180116

In my previous article, HowTo: Upgrade Scosche Rhythm+ Firmware, I showed how to update Scosche Rhythm+ firmware via their Fitness Utility iOS app. Some people have had issues with the 3.01 firmware installed by the latest V2 Fitness Utility, notably incompatibility with certain apps, and/or flaky readings.

I contacted Scosche via live chat, and they told me that there was no way to downgrade from 3.01, except for sending the unit back to them. The V2 Fitness Utility no longer has a Firmware Update button, so there’s no way to use it to install any firmware other than v3.01. Instead of sending mine back to them, I decided to try to get a hold of an older version of Fitness Utility, in order to downgrade the firmware. It turned out to be a very laborious and time consuming procedure. I was hoping that I could share the IPA file of Fitness Utility 1.4.1 so everyone else could save a lot of time, but as reader Hap noted in the comments below, IPA files are tied to specific Apple IDs.

If you want to downgrade your firmware yourself, rather than send it back to Scosche, follow the rather lengthy and complicated procedure below.

To obtain the older version of Fitness Utility, I loosely followed the procedure from How to legally download any previous version of an App Store app through iTunes, but it was somewhat outdated, so I will summarize my own procedure below. I am not going to explain the nuts and bolts of what each step does, since that’s covered in the linked article.

Current versions of iTunes no longer support app installs, so you need to downgrade to an older version. The linked article states that there’s yet another hurdle, in that as of iTunes 12.5, Apple is using certificate pinning, which nullifies the ability of Fiddler to snoop HTTPS traffic. I tried an older version of iTunes, but it was no longer able to communicate with the App Store (Apple just LOVES to put up hurdle after hurdle for us!). After much searching, I discovered that in December 2017, Apple quietly released iTunes 12.6.3 for enterprise users who still need the ability to do app installs. Because it uses certificate pinning, I had to devise a procedure to get around that.

Note for Mac users: You can probably follow the same basic procedure using Charles Proxy, but I don’t have the ability to walk you through that.

WARNING: THE PROCEDURE BELOW IS PROVIDED AS A RESULT OF MY OWN FINDINGS. THERE IS ABSOLUTELY NO WARRANTY, AND THERE IS A SMALL POSSIBILITY THAT YOUR DEVICE CAN BECOME BRICKED DURING A FIRMWARE UPDATE. MAKE SURE THAT YOUR DEVICE IS FULLY CHARGED BEFORE STARTING. IN FOLLOWING THE INSTRUCTIONS BELOW, YOU AGREE TO RELEASE ME FROM ALL LIABILITY, AND PROCEED AT YOUR OWN RISK.

How to download Fitness Utility 1.4.1 and use it to downgrade your Rhythm+ to firmware 2.62:

    1. Find your current iTunes folder, and rename it to iTunes.sav, or just move it to a new location. On Windows 10, it’s located at C:\Users\<yourusername>\Music\iTunes. (Don’t worry, after you’re done, you can reinstall the latest iTunes, and restore your old iTunes folder).
    2. Download and install iTunes 12.6.3
    3. Download and install Fiddler. DO NOT START FIDDLER YET
    4. Launch iTunes 12.6.3 and download any random app. iTunes will prompt you to log in with your Apple ID. This is the loophole we use to get around the certificate pinning. It turns out that iTunes 12.6.3 only checks the certificate during the login process, and doesn’t detect when we later swap in Fiddler‘s fake root certificate so that it can snoop HTTPS traffic.
    5. Before proceeding, it’s best to kill any programs on your computer that access the web, because they will pollute your Fiddler capture. If you have your web browser open in order to read this article, kill all of your other tabs that might be accessing the web in the background.
    6. Launch Fiddler.
    7. In Fiddler, go to the File menu and uncheck File->Capture Traffic
    8. From the Fiddler menu, go to Tools->Options->HTTPS. Check the Capture HTTPS CONNECTs and Decrypt HTTPS traffic checkboxes. A dialog box will pop up asking if you want to Trust the Fiddler Root certificate. Select Yes to it, and all of the ensuing dialog boxes. Don’t worry, after we’re done, we will remove the fake certificate, and restore your original.
    9. In Fiddler, go to the menu to check Rules->Automatic Breakpoints ->Before Requests
    10. Launch iTunes and search for Fitness Utility in the App Store
    11. In Fiddler, go to the File menu and check File->Capture Traffic
    12. In iTunes, click the button to download Fitness Utility
    13. A few requests with red icons on the left will appear in the Fiddler capture pane. Select
      HTTP Tunnel to upp.itunes.apple.com:443  and click the green Run to Completion button in the right pane. Next, select
      HTTP Tunnel to p14-buy.itunes.apple.com:443 in the left pane, and click the green Run to Completion button in the right pane
    14. A new request should appear in the Fiddler capture pane: HTTPS p14-buy.itunes.apple.com /WebObjects/MZBuy.woa/wa/buyProduct  Select it in the capture pane, and then in the right pane, click the TextView tab, look for

      <plist version=”1.0″>
      <dict>
      <key>appExtVrsId</key>
      <string>821322483</string>

      and replace 821322483 with 813634417.

    15. In Fiddler, go to the menu to check Rules->Automatic Breakpoints ->Disable
    16. Make sure the HTTPS p14-buy.itunes.apple.com /WebObjects/MZBuy.woa/wa/buyProduct request is selected in the Fiddler capture pane, and click the green Run to Completion button.
    17. After iTunes shows that Fitness Utility is downloaded, verify that you have the Fitness Utility 1.4.1.ipa file in C:\Users\<yourusername>\Music\iTunes\iTunes Media\Mobile Applications
    18. Connect your iOS device to your computer, and use iTunes 12.6.3 to install the Fitness Utility 1.4.1 to your iOS device, or use iFunBox instead as described below in Update 20170112
    19. Launch Fitness Utility 1.4.1 on your iOS device and turn on your Rhythm+. WARNING: MAKE SURE YOUR RHYTHM+ IS FULLY CHARGED BEFORE UPGRADING THE FIRMWARE. IF IT DIES DURING A FIRMWARE UPGRADE, IT MAY BE RENDERED UNUSABLE.
    20. Tap the Commands button at the top right of the screen, and then tap the Start button next to Firmware Update.
    21. After the update is completed, power cycle your Rhythm+
    22. You can check that the firmware version is now 2.62 by tapping the Attributes button at the top left of Fitness Utility.
    23. VERY IMPORTANT: Once you verify proper operation of Fitness Utility, on your computer, have Fiddler restore your original root certificate with Tools->Options->HTTPS->Actions->Reset All Certificates.
    24. Copy your Fitness Utility 1.4.1.ipa file somewhere so that you can reuse it in the future if you wish.
    25. Delete the new iTunes folder, restore your old iTunes folder by renaming iTunes.sav to iTunes, uninstall iTunes 12.6.3, and reinstall your original version of iTunes.

Now that you have your own copy of Fitness Utility 1.4.1.ipa, you are free to try any future firmware upgrades from Scosche, because it’s easy to go back to a working version if you don’t like the new one. If you use iFunBox, you don’t even have to mess with swapping out iTunes versions.

If you prefer to downgrade to firmware v2.4, you can use Fitness Utility 1.4.1 and follow the procedure below:

*** WARNING: DOWNGRADING TO FIRMWARE V2.4 DISABLES THE ABILITY TO UPDATE FIRMWARE VIA FITNESS UTILITY. IF YOU LATER CHANGE YOUR MIND, AND WANT TO INSTALL A DIFFERENT VERSION, YOU WILL HAVE TO SEND THE UNIT BACK TO SCOSCHE. ***

  1. download firmware 2.4 and unzip it.
  2. send the unzipped HEX file to an e-mail address accessible from your iOS device
  3. open the e-mail you sent on your iOS device, tap the attachment, and then scroll through the on screen icons until you find Copy to Fitness Utility, and tap the icon.
  4. Turn on your Rhythm+ and follow steps 19-22 above.

The above method actually works with any version of firmware HEX file that you are able to obtain.


Update 20180112: I tried installing Fitness Utility 1.4.1.ipa with iFunBox instead of iTunes, and it also works. Launch iFunBox with your phone connected to your computer, and install the app by clicking the Install App(*.ipa) from the main screen. Firmware 2.4: scosche-rhythmplus-2_4.zip

 

Downloads:
iTunes 12.6.3 (allows App installs): https://support.apple.com/en-us/HT208079

 

Previous article: HowTo: Upgrade Scosche Rhythm+ Firmware

Programming OpenEVSE with a Serial Cable instead of Hardware Programmer

Typically, OpenEVSE firmwares are flashed into the board using a hardware programmer, such as a USBasp. In the past, this was required, because the firmware had grown so large that there was no space left in the ATMega328P‘s flash to fit in a bootloader. However, the latest versions of the AVR tools that come with Arduino have shrunken down the binaries to the point that we now have space for a bootloader. Once the bootloader is installed, OpenEVSE can be programmed in exactly the same fashion as an Arduino Pro Mini, via a USB->TTL UART adapter, such as a FTDI cable, using the stk500 (arduino) protocol.

Before we can program the chip with a bootloader, we need to make a minor hardware mod. After a reset, the bootloader waits to see if a new firmware wants to be flashed before proceeding with booting the installed firmware. It is only during this very small time window that the ATMega328P‘s MCU is ready to accept a firmware. In order to trigger a reset via software, we need to connect the DTR pin of the FTDI cable to the RESET pin of the MCU via a .1uF capacitor.

Below is a photo of the mod, done on a Wattzilla C3 board, which is an OpenEVSE variant:

The DTR pin is on the far left of the 6-pin serial connector. The RESET pin can be accessed at either the left side of R10, as pictured above, or at Pin 5 of the ISP connector (red circle).

Once the hardware mod is in place, we must set the fuses to use a bootloader, and flash in the bootloader, using a hardware programmer. In this example, we will use OptiBoot, because it’s smaller and faster (115200 baud) than the standard Arduino bootloader.

avrdude -c USBasp -B0.5 -p m328p -Uflash:w:optiboot_atmega328.hex -Ulfuse:w:0xFF:m -Uhfuse:w:0xDE:m -Uefuse:w:0x05:m -Ulock:w:0x3F:m

After the bootloader is flashed in, we can thereafter flash in firmwares using just the FTDI cable:

avrdude -carduino -PCOM5 -b115200 -p m328p -Uflash:w:open_evse.hex

Substitute your FTDI cable’s virtual serial port for COM5 above.

For those who are not comfortable with command lines, it’s also possible to use the Arduino IDE to burn the bootloader, and flash in firmwares.

  1. Set your board to Arduino UNO by using the menu to navigate to Tools->Board->Arduino UNO
  2. Select your hardware programmer via Tools->Programmer
  3. Install the bootloader via Tools->Burn Bootloader
  4. Disconnect the hardware programmer, and use Tools->Port to select your FTDI cable’s virtual serial port.

Thereafter, you may flash in your sketches with the upload button. The above procedure will also work with any DIY or other Arduino clone which is not wired for a bootloader. Note that the bootloader takes up 512 bytes, so your maximum sketch size drops from 32768 to 32256 bytes.

 

 

Samsung Refrigerator Noisy Fan – Quick Fix

I have a Samsung RF28HMEDBSR french door refrigerator that’s only a few years old.

Several months ago, I started to notice a mild clicking sound coming from it occasionally. The sound would always stop as soon as I opened the door, and then usually restart a little while after closing the door. In the past few days, the noise got considerably louder. It became clear that the sound was coming from a fan that was inside the refrigerator compartment. It started sounding like a fan whose blades were hitting something. Then this morning, it became unbearably loud.. like there was an airplane inside my kitchen!

I thought maybe the fan bearings were just dry and needed oil. After doing a lot of research on the Internet, I figured out that the evaporator fan, which circulates cool air inside the refrigerator, was probably the culprit. It turns out that ice builds up on the evaporator (due to bad design of the defrost circuit), and eventually hits the fan blades, causing the racket.  The evaporator fan is a box fan that’s attached to the evaporator cover in the back of the fridge, behind where it says Twin Cooling:

The fan looks like this:

The proper fix is to remove everything from the refrigerator, take out all the drawers and shelves, remove the evaporator cover, and then melt the ice. I didn’t have time to do this today, and just wanted to silence the racket, so I decided to try a quick hack. The ice build up usually occurs on the coolant pipes feeding the evaporator. Notice how there are two large oblong air holes in the evaporator cover (see above photo), above Twin Cooling. The coolant pipes are approximately behind the air slot on the right.

I decided to try blowing hot air into the air slots, to melt some of the ice enough so that it wouldn’t hit the fan anymore. It’s important not to blow air that’s so hot that it melts the plastic cover. I set my dryer to high, and then pointed it at my hand, adjusting the distance so that the air was just a little too hot for me to tolerate. Then I aimed it at the intake slots, at about the same distance, and alternated blowing air into them, 10 seconds at a time, for 2 minutes:

Voila! The noise is completely gone! When I have more time, I will do the proper fix, taking the evaporator cover off, and melt the ice that’s covering the evaporator. Most likely, there’s a lot of ice back there, which blocks air flow to the evaporator, reducing the efficiency of the refrigerator, which wastes electricity, and in the worst case, keeps it from cooling properly. I will make a post in the future, documenting the process as I go.

In the meantime, if you want to tackle the proper fix yourself, here are some YouTube videos which are helpful:

At about 4:35 in the video above, the guy has a good hack for preventing the issue from ever happening again. He moves the temperature sensor for defrosting from the inlet to the outlet pipe of the evaporator, which extends the defrost cycle.

UPDATE 2020-05-20: It’s been almost 3 years since I applied the temperature sensor moving hack described above, and I haven’t had a recurrence of the noisy fan, so it works well as a permanent fix!

The video below gives a lot more details on disassembly procedures:

Service ManualRF28HMEDBSR Service Manual

How to Run a Server from VMware Client

I’m running some server software in a virtual machine running Debian 8 which is running under VMware on a Windows 8.1 host. While it’s easy to access the server through VMware’s virtual NAT from the host computer, it isn’t at all clear how to access it from outside the Windows host. There are two ways to accomplish this feat:

  1. configure VMware to set the Network type from NAT to Bridged (easy)
  2. keep the NAT and forward the VM’s port to the host, and then open a port in the host’s firewall (hard)

So which method is better? (1) is easier, because when you configure your VM’s network to bridged, the VM will get its own IP address on your LAN, and will be fully visible on your LAN, just like your real computers. (2) is more secure, because you only expose the ports that you need to the LAN, so you don’t have to configure the firewall in the VM’s client OS.

For our example, let’s walk through how to remotely access an apache server running in our VMware VM, listening at port 8080. First, let’s find the IP address of our VMware VM. Since my VM is running Debian, we simply run ifconfig:

% sudo ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:96:81:fa
inet addr:192.168.88.144 Bcast:192.168.88.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe96:81fa/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:61515 errors:0 dropped:0 overruns:0 frame:0
TX packets:18860 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:49210391 (46.9 MiB) TX bytes:1321143 (1.2 MiB)
Interrupt:19 Base address:0x2024

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:61 errors:0 dropped:0 overruns:0 frame:0
TX packets:61 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:20606 (20.1 KiB) TX bytes:20606 (20.1 KiB)

From the output of ifconfig, we can see that our VM’s IP address is 192.168.88.144 on VMware’s virtual NAT. My Windows host, we can get our IP numbers from ipconfig:

C:\Program Files (x86)\Microsoft Visual Studio 8\VC>ipconfig

Windows IP Configuration
Wireless LAN adapter Wi-Fi:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::4c64:efa3:132a:68c0%22
IPv4 Address. . . . . . . . . . . : 192.168.1.115
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1

Ethernet adapter VMware Network Adapter VMnet8:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::e01a:da83:d339:b55e%20
IPv4 Address. . . . . . . . . . . : 192.168.88.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :

The output of ipconfig shows that on my LAN, my Windows host has IP number 192.168.1.115, and on VMware’s NAT, its IP number is 192.168.88.1. To test access to our apache server from within the Windows host, we an simply open a web browser, and point it to http://192.168.88.144:8080. Next, let’s configure things so that we can access the server from any host on our LAN.

 

1. Network Bridging (Easy Way)

To switch our VM from NAT to Bridge mode, simply go to VMware’s main menu and select VM -> Settings... A Virtual Machine Settings dialog will pop up. In the left side of the dialog, select Network Adapter, and then on the right side of the dialog, under Network connection, change the setting from NAT to Bridged:

After you reboot your VM, it will obtain an IP number from your LAN. My VM came up with IP number 192.168.1.111, so apache is accessed via http://192.168.1.111:8080.

 

2. Port Forwarding (hard way)

Now, let’s see how to do it while keeping the NAT. In the Virtual Machine Settings above, make sure NAT is selected. If you change the setting, make sure to reboot your VM afterwards. The first thing we need to do is forward the port from our VM to the host. From VMware’s menu, select Edit -> Virtual Network Editor…

(Note, VMware Player, unlike VMware Workstation, doesn’t come with vmnetcfg.exe, the Virtual Network Editor. You can follow instructions here to access it: DOWNLOAD VMNETCFG.EXE & VMNETCFGLIB.DLL FOR VMWARE PLAYER). In the Virtual Network Editor, click the Change Settings button near the right bottom of the main dialog. In the next dialog, select the NAT from the listbox, and then click the NAT Settings… button:

Next, in the Nat Settings dialog, click the Add… button, and fill in the info for your server’s port:

Host port: the port number you want to use to access the server … can be different from the actual port used in the VM if you like
Type: select TCP or UDP
Virtual machine IP address: the VM’s IP on the NAT
Virtual Machine port: the port number used by the server inside the VM
Description: arbitrary info

Finally, click the OK button to save your port mapping. At this point, the port forward is functional, but most likely, your have a firewall running on your host computer. You must open up a hole in your firewall for the Host port you selected above.

In a Windows 8.1 host, if you’re using the built-in Windows Firewall, run WF.msc. Select Inbound rules -> New Rule…. Under What type of rule would you like to create?, select Port – rule that controls connections for a TCP or UDP port. From the New Inbound Rule Wizard, select your protocol and port(s):

In the next dialog, select Allow the connection. Finally, you can decide where you want to rule to apply, Domain/Private/Public. Unless you’re planning to use the server while travelling, it is best to leave Public unchecked. Finally, you’ll be presented with a page to enter a name and description for the mapping. After you click the Finish button, you should be able to access your server from any host on your LAN. In our example, a web browser should work when pointed to http://192.168.115:8080.

 

Precision PWM Frequency for Arduino / ATmega 328P

I’m working on an application where I need fine adjustment of PWM frequency. The existing PWM code that I found, such as the Arduino PWM Frequency Library, only allows integral frequencies to be selected. On pins supported by 16-bit timers, the Arduino PWM Frequency Library allows fine adjustment of duty cycle, but not frequency. After searching for a while, I found an interesting article in Udo Klein’s Blinkenlight blog: Flexible Sweep. In the article, Klein has an Arduino sketch which sweeps the LEDs of a Blinkenlight board from 0-999.9999 Hz in increments of .0001 Hz.

I hacked his sketch into PrecisionPWM, which outputs PWM to any arbitrary digital pin in increments of .0001 Hz. What’s nice is that since it doesn’t use the ATmega’s internal PWM generator, you can use it on any arbitrary digital pin, whether or not it supports hardware PWM.

Download from github: PrecisionPWM

How to Dramatically Speed Up AVRDUDE with USBasp or USBtinyISP Programmers

AVRDUDE has a little-known command line parameter, -B, which sets the bitclock, and can dramatically speed up writing/reading firmware to/from an AVR MCU when using a USBasp or USBtinyISP. For a USBasp, simply add -B0.5 to your command line parameters. Example:

avrdude -cusbasp -B0.5 -pm3280 -U flash:w:firmware.hex

In my tests, adding -B0.5 reduces the time to write & verify a hex file by about 2/3! For the USBtinyISP, add -B1 to your command line parameters. Example:

avrdude -cusbtiny -B1 -pm3280 -U flash:w:firmware.hex

The speedup is even more dramatic with the USBtinyISP. In a specific test, I found that write/verify time dropped from 59 sec to 17 sec!

You can also speed up programming from the Arduino GUI. Simply edit your programmers.txt file. In older versions of Arduino, it can be found in <ArduinoFolder>/hardware/arduino/avr/boards.txt. For Arduino 1.8.x, it’s located in C:\Users\<YourUserName>\AppData\Local\Arduino15\packages\arduino\hardware\avr\<version>\programmers.txt.

For the USBasp, add the -B0.5 parameter to the usbasp.program.extra_params line:

usbasp.program.extra_params=-Pusb -B0.5

In order to realize the speed gain in programming, the USBasp must have firmware which supports the setting of SCK. If AVRDUDE gives you this warning:

avrdude: warning: cannot set sck period. please check for usbasp firmware update.

then you must update your USBasp’s firmware. Follow the instructions in my article:
How to Update the Firmware on a USBasp V2.0

For the USBtinyISP, add the -B1 parameter to the usbtinyisp.program.extra_params line:

usbtinyisp.program.extra_params=-B1

If the Arduino GUI is already running, you must restart it in order to load the new settings.

WS2812B LED (NeoPixel) Control: Part 2 – WiFi Control via Art-Net on ESP8266

INTRODUCTION

For wireless control of WS2812B (NeoPixel) LEDs, I initially played with Bluetooth SPP (Serial Port Profile), due to the simplicity of setting up the host software… from the host’s software’s point of view, the connection just looks like a physical serial port. Unfortunately, the flakiness of my Windows 8.1 PCs’ Bluetooth SPP support caused me to abandon that solution.

WIFI CONTROLLER HARDWARE

ESP8266 modules provide a very low cost method of interfacing WS2812Bs to WiFi. Adafruit’s Huzzah module costs $9.95, but on eBay, NodeMCU clones, such as the LoLin NodeMCU board can be had for ~$3 shipped from China. This makes it even cheaper than the Arduino/Bluetooth combination!

What’s more, the LoLin board has a CH340G onboard, so it doesn’t require a FTDI cable to connect it to your host computer for programming. I ordered a few of the LoLin boards, but in the meantime, I started playing with the Adafruit Huzzah boards I had on hand.

With the addition of ESP8266 support via the Board Manager, Arduino becomes an easy to use platform for code development. Also, there are easily obtainable libraries for both WiFi configuration and control of the WS2812Bs.

One extra complexity of using an ESP8266 to control WS2812Bs is that the ESP8266 is a 3.3V device, while the WS2812B is a 5V device, (usually) necessitating level shifting. The WS2812B datasheet shows a threshold of >= 0.7VDD for logic HIGH, and <= 0.3VDD for logic LOW. The allowed VDD ranges from +3.5-5.3V. Interestingly, some WS2812Bs can actually work when powered by 3.3V, and driven by 3.3V logic, even though it’s out of spec, but many cannot. On the other hand, it’s totally within spec to be powered by 3.7V and driven by 3.3V logic. So, if you use a 3.7V LiPo battery to power the WS2812B strand, the WS2812B data line can be connected directly to the ESP8266 without any level shifting! If you choose to go this route, power the Huzzah from its VBat terminal, so that the 3.7V will be regulated down to 3.3V to power the ESP8266. More details are available in Adafruit’s NeoPixel Uber Guide.

Since I want to be able to drive long strands of LEDs, I elected to go the 5V power with level shifter route. Also, I have lots of 5V power supplies laying around. There are many different ways to do level shifting, either passive or active. The WS2812B has tight timing requirements, and runs at 800KHz, so care has to be taken in order to avoid signal distortion. One of the most reliable methods is to use a 74AHCT125 level shifter IC. I decided to first try a simple diode and pullup resistor circuit (credit: RPi GPIO Interface Circuits):

The circuit is currently working flawlessly for me, driving my 5m long strand of 150 LEDs.

WIFI COMMUNICATION PROTOCOL

In order to send data to our WS2812Bs over WiFi, we need some sort of IP protocol. Art-Net is a royalty-free protocol, which sends DMX data embedded in UDP packets. I decided to go with Art-Net because it is an industry standard that is supported by a variety of Pro software, and Jinx! and Glediator can talk to it.

ARDUINO FIRMWARE

I will not go into how to set up Arduino to compile sketches for the ESP8266, as that is discussed elsewhere. To compile for the Huzzah, select it as the compile target from the Tools pulldown menu:

Tools -> Board -> Adafruit HUZZAH ESP8266

I created a sketch, which is a mashup of a few different projects from github. The code is in my github repo: WS2812ArtNet. I stripped the Adafruit NeoPixel library down to the bare metal, and added a captive portal for configuring the WiFi connection. Also, it supports a hardware pin to erase the WiFi settings. Configuration is done via a few defines in WS2812ArtNet.ino. See the #defines for PIXEL_CNT, PIN_DATA, PIN_LED, and PIN_FACTORY_RESET. At a minimum, PIXEL_CNT must be set to the number of LEDs in your strand.

PIN_DATA is used to select the pin that’s used to drive the data to the LED strand.

PIN_LED is used to select the a pin which blinks an LED every time an Art-Net packet is received. This makes it easy to tell if the board is receiving data. In addition, the LED is initially off at boot-up, and turns solid red when the ESP8266 connects successfully to a WiFi AP. By default, PIN_LED = 0, which makes it control the onboard red LED on the Huzzah.

PIN_FACTORY_RESET wipes out any saved settings and clears the EEPROM when it’s grounded for 2 sec.

To load the WS2812ArtNet sketch into the ESP8266, first press the GPIO0 and Reset buttons simultaneously, and then let go of the Reset button. The red LED will then glow dimly, indicating that the bootloader is active. Once the sketch is loaded, when the ESP8266 initially boots up, it will create a WiFi AP with SSID WS2812ArtNet_hh-h. Use a computer, phone, etc to connect to the AP. Upon connection, it should automatically present a captive portal for configuration:

If the captive portal doesn’t automatically launch, open a web browser, and point it to http://192.168.4.1. Tap on Configure WiFi, and the ESP8266 will automatically scan for available APs:

Tap the desired AP’s SSID, and type in the passphrase. Additionally, you can also choose a starting Art-Net universe, and configure a static IP. After you tap save, the ESP8266 will reboot. If it connects successfully to your AP, the onboard red LED will light. Then, the LED strand will go into the startup test sequence of lighting up red, green, and blue, and then turning off. Once Art-Net data is received, the LED still start blinking with every packet it receives.  If you have trouble during setup, you can see debug messages by opening the ESP8266’s serial port in a terminal set to 115200,N,8,1.

 

When configuring Jinx!/Glediator, select GRB as the pixel data format.

 

Prev: WS2812B LED (NeoPixel) Control: Part 1 – Serial Control via 8-bit ATmega (Arduino)

WS2812B LED (NeoPixel) Control: Part 1 – Serial Control via 8-bit ATmega (Arduino)

INTRODUCTION

I’ve been laying the groundwork for doing some projects using remote controlled RGB LEDs. My first attempt was Lampduino, which used discrete RGB LEDs, and an ITEAD Colorduino as a controller. In that project, I ran into several pitfalls:

  • though inexpensive, assembly of the LED matrix was very labor intensive
  • the LED’s were rather dim, due to the limited drive capability of the Colorduino
  • the frame rate was slow, due to limited baud rate and RAM
  • while it was scalable, I didn’t like the idea of having to use a separate Colorduino for every 64 LEDs

A few years have passed, and WS2812B LEDs have dropped enough in price enough to get into the range that I feel is affordable. They can be found on eBay and AliExpress very cheaply. Also, they can be controlled without any specialized hardware – all that is needed is one GPIO pin. There are libraries available for many of the popular microcontrollers. Some examples are Arduino, ESP8266, Teensy 3.x, and Raspberry Pi.

HOST SOFTWARE

The other piece of the puzzle is control software. For Lampduino, I hacked uRaNGaTaNG’s mtXcontrol Processing sketch into rgbMtx, but I found Processing to be a very limiting platform, which was hard to debug. This time around, I found a couple of interesting free LED control programs, which are both quite powerful. The first one is Jinx! LED Matrix Control, which runs on Windows only, and the second is Glediator, which is a Java app. Both programs, while free, are not open source. However, they are both powerful enough to do some interesting things.

HARDWARE

I decided to start my experiments with an Arduino Pro Mini clone, because they have a tiny footprint, are cheap (clones are <$2 shipped from China on eBay), and I happened to have some laying around. Also, the Arduino Pro Mini’s ATmega 328P MCU runs at 5V, so no level shifting is required when interfacing to WS2812Bs. Glediator’s creator, Solderlab, has barebones, fast serial client Arduino sketch which can be downloaded at: WS2812-Glediator-Interface. It can run on any 8-bit ATmega-based Arduino such as the Mega, UNO, Deumilanove, etc. The code that outputs the data to the LEDs is written in assembly language, and is thus, very fast & compact. Also, rather than using Arduino’s Serial library, it contains its own very compact serial code. At the expense of a little bit of speed, I decided to generalize it a bit, and add my own packet protocol. My code is on github at: WS2812Remote. The main changes that I made in my version of the code are:

  • Since I didn’t understand the Glediator example’s serial code, I reverted to using Arduino’s built-in Serial library. I’ve tested it with baud rates up to 1000000 and an FTDI cable on a Windows PC, and it works fine
  • I added support for my own packet protocol. Glediator’s serial protocol is extremely simple. Each frame starts with 0x01, followed by the pixel data stream. My simple packet protocol adds an XOR check byte, as well as a few simple commands such as color fill and blanking of the LEDs.

I also wrote a C++ program, called pkt_test, which demonstrates usage of my packet protocol.

Hookup of the WS2812B LED strand to the Arduino is quite simple. You can use any 8-bit Arduino. First, you must select a data pin to drive the strand. I arbitrarily decided to use pin PD2. For speed and compactness, instead of using Arduino functions to access the data pin, the code refers to the ATmega port and pin numbers, rather than Arduino’s rather arbitrary digital pin numbers. On the Arduino Pro Mini, digital pin 2 = PD2, as can be seen from the following pin mapping diagram:

FIRMWARE CONFIGURATION

So WS2812Remote.h is configured as follows:

#define DATA_PORT PORTD
#define DATA_DDR DDRD
#define DATA_PIN 2

Next, PIXEL_CNT needs to be set to the number of LEDs in your strand. I tested with an Adafruit NeoPixel ring containing 16 LEDs:

#define PIXEL_CNT   16

Connect your the data input pin of the first LED of your WS2812B strand to your selected data pin. Adafruit recommends a 300-500 ohm inline resistor to protect from voltage spikes. The NeoPixel ring I used already has a resistor onboard, so I didn’t need it. I connected the +5V and GND pins directly to the corresponding pins on the Arduino. To protect against current inrush when powering it up, Adafruit also recommends connecting a 100uf capacitor between the +5V and GND pins. However, it’s not necessary if you’re just going to power it from USB, which is what I did, since I was only powering 16 LEDs. For large strands, you will need an external power supply to supply sufficient current, as each LED can draw up to 60mA at full brightness. If using an external power supply, make sure to always apply power to the WS2812B strand before the data pin!

HOST SOFTWARE CONFIGURATION

I used the same FTDI cable that I used for programming the Arduino as a virtual com port for sending data to it. When configuring Jinx! or Glediator, select Glediator protocol. For speed, the sketch just receives raw pixel data, and dumps it out to the LED strand, so the data format is in native GRB order.

When configuring Jinx! or Glediator, select Glediator as the device type (Jinx!) or output mode (Glediator). Make sure that the baud rate of the corresponding com port matches BAUD_RATE as defined in your sketch. I tested 115200 and 1000000 bps with my FTDI cable, and both worked fine with both programs. It failed at 1250000 bps.

If you want to play around with my packet protocol, the pkt_test code is self explanatory. I tested it with Visual Studio 2015 in Windows 8.1, and g++ in Debian linux 8.2.0. Prior to compilation, set COMM_PORT to correspond to your Arduino’s serial port. Also, confirm that BAUD_RATE in ../WS2812Remote.h matches the value that was used when loading the Arduino sketch. To compile and run pkt_test in linux, use:

g++ pkt_test.cpp serialib.cpp -o pkt_test
sudo ./pkt_test

WIRELESS CONTROL

My first inclination for wireless control was to use Bluetooth, due to its simplicity. The Bluetooth SPP (Serial Port Profile) makes it easy to construct a wireless virtual serial interface between a host computer and the Arduino. This allows you to use exactly the same host software configuration that you would for a direct serial connection to the host. I had an Elechouse EHB Serial Bluetooth Module in my parts bin (very similar to the ubiquitous HC-05), so I decided to try it out.

Before using the EHB module can be used, it must be configured with a series of simple AT commands. I hooked it up to my Windows PC with my FTDI cable, and used PuTTY as a serial terminal to configure it. Connecting the EHB module to the Arduino is quite straightforward:

Arduino -> EHB

5v -> VCC
GND -> GND
RXD -> TXD
TXD -> RXD

Pairing the EHB to a host computer creates a virtual serial port for the host software to access. Unfortunately, I was using Windows 8.1 as my host computer, and its handling of Bluetooth SPP clients is rather flaky. Every time I powered down the LED controller, I had to unpair/pair the Bluetooth in order to get the virtual serial port to work properly. While it worked flawlessly when the virtual serial port was functional, ultimately, I abandoned Bluetooth due to the flakiness of Windows’ Bluetooth SPP support. Perhaps Linux can handle it better.

Next: WS2812B LED (NeoPixel) Control: Part 2 – WiFi Control via ARTnet on ESP8266

HowTo: Fix AVRDUDE 6.3/Arduino 1.6.10+ Compatibility Issues with USBasp Clones

I recently upgraded to Arduino 1.6.13, and found that I could no longer program my boards with my Chinese USBasp clone programmer. When the Arduino IDE tried to load the firmware with my USBasp, AVRDUDE couldn’t find my USBasp, and gave this error:

avrdude: error: could not find USB device with vid=0x16c0 pid=0x5dc vendor=’www.fischl.de’ product=’USBasp’

It turns out that the that AVRDUDE 6.3, which is bundled with Arduino 1.6.10+, has timing issues with USBasps. The fix is to replace your libUSB-win32 driver with libusbK v3.0.7.0. An easy way to install libusbK v3.0.7.0 is to use zadig. Download the zadig from

http://zadig.akeo.ie/

Plug your USBasp into your PC.

Launch zadig, and from the menubar, select Options->List All Devices

Next, from the top listbox, select USBasp.

From the Driver selector box, click the up or down arrow key until libusbK (v3.0.7.0) appears.

Finally, click the Replace Driver button.

The screen should look like this:

zadig

You do not have to reboot or disconnect/reconnect your USBasp. After Zadig finishes installing libusbK, AVRDUDE 6.3 will start working correctly with your USBasp.

NOTE: the version of AVRDUDE that Arduino 1.6.x uses is actually controlled by the Boards Manager (Tools->Board->Boards Manager). Even if you have a version of Arduino 1.6.x prior to 1.6.10, if your Arduino AVR Boards by Arduino is version 1.6.10+, it will use AVRDUDE 6.3.

HowTo: Clean Hydration Bladder Hose/Tubing

If you use a hydration pack, sooner or later, your hose is going to get gunked up with disgusting biofilms or other residues. Biofilms tend to be resistant to disinfectants such as bleach and hydrogen peroxide, so how can you clean the junk out of your hose? I didn’t feel like spending the $$ for a Camelbak cleaning kit, so I found a simple and cheap solution. Simply use a pair of shoelaces.

The shoelaces have to be longer than the length of your hydration hose/tubing. Make sure to use round laces, rather than flat laces. The diameter of the laces has to be smaller than the inside diameter of your hose, in order for them to easily pass through. I happened to have a pair of dress shoe laces I got from a $.99 store.

Small diameter paracord will work, as well, but it doesn’t have the nicely finished ends, which are easier to thread. If you use paracord, wrap the end with a bit of tape to simulate the plastic end of a shoelace, and it will pass through your hose more easily.

First, soak your hose until the gunk inside it softens up. Next, get out the excess water by holding the hose on one end, and cracking it like a whip. Tie the shoelaces together with a knot that’s small enough to pass through the hose, but big enough to be a tight fit to scrub the walls of the tube clean:

img_8719

In the photo above, the knot has white slime on it, because I’ve already used it to scrub out my hose. I just used a basic overhand knot. Next, thread one end of a shoelace through the tube:

img_8718

You may need to remove the attachments from the ends of your hose, in order to get access (especially on the bite valve end). Often, the attachments are very difficult to separate from the hose. Simply dip end of the hose and attachment into hot water to soften up the hose. When the hose is sufficiently softened, you should be able to easily pull off the attachment.

It’s easiest to thread the shoelace through the hose if you clamp the hose between your legs, straighten the hose vertically, and let gravity help you push the shoelace through the top. Finally, just alternately pull ends of the shoelaces to work the knot back and forth through the tube, wiping the junk out of the hose. Wash the gunk off the knot and repeat the process until the hose is clean. Wash the shoelaces, and then soak the hose and shoelaces in some water with a bit of bleach, in order to kill the bacteria and mold.

If you find it hard to get the knot to fit through the hose, try a square knot, which is a bit smaller: http://www.netknots.com/rope_knots/square-knot

You can also get away with using just 1 shoelace. Just tie an overhand knot at one end. However, you will have to re-thread the shoelace through the hose after each pull.

I find that hanging the hose to air dry doesn’t work very well, even if I leave it for a few days. The quickest way to dry it is to first crack it like a whip to expel as much water as possible, and then use forced air to dry out the remaining moisture. I have sleep apnea, so I use my CPAP to blow air through the hose:

img_8720

If you have a fish pump, you can attach the air hose to the hydration tube, and use that to blow air through until it’s completely dry.