"arduino.h": no such file or directory, where am I supposed to fix it?

I'm trying to run a simple I2C Scanner code (the one I'm sure most of us has used), however I get the following error:

In file included from /tmp/959632525/Scanner/Scanner.ino:1:0:
/home/builder/Arduino/libraries/i2cscanner_1_0_0/src/I2CScanner.h:5:11: fatal error: arduino.h: No such file or directory

Here's where my issue is, though; I'm using the Cloud Editor. I know that there's a file somewhere that I'd likely need to replace "arduino.h" with <Arduino.h>, however I can't access any files because I'm using the cloud editor, all I have access to is the sketch but that doesn't have "arduino.h" anywhere on it. How do I fix this issue?

My code:

#include "I2CScanner.h"

I2CScanner scanner;

const uint8_t num_addresses = 4;
const byte addresses[num_addresses] = { 0x20, 0x21, 0x40, 0x41 };
bool results[num_addresses] = { false, false, false, false};


void setup() 
{
	Serial.begin(9600);
	while (!Serial) {};

	scanner.Init();
}

void loop() 
{
	for (uint8_t index = 0; index < num_addresses; index++)
	{
		results[index] = scanner.Check(addresses[index]);
	}
	
	for (uint8_t index = 0; index < num_addresses; index++)
	{
		if (results[index])
		{
			Serial.print("Found device ");
			Serial.print(index);
			Serial.print(" at address ");
			Serial.println(addresses[index], HEX);
		}
	}
	delay(5000);
}

maybe for your board you need special scanner lib
my scanner is:

 // --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
// 
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>


void setup()
{
  Wire.begin();

  Serial.begin(115200);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++) 
 {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
   {
      Serial.print("I2C device found at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4) 
   {
      Serial.print("Unknown error at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

#include "I2CScanner.h"

I would say that most people do not use the library, but rather the simple scanner sketch by Nick Gammon from https://www.gammon.com.au/i2c

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

void setup() {
  Serial.begin (115200);

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

I copied the code and it worked! I suppose the Scanner library could've been out of date or something? I have seen it used and have used it before with my Uno R3 but I dunno, that's beyond my knowledge. Thank you, though!

Hi @itsfoxy87.

The problem is there is a bug in the library:

The bug was fixed five years ago, but the library maintainer never made a new release of the library since that time so the fix is only available to those who use the beta tester version of the library. The release versions of the libraries are preinstalled in Arduino Cloud, so that is why you still suffer from the bug when you use the library.

I submitted a request for the library maintainer to make a new release so others won't encounter this problem in the future:

It looks like a workaround has already been provided and is working for you so I guess this is resolved. In case you do still want to use the library for some reason, just let me know and I'll provide instructions you can follow to install the beta version of the library that has the bug fixed.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.