ERROR Reflashing R3 Arduino Board For Science Kit

I have an Arduino R3 Science Kit.

The arduino nano RP2040 Connect that came with it is working fine. I can upload my own sketches and run them on the board.

However, when I try and to pair with the Science Carrier using the Science Journal app on my phone, no arduino board is detected.

In the getting started section here: Arduino | Account Settings it suggests reflashing my arduino board with the science kit code.

When I try to compile the sketch it supplies me, I get the following error:

In file included from /run/arduino/sketches/ScienceJournal/ScienceJournal.ino:21:0:
/var/run/arduino/directories-user/libraries/Arduino_ScienceKitCarrier/src/Arduino_ScienceKitCarrier.h:46:10: fatal error: ../../OneWireNg/src/platform/OneWireNg_PicoRP2040.h: No such file or directory
#include "../../OneWireNg/src/platform/OneWireNg_PicoRP2040.h" // forces to use gpio instead PIO hw
compilation terminated.

It seems like the library it tries to call is missing.

Can you please help with the code, or alternative methods to detect the arduino board.

All help would be greatly appreciated :slight_smile:

Thanks

Hi @Martian_Tripod101. I apologize for the trouble caused by the bug in the "Arduino_ScienceKitCarrier" library. I'll provide instructions you can follow to work around the problem:

  1. Click the following link to download a version of the Arduino_ScienceKitCarrier library in which I have made a patch to fix the bug:
    Arduino_ScienceKitCarrier.zip (62.8 KB)
    Your web browser will start a file download.
  2. Open the "ScienceJournal" sketch in Arduino Cloud Editor, just as you did before when you encountered the error.
  3. Click the icon that looks like shelved books ("Libraries") in the bar on the left side of the Cloud Editor page.
    The "Libraries" panel will open.
  4. Click the upward pointing arrow icon at the top of the "Libraries" panel.
    The "Open" dialog will open.
  5. Select the Arduino_ScienceKitCarrier.zip file that was downloaded at step 1 of these instructions in the dialog.
  6. Click the "Open" button.
    The "Open" dialog will close.
  7. You will now see an indicator at the top of the "Libraries" panel in place of the upward pointing arrow icon as the library is imported. Wait for this indicator to disappear.

Now upload the "ScienceJournal" sketch to your Nano RP2040 Connect board, just as you did before when you encountered the error. Hopefully this time everything will work ae expected.


ⓘ If you later decide you want to remove the imported library from your Arduino Cloud account, you will find it under the "Custom" tab of the "Libraries" panel.



Please let us know if you have any questions or problems while following those instructions.


Technical Details

In case you are curious about the technical details, I'll provide an explanation of the bug and its fix below. If you aren't interested, feel free to skip reading it.

Explanation of Bug

The Arduino_ScienceKitCarrier library has a dependency on the OneWireNg library. The developer of the Arduino_ScienceKitCarrier library referenced that dependency with the following #include directive:

This #include directive uses a relative path. That assumes the installation of the OneWireNg library will be at a specific path relative to the installation of the Arduino_ScienceKitCarrier library. That assumption holds true when using Arduino IDE, and in the equivalent environment used by the library's continuous integration system. However, it does not hold true for Arduino Cloud. On the Arduino Cloud server, the Arduino_ScienceKitCarrier.h file that contains the problematic #include directive is at this path:

/var/run/arduino/directories-user/libraries/Arduino_ScienceKitCarrier/src/Arduino_ScienceKitCarrier.h

While the reference header file is at this path:

/run/arduino/directories-data/internal/OneWireNg_0.14.1_37fe3dc3c2e551b0/src/platform/OneWireNg_PicoRP2040.h

So this is why compilation of the sketch via Arduino Cloud Editor fails with that "No such file or directory" error.

Fix

The fix is to avoid any assumption of the relative location of the referenced header file, and instead utilize the standard "library discovery" feature of the Arduino sketch build system.

When an #include directive does only specifies a header filename, the sketch build system searches through the installed libraries to find the library that provides that header file.

So we might expect that the fix could be accomplished like so:

--- a/src/Arduino_ScienceKitCarrier.h
+++ b/src/Arduino_ScienceKitCarrier.h
@@ -43,7 +43,7 @@
 #include "Arduino_BMI270_BMM150.h"

 #ifdef ARDUINO_NANO_RP2040_CONNECT
-#include "../../OneWireNg/src/platform/OneWireNg_PicoRP2040.h"  // forces to use gpio instead PIO hw
+#include <platform/OneWireNg_PicoRP2040.h>  // forces to use gpio instead PIO hw
 #define OneWireNg_CurrentPlatform OneWireNg_PicoRP2040
 #endif
 #ifdef ARDUINO_NANO_ESP32

However, this is not sufficient. The problem is that, for the sake of efficiency, discovery is only performed for header files present in the root of the target library's source code folder. In this case, the #include directive is targeting a header file present under the platform subfolder of the source folder, so this header file will not serve to achieve discovery of the OneWireNg library.

For this reason, it is necessary to add an additional #include directive for a header file that is present in the root of the library's source folder. If that #include directive is placed before the directive for the file in the subfolder, then the subsequent #include directive will work as intended because the library has already been discovered (and thus added to the compiler's "search path"). The OneWireNg.h header file serves as a suitable discovery target. Thus the fix looks like so:

--- a/src/Arduino_ScienceKitCarrier.h
+++ b/src/Arduino_ScienceKitCarrier.h
@@ -43,7 +43,8 @@
 #include "Arduino_BMI270_BMM150.h"

 #ifdef ARDUINO_NANO_RP2040_CONNECT
-#include "../../OneWireNg/src/platform/OneWireNg_PicoRP2040.h"  // forces to use gpio instead PIO hw
+#include <OneWireNg.h>
+#include <platform/OneWireNg_PicoRP2040.h>  // forces to use gpio instead PIO hw
 #define OneWireNg_CurrentPlatform OneWireNg_PicoRP2040
 #endif
 #ifdef ARDUINO_NANO_ESP32

I have submitted a fix for the bug in the library:

Hi - those instructions work and the board successfully reflashed.

However, the board is still not appearing in the available devices in the sensor settings in the Science Journal App. I have attached a screenshot of the app, and a picture of the science kit plugged into my laptop.

I have also checked to see if I could see the arduino board directly from my phone’s bluetooth connections. I attempted this both with the chip on its own and as part of the science carrier. In both cases, the phone’s bluetooth was unable to detect the arduino chip.

I am using a samsung A10 phone, running Android 9.

Thanks for all your help :)