Tips for Using the Qwiic Port on the Arduino UNO R4

The latest edition of Arduino’s classic form factor is equipped with a Qwiic port. Figure 1 shows the Arduino UNO R4 WiFi Qwiic port connected to a representative Adafruit 3966 barometric sensor.

If you are new to Qwiic, please follow this link for a brief introduction.

TL;DR: An Arduino equipped with a Qwiic connection provides a convenient way to test-drive new hardware. But watch out as the new UNO R4 WiFi adds a new I2C hardware port that challenges the way we think about I2C.

:white_check_mark: Specifically, if your Qwiic board is not working, you may need to change from the Wire object to the Wire1 object when addressing the Qwiic port.

Continue reading for a full explanation and working example.

Figure 1: Image of an Arduino UNO R4 WiFi connected to an Adafruit BMP388 (3966) sensor. All components mounted on the Arduino Plug and Make base.

What is the easiest way to get started with Arduino and Qwiic?

One of the easiest ways to get started with the UNO R4 WiFi is to purchase Arduino’s Plug and Make kit. This TechForum article introduces the kit as a very good starting position for a software-focused exploration of Arduino, programming, and sensors.
The Plug and Make kit is offered with a variety of matching Qwiic boards (Modulinos) including:

Why are the modulino boards preferred?

The modulino boards were natively developed to match the UNO R4 WiFi in physical and software terms.

  • As shown in Figure 2, the modulino boards are all designed to match each other and screw into the Plug and Make base forming a firm foundation for your project.

  • The modulino boards include a comprehensive library. This includes example sketches that are as easy to use as the rudimentary blinky LED program. This is a launchpad to quickly get the learner up to speed allowing Arduino to shine. Instead of focusing on the dull components of programming they can focus on the higher-level applications. True to Arduino tradition, this has the potential to generate excitement as the learner can quickly code relatively complex behaviors.

  • The software libraries are built to accommodate the advanced features of the 32-bit UNO. Specifically, they use the secondary Wire1 port for the UNO’s Qwiic connection.

Tech Tip: The Arduino philosophy of easy application development should be weighed against the discipline of deeper understanding of the microcontroller. The latest edition of the IDE makes this easier as the IDE can jump to the underlying .h and .cpp files. This makes it easier to inspect the underlying support layers.

Figure 2: Image of the Arduino Plug and Make with four modulino boards daisy chained together.

Correct a common issue where the Qwiic sensor is not identified by the Arduino UNO R4 WiFi

The most likely problem is use of an incorrect Wire object. Specifically, we use the Wire (traditional) object when we should be using the Wire1 (Qwiic) object. This answer assumes you have selected an appropriate Qwiic equipped board.

Background: What is the difference between Wire and Wire1 objects?

We start by recognizing that earlier editions of the UNO were built using the 8-bit Atmel(Microchip) ATMega328 AVR. The latest Arduino R4 is based on an advanced 32-bit Renesas RA4M1. Consequently, it has advanced features including multiple communication peripherals.

  • The ATMega328 was equipped with a single hardware based I2C module. This was identified as the Wire object and was accessed using methods such as Wire.begin(), Wire.write(), and Wire.end(). Physically, this hardware is mapped to pin D18 (SDA) and pin D19 (SCL). Most “Arduino” libraries were built to leverage this hardware peripheral for speed.

  • The RA4M1 has two available I2C communication peripherals. It includes the D18 and D19 unit just described as well and the new Qwiic port which is mapped with the RA4M1’s P401 (SDA) and P400 (SCL). This second object is called Wire1.

A working example where the Wire object was changed to Wire1

Figure 1 shows the UNO R4 WiFi connected to an Adafruit parametric sensor. This board is Qwiic ready and easily connects to the R4 using the same connecting wires as the modulino.

  • The example software was loaded following the Adafruit example

  • Adafruit libraries were installed.

  • The I2C example code was compiled and then downloaded to the UNO R4.

  • The system failed to discover the sensor.

Description of a quick (not recommended) modification

One quick, and perhaps dirty, solution is to change the Wire object address from within the Adafruit_BMP3XX.h file.

The change is relatively simple as shown in this snippet. All that was required was changing Wire to Wire1.

public:
  Adafruit_BMP3XX();
  bool begin_I2C(uint8_t addr = BMP3XX_DEFAULT_ADDRESS,
                 TwoWire *theWire = &Wire1);

We call this a “dirty” modification as it breaks the Adafruit library in a way that is not easily detected. For example, suppose we used the same sensor library with a UNO R3. The code would not compile as there is no defined Wire1 object in the ATmega328 ecosystem.

Description of a clean (recommended) modification

A better solution is to change the call from your sketch. Instead of breaking the library we modify the calling function with the address of the Wire1 object. Here is an example:

if (!bmp.begin_I2C(BMP3XX_DEFAULT_ADDRESS, &Wire1)){

Parting thoughts

The Arduino has been with us for about 20 years. In that time, we have become accustomed to things being in a single known location. This example shows how we fall into a trap expecting to leverage the old ways.

Personally, I’m glad Arduino leveraged the additional hardware. Instead of paralleling the Qwiic port with the existing I2C lines, they made it independent allowing increased flexibility.

We would love to hear from you. Have you encountered this change in tradition with other aspects of the Arduino R4?

Best wishes,

APDahlen

Related information

Please follow these links to related and useful information:

About this author

Aaron Dahlen, LCDR USCG (Ret.), serves as an application engineer at DigiKey. He has a unique electronics and automation foundation built over a 27-year military career as a technician and engineer which was further enhanced by 12 years of teaching (interwoven). With an MSEE degree from Minnesota State University, Mankato, Dahlen has taught in an ABET-accredited EE program, served as the program coordinator for an EET program, and taught component-level repair to military electronics technicians. Dahlen has returned to his Northern Minnesota home and thoroughly enjoys researching and writing articles such as this.