User Tools

Site Tools


digispark:tutorials:debugging

This is an old revision of the document!


Debugging with the Digispark

The DigiSpark is small and inexpensive. To keep it that way it has limited features. One feature that Arduino programmers may miss is the serial monitor window. On the Arduino this is used to send and receive information from the Arduino.

Although the DigiSpark does not support the serial monitor window there are several options available with similar features.

DigiKeyboard

  • The simplest is the DigiKeyboard. You can use this where you would use serial.print with an Arduino. To use this you will need to add the keyboard library. Here are the steps to try out the example:
  1. Start Arduino
  2. open DigiSparkKeyboard, under File > Examples > DigiSparkKeyboard→Keyboard
  3. On windows: Open Notepad, under All Programs > Accessories > Notepad On Mac/Linux open your favorite text editor.
  4. Drag the Notepad/text Editor window to the side
  5. Select Upload
  6. When it asks you to plug in the DigiSpark
  7. Quickly move the cursor into the open Notepad window and click
  8. In a few second “Hello Digispark!” should start appearing in the Notepad/Text Editor - it is acting as a keyboard and so will type in any application that has the focus.

Also see the DigiKeyboard Wiki Page

DigiUSB

  • As far as DigiUSB tools packaged with the software the DigiUSB library in conjunction with the digiusbprogram in the DigiUSB Programs folder is the simplest option for full two way communication and debugging.
  • See the Examples→DigisparkUSB→Echo example for how to print a messages back to the computer.
  • Open digiusb.exe once you're device is plugged in - it then should display similar to the Arduino serial monitor, showing messages as they come in and allowing you to send data to the device (if you've set your sketch up to receive it).
  • If you get a message about missing pdcurses.dll download this and place it in the same directory as DigiUSB

See the DigiUSB page for more info.

DigiUSB RubyGem

There is also a RubyGem for communication using the DigiUSB Library

The rubygem is a package install-able using the rubygem package manager. You can download the files from github but you also need to use gem tools to compile it in to a gem and install it.

To install the rubygem, make sure you have libusb 1.x and ruby 1.9.x or ruby 2.0 installed (mac's and many versions of linux come with 1.8 installed, which is no good for this), then open a terminal and run 'gem install digiusb'. You might need to sudo that depending on your platform. Finally, you aught to be able to just type 'digiterm' in your terminal window and it will find the most recently attached digispark, connect to it, and start outputting everything printed via DigiUSB on the device and forwarding keystrokes from the terminal window in to the digispark.

Because of all this complex inter-dependency it might not be a good option for beginners.

LCD and LED

The onboard LED and the I2C LCD can also be good debugging options.

LCD Shield Kit Tutorial

Bi-directional Serial Debugging with a single I/O

If you didn't plan to use DigiUSB in your final sketch, the following proposed alternative consumes less pin than USB and less program memory.
Since the last version of <SoftSerial> library (may 2013), <SoftSerial> is an alternative for debugging Digispark just using a single I/O.
By declaring a <SoftSerial> object with the same pin for Tx and Rx: it's possible to use a half duplex (request/response) software serial port using a single I/O. The external interface is composed of 2 resistors and a regular diode (See below).
Please, note this solution requires a native RS232 port (rare today) or a RS232/USB adapter on the development PC.

How to use this debugging capabilities?

In your sketch, declare a <SoftSerial> object with the same pin for Tx and Rx as depicted below:

Simple example of sketch

#include <TinyPinChange.h>
#include <SoftSerial.h>
 
#define DEBUG_TX_RX_PIN         2 //Adjust here your Tx/Rx debug pin
 
SoftSerial MyDbgSerial(DEBUG_TX_RX_PIN, DEBUG_TX_RX_PIN, true); //true allows to connect to a regular RS232 without RS232 line driver
 
void setup()
{
  MyDbgSerial.begin(38400); //After MyDbgSerial.begin(), the serial port is in rxMode by default
  MyDbgSerial.txMode(); //Before sending a message, switch to txMode
  MyDbgSerial.println(F("\nDebug enabled"));
  MyDbgSerial.rxMode(); //switch to rxMode to be ready to receive some commands
}
 
void loop()
{
  if(MyDbgSerial.available())
  {
    MyDbgSerial.txMode();
    MyDbgSerial.print(F("\nReceived: "));MyDbgSerial.write(MyDbgSerial.read());MyDbgSerial.print(F("\n"));
    MyDbgSerial.rxMode();
  }
}

Hardware wiring

                        SERIAL SINGLE I/O
                         DEBUGGING CABLE
            ___________________/\__________________
           /                                       \
                                              ____
 .--------.                                  |    \
 |    GND |--------------------------------+---o5  \
 |        |                           47K  | |   9o |
 |        |                        .--###--' | o4   |
 |  DEBUG |                  4.7K  |         |   8o |
 |  TX_RX |-------------------###--+--|<|------o3   |    ---> To regular RS232 SubD 9 pins Male of PC
 |   PIN  |        ^               | 1N4148  |   7o |         or to RS232/USB adapter
 |        |        |               '-----------o2   |
 '--------'        |                         |   6o |
  ATtiny85       Single                      | o1  /
 (Digispark)      I/O                        |____/
                                          SubD 9 pins
                                            Female

Connection between the Digispark and the PC

Plug the “Serial Single I/O Debugging Cable ” to a native RS232 port or to a RS232/USB adapter on your development PC.

Built-in IDE Serial Monitor or external Terminal?

With this approach, the regular serial monitor of the arduino IDE can be used. In the IDE, just select the RS232 port through the Tools→Serial Port menu. Then, adjust data rate and line terminator (if any), you can use the serial console as usual. In this case, you do not need any external Terminal.
If you prefer using an external Terminal, on the PC, open your favorite Terminal application at 38400,n,8,1: HyperTerminal, Teraterm (Windows) or Minicom, GtkTerm (Linux) and CoolTerm (MAC) does the trick.

Note:

  • Trick to be less intrusive: use a “high” data rate (38400 is fine) → less time wasted in ISR and for transmitting each character.
  • You can still upload your sketch modifications through the USB interface whilst the additionnal serial port is selected as Serial port in the IDE.

“Vintage” serial interfaces are not dead! :-)

Download here the related libraries

digispark/tutorials/debugging.1367766285.txt.gz · Last modified: 2013/05/05 08:04 by RC Navy