Bonjour !
J'ai un arduino nano.
Je lui ai envoyé ce programme(i2c scanner):
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 0; 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);
Serial.println("Entre dans le endTransmission");
error = Wire.endTransmission();
Serial.println("sort du 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(8000); // wait 8 seconds for next scan
}
Comme vous pouvez le voir, j'ai rajouté 2 Serial.println() avant et apres le Wire.endTransmission() pour savoir ou le programme en est.
Et en testant, le programme se bloque dans le Wire.endTransmission(), pas moyen qu'il en sorte !
J'ai relié des résistances sur le bus i2c, comme dans les tutos.
Même en enlevant le DS1307 qui est connecté sur le bus, ça ne change rien, sa me sort scanning... et c'est tout.
Ton code fonctionne. Je viens de l'essayer. Regarde le câblage de ton bus.
Un code que j'ai fait et qui réalise la même fonction. Avec une présentation du résultat plus pratique.
// Wire Scanner
//
//
// Demonstrates use of the Wire library
// Ping all valid adresses on the I²C bus
// and the answer to see if there is a slave
// Print an 8 x 16 array with the results
// Created by fdufnews 2012 december 14th
// This example code is in the public domain.
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
Serial.println(); // Print a banner
Serial.println();
Serial.println("I2C slave scanner");
Serial.println(" reserved adress");
Serial.println(". no slave detected");
Serial.println("X slave detected");
Serial.println();
Serial.println();
int result;
Serial.println(" 0 1 2 3 4 5 6 7 8 9 A B C D E F");
// Scan only valid addresses (8 to 0x7B)
// 0-7 and 7C-7F are reserved ones
unsigned char devices=0; // holds how many devices found
for (unsigned char ad=0; ad<0x7C;ad++){
if(ad%16==0){ // If at start of a row
Serial.print(ad>>4,HEX); // Display high order bit address
Serial.print(" ");
}
if (ad>7){ // skip address from 0 to 7
Wire.beginTransmission(ad); // start transmission
result = Wire.endTransmission(); // end transmission and store answer
if (!result) devices++; // add a device to the count if ACK
Serial.print(" ");
Serial.print(result==0?"X ":". "); // If ACK there is a guy at this address
}
else{
Serial.print(" "); // Sorry nobody here
}
if(ad%16==15) Serial.println(); // end of the row add a new line
}
Serial.println();
Serial.println();
Serial.println();
Serial.print(devices, DEC);
Serial.print(" device");
Serial.print(devices>1?"s":"");
Serial.println(" found on the bus");
}
void loop()
{
}
Je viens de dessouder tous ce qui etait soudé à l'arduino et j'ai toujours le meme probleme.
Est ce que je peux obtenir un résultat si il n'y a rien de branché sur les pins SDA et SCL ?
Est ce que les pins utilisés sont bien le 4 et le 5 ?
Est ce qu'il ne faut pas configurer les pins quelque part ?