Post topics, source code that relate to the Arduino Platform

User avatar
By sybeck2k
#16541 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?