hello, i am struggling at the moment as i am trying to create a prototype for a class assignment (worth 12 credits) and what i am trying to make is a sonic sensored car that also displays the amount of cm that an object is in front of it. There are three codes and i am stuck on the i2c address for the display.
Code: #include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
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("Unknow 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
}
All i get is the stupid ""
Invalid library found in E:\Compy\Program Files (x86)\Arduino\libraries\i2c_scanner: E:\Compy\Program Files (x86)\Arduino\libraries\i2c_scanner ""
Any suggestions? I have looked on forums but found no answers that helped..
Much appreciated
All i get is the stupid ""
Invalid library found in E:\Compy\Program Files (x86)\Arduino\libraries\i2c_scanner: E:\Compy\Program Files (x86)\Arduino\libraries\i2c_scanner ""
This looks wrong. Why is the i2c_scanner program in the IDE libraries folder?
You have changed the Arduino system files.
Please delelete E:\Compy\Program Files (x86)\Arduino
Download the Arduino IDE and install it.
Start the Arduino IDE. Create a new sketch, replace the empty sketch with the i2c_scanner code ( Arduino Playground - I2cScanner ). Save it. Upload it. Open the serial monitor.
I don't know. I can't imagine that a copy to another driver would be faster. Is the C: drive a network drive ?
Somehow the Arduino system files are changed, because the compiler seems to think that the i2c_scanner is in the system libraries. I'm afraid that more is changed, that is why I advice to make fresh new install of the Arduino IDE.
Koepel:
I don't know. I can't imagine that a copy to another driver would be faster. Is the C: drive a network drive ?
Somehow the Arduino system files are changed, because the compiler seems to think that the i2c_scanner is in the system libraries. I'm afraid that more is changed, that is why I advice to make fresh new install of the Arduino IDE.
I'm going to save the new downlaod on the e drive. Can I do that or will it cause the same problems??
What does the scanner program report. Can the display be seen in the i2c bus?
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
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("Unknow 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
}
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("Unknow 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
}
Sketch uses 4,130 bytes (12%) of program storage space. Maximum is 32,256 bytes.
Global variables use 522 bytes (25%) of dynamic memory, leaving 1,526 bytes for local variables. Maximum is 2,048 bytes.
thats it
Please verify that the serial monitor is set to 9600 baud. There is a little box at the lower right hand corner of the serial monitor window where you can set the baud rate. The rate in the monitor must be the same as the the rate set in the sketch with Serial.begin(9600).
The Serial.println() functions print text to the "serial monitor". You have to open the "serial monitor".
It is a small button in the upper-right corner of the Arduino IDE (a quare button with dots and a magnifier).
It is also in the menu : Tools / Serial Monitor Ctrl + Shift + M
The I2C bus for a Arduino Uno is at pin A4 and A5. Pin A4 is SDA and pin A5 is SCL.
The same SDA and SCL pins are near the USB connector.
cattledog:
Please verify that the serial monitor is set to 9600 baud. There is a little box at the lower right hand corner of the serial monitor window where you can set the baud rate. The rate in the monitor must be the same as the the rate set in the sketch with Serial.begin(9600).