Project tutorial
Arduino Nano 33 IoT Debugging

Arduino Nano 33 IoT Debugging © LGPL

Get your Nano 33 IoT board connected to full GDB debugging so you can solve those bugs and get your project released!

  • 3,736 views
  • 3 comments
  • 12 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)
4966285
Solder Wire, Lead Free
66y6421 40
Solder Flux, Soldering
(may be in your solder already)

Apps and online services

About this project

There is nothing more frustrating than a project nearly working as intended, and there is only so much you can print to serial to understand your code.

This is where debugging tools come in to allow you to stop the code executing at specific points, and allow you to inspect the variables, and move through the code line by line if desired.

We can use the GDB debugging system and an external hardware debugger with the Arduino Nano 33 IoT board thanks to its breakouts with a little soldering.

With the Arduino IDE + Visual Micro + Visual Studio software set we have the full IDE experience along with these debugging tools out of the box.

The Soldering

Before we can connect our Nano 33 IoT board to our external debugger, we need to connect some female jumper wires onto the pads on the back of the board as below.

An External Hardware Debugger

There are a variety of external hardware debugging devices available, and in this example we will be using the Segger J-Link debugger (EDU available for Educational use at a lower cost).

Other debuggers such as the Black Magic Probe are also available, and connect in the same way as shown here, and it is available in Visual Micro already. You can also make your own Probe as shown in our Nano 33 BLE article.

The connections between the two devices are shown below.

Driver Setup

Some debuggers need an additional USB Driver installing on Windows to allow the debugging work correctly.

In our J-Link example you will need the Zadig tool, and to install the driver so they match in the tool.

Open the Zadig tool after downloading

Select Options > List All Devices

Now drop down the device list and select your device (JLink in this case).

If two devices are present select the "Interface 0" of the device

If the driver versions do not match, click Install Driver

There is a handy list of debugger / additional driver information on this page.

Debugging Setup

Once you are setup with the Arduino IDE + Visual Studio + Visual Micro, you can start debugging straight away.

Simply open your project and select the correct board and COM port.

Now you can set the debugger to "Hardware" which will expose a new list of pre-configured debuggers.

Select the one you are using, and ensure the vMicro > Debugger > Optimisation is set to "No Project + Libraries".

Add a breakpoint in where you want to stop initially, these can be moved once you have started the debugger, and there is often a limit of 6 concurrent breakpoints.

Now simply build and upload your code, and attach the debugger. You can also do this in one step by simply pressing Debug > Start Debugging.

A video of this Debugging Setup section is below:

Debugging process on the Nano33 IoT

Solve Those Problems

You should now be stopped on your break point, and a number of other windows are available on the Debug > Windows menu, if you do not see all of the watches / autos, etc.. windows that you wish to use.

Using the stepping and inspection tools, you can now move through the code to find the issues.

Getting started with the Arduino NANO 33 IoT

Segger J-Link Debug Probes

Segger EDU Debug Probes

Black Magic Wiki and Hardware Listing / Vendors

Zadig USB Driver Tool

Visual Micro - Nano 33 IoT Debugging Overview

Visual Micro - Debugger Support Listing (All)

Tutorial: Create Debug Probe and Use with Nano 33 BLE

Code

Nano33IoTProject.ino Arduino
Main Sketch file used in video
const int motor = 12;
int currentMotorPWM = 0;
unsigned long currentPeriodStartTime = 0;
unsigned int currentPeriod_MS = 1000;
unsigned int currentResolution = 254;
unsigned int maxResolution = 254;
int currentPWMVal = 0;
unsigned long loopCounter = 0;

void setup() {
	pinMode(motor, OUTPUT);
	analogWrite(motor, currentPWMVal);
}

void loop() {
	currentPWMVal = calculateCurrentPWM_sine((millis() - currentPeriodStartTime) % currentPeriod_MS);
	pwmWrite(currentPWMVal);
	loopCounter++;
}
Calcs.inoArduino
Secondary INO sketch used in Debugger video
// Encapsualtion 
int calculateCurrentPWM_spiky(unsigned long periodTime) {
	return calculateCurrentPWMMultiplier(periodTime) * currentResolution;
}

int calculateCurrentPWM_sine(unsigned long periodTime) {
	return
		round(
			abs(int(
			(
				sin(
				(
					double(calculateCurrentPWM_spiky(periodTime))
					/ 165.00
					)
				)
				)
				* double(currentResolution)
				)
			)
		);
}


int oldValue = -1;
void pwmWrite(int value) {
	if (oldValue != value) {
		analogWrite(motor, value);
		oldValue = value;
		Serial.print(",");
		Serial.print(value);
	}
}

double calculateCurrentPWMMultiplier(unsigned long periodTime) {
	if ((double(periodTime % currentPeriod_MS) / double((currentPeriod_MS / 2.00))) <= 1.00) {
		return (double(periodTime % currentPeriod_MS) / double((currentPeriod_MS / 2.00)));
	}
	else {
		return (1.00 - ((double(periodTime % currentPeriod_MS) - double((currentPeriod_MS / 2.00))) / double((currentPeriod_MS / 2.00))));
	}
}

Schematics

Arduino Nano 33 IoT to Debugger Wiring
Example of how to wire the Arduino Nano 33 IoT to an external debugger.

The header shown is from the Segger JLINK and we are using it in SWD mode here.
Wiring diagram wsxsdqwqwu

Comments

Similar projects you might like

Arduino Nano 33 BLE/IoT Custom Debugging

Project tutorial by visualmicro

  • 1,700 views
  • 2 comments
  • 4 respects

Arduino Uno Debugging

Project tutorial by visualmicro

  • 1,588 views
  • 0 comments
  • 5 respects

MQTT Communication With the Nano 33 IoT & WeMos D1 Boards

Project tutorial by BnBe_Club

  • 2,710 views
  • 2 comments
  • 9 respects

Nano 33 IoT + EC/pH/ORP + WebAPK

Project tutorial by uFire

  • 13,911 views
  • 3 comments
  • 51 respects

The Talking IoT Toaster

Project tutorial by visualmicro

  • 777 views
  • 0 comments
  • 2 respects

Air Drum with Arduino Nano 33 IoT

by Andrea Richetta

  • 4,907 views
  • 4 comments
  • 22 respects
Add projectSign up / Login