How To Test Your Hardware And Software When Your imp Is Not Online
Battery operated devices commonly disable WiFi to save power. Mains-powered devices may be configured to continue operating even when WiFi connectivity has been lost due to circumstances beyond the device’s control. However, with no network connectivity, logging is a challenge.
In order to add visibility to the state of your product during power saving modes or periods of unexpected connectivity loss, you can employ one of the many digital communication protocols available on an imp. One of particular value is UART. This standard bus is a great choice for its ease of use and availability on each imp.
By using a UART for offline debugging you can send the same messages you would via server.log() to a serial port with just a few simple hardware modifications. We’ll describe below how you can take advantage of this technique.
You’ll need a few tools in order to use UART for debugging. These tools comprise both software and hardware but are either low cost or free. In addition to these tools, you will have to modify your device under test (DUT) hardware and software to output debug messages.
We recommend using a TTL UART-to-USB (COM port emulator) cable to view debug messages on your workstation. In order to connect this cable to your DUT you will have to solder two wires (imp TX and GND) directly to pins (or test points) on the DUT. In addition, you will need terminal software and to modify the DUT code to output debug messages over serial. We have collected the information you need to source components and software, and we have written a class you can add to the DUT code to output debug messages easily.
A USB-to-serial adaptor useful for testing UART links
We recommend FTDI cables because they are highly available and relatively inexpensive. They are available with either a female 0.1-inch socket or bare wire termination, so select on one the basis of your application. They are also available in 3.3V and 5V signal levels, but it is important that you always use the 3.3V version to avoid damaging the imp’s IO pins.
There are many options available depending on your OS. Linux and macOS both come with Terminal utilities; these can be used run a command-line utility called screen which lets you send and receive information via UART. Windows users should download Simon Tatham’s PuTTY, which combines the role of Terminal and screen.
You will need to install the FTDI drivers for your OS. Note that macOS 10.9 and above come with FTDI drivers built in.
In order to send data out over the UART you will need an available UART TX pin. This pin can share functionality with other devices on your board but you will have to evaluate if the sending TX data to the other device will cause damage to it or the system. The imp001 has three UART TX pins available, the imp002 has four, the imp003 and imp004m have five, and the imp005 has three. The table below shows the various imps’ TX pin options.
The imp005 has three dedicated UART buses which are not accessed via GPIO pins but directly.
Once you have found a viable TX pin, you need to connect it the RX pin (yellow) on the FTDI cable or header. The only other connection required is a link between the GND of the imp to the FTDI GND pin:
Be sure to set the serial terminal connection to use the FTDI cable and match the following settings:
For guidance on setting up the serial software, please see the Design Guide ‘UART Explained’.
Squirrel code for a class that you can use to log to an available UART TX pin is listed below. Add the listing to your device code. Use its log(message) function wherever you want a log message sent to both the UART and to server.log(). Also included is a simple listing to show the logger class in use.