-->
Page 1 of 1

Problems i2c to Arduino

PostPosted: Tue May 05, 2015 5:32 am
by sybeck2k
Hello,
I'm wiring an attiny 85 to an esp8266 via I2C. I'm just trying to send 1 byte from the slave attiny back to the esp.
Here are the codes
(attiny)
Code: Select all#include "TinyWireS.h"           
#define I2C_SLAVE_ADDR  0x26
#define LED_PIN         1

byte t=10;
   
void setup(){
  pinMode(LED_PIN,OUTPUT);
  TinyWireS.begin(I2C_SLAVE_ADDR);
  digitalWrite(LED_PIN,LOW);
  TinyWireS.onRequest(requestEvent);
}

void loop()
{
}

void requestEvent(){ 
   TinyWireS.send(t);
   Blink(LED_PIN);
}


void Blink(byte led) {
 digitalWrite(led,HIGH);
 delay(200);
 digitalWrite(led,LOW);
}


ESP8266
Code: Select allid = 0

i2c.setup(id,7,6,i2c.SLOW)
i2c.start(id)
i2c.address(id, 0x26,i2c.RECEIVER)
result=i2c.read(id,1)
i2c.stop(id)
print("value is " .. string.byte(result,1) )


I can see the led on the attiny blink (meaning that the I2C bus is called correctly), but the value read by the esp is always 0 instead of 10. What is the problem?

Re: Problems i2c to Arduino

PostPosted: Sat May 09, 2015 12:47 am
by roboticboyer
ESP and Attiny are all two slaves.
ESP must send a request to Arduino and after receive a response. ESP is the master.
See this example http://www.esp8266.com/viewtopic.php?f=19&t=2183