Jump to content


Photo

I2C problem between PcDuino V2 ans Arduino Mega 2560


  • Please log in to reply
No replies to this topic

#1 arnaudf09

arnaudf09

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 04 November 2016 - 01:02 PM

Hello,

I have a problem with the I2C communication between Arduino Mega 2560 and PcDuino V2. I search from 2 days for resolved my problem but is not good...

 

I have setup the I2C speed at 200 kHz as the PcDuino.

 

please see my code and send me your opinion...

 

Arduino:

void setup()

{

  Wire.begin(0x02);        // Active I2C en esclave
  Wire.setClock(200000L); // Configure la vitesse a 200 kHz comme le PcDuino

  Wire.onReceive(receiveEvent);
  Wire.onRequest(requestEvent);

}

 

void receiveEvent(int howMany)
{
  while (1 < Wire.available()) // loop through all but the last
  {
    char c = Wire.read(); // receive byte as a character
    Serial.print©;         // print the character
  }
  x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
   
} // Fin du void receiveEvent(int howMany)

 

void requestEvent()
{
// Attends la demande du PcDuino pour envoyer les données en I2C
  Hydrometrie = 1;
  Temperature = 2;
  Luminosite = 3;

  Wire.write(Hydrometrie);    
  Wire.write(Temperature);
  Wire.write(Luminosite);

} // Fin du void requestEvent()

 

 

Et cote PcDuino:

 

def Reception_Donnees_I2C():

    global Hydrometrie, Temperature, Luminosite

 

    Hydrometrie = i2c.read_byte(Pcb_Relayage) # Lit un octet sur la carte relayage
    Temperature = i2c.read_byte(Pcb_Relayage) # Lit un octet sur la carte relayage
    Luminosite = i2c.read_byte(Pcb_Relayage) # Lit un octet sur la carte relayage

 

    print Hydrometrie
    print Temperature
    print Luminosite

 

I received 3 variables in RF 433 MHz by the Mega 2560 (Hydrometrie, Temperature, Luminosite)

and i send it to the PcDuino in I2C communication when the master want...

My problem is in the terminal, i received just 3x the number 3 and not 1,2,3...

Please see my code and send me your comments

 

Thanks

 

@+

 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users