I’m trying to connect my D1 mini module and attiny85 USB module together over a data wire, but I don’t know how to do it.

Basically, what I want to do is have the D1 broadcast a hotspot with a web page that when a button is pressed, it sends a signal to the attiny85. The D1 is connected via power wires to the attiny85.

I have the sending signal and web server setup on the D1 but I don’t know how to let the attiny85 receive it.

If it helps, I’m using the wire.h library on the D1

(edit: sorry for inactivity, just haven’t been able to test it)

  • why do you need to use the ATtiny? what does it do what the D1 can't?
    – Juraj
    Dec 25 '20 at 4:37
  • I’m using the attiny85 USB module to send keystrokes to a computer, but if I was using it as a microcontroller I wouldn’t use it at all.
    – circle guy
    Dec 25 '20 at 14:47

ATTinyCore seems to come with a Wire library implementation presenting the same interface as you find in other Arduino board packages. The damellis package doesn't, so if you've been trying to use that one, I'd suggest switching to ATTinyCore.

To get started you should be able to use the ESP8266-Arduino Wire library's Master Writer example with ATTinyCore Wire library's Slave Receiver example. To be clear, you don't need to get them from github, they should be available in the File/Examples menu. Because the interface is the same, you may find that it doesn't matter which board from which you take the example.

I don't know that I've ever used this Wire library in ATTinyCore; my only memory of using I2C slave no an ATTiny85 was coding it directly myself, but I expect it works fine. I may try myself to confirm though.

On the ATTiny85 you'll be using DIP/SOIC pin 7 (PB2) for the SCL signal. And DIP/SOIC pin 5 (PB0) for the SDA signal.

If I try it myself later I'll update this with more details.

More details

I don't have a D1 mini. I do have this NodeMCU clone though. According to the pin maps, the D1 mini's D1 and D2 pins are same as on the NodeMCU, that is GPIO5 an GPIO4 respectively. I wired it together as shown here:

NodeMCU and ATTiny85 connected for I2C

I've drawn some lines on the lower part of the image where the camera angle is bad. The smaller inset images are just for showing a better angle there. The yellow and white leads carrying I2C "Wire" data are doctored simply because they went out of frame.

Don't take the "5V" on the ISP cable breakout too literally, that line is at 3.3V (from the NodeMCU 3.3V pin).

ATTiny85 had the following code loaded onto it. It is just the ATTinyCore slave receiver example with unnecessary comments removed and code to set the LED based on whether it receives a non-zero byte in the I2C ("Wire") transaction:

#include <Wire.h>

static const int LED_PIN = 4;
static const int SLAVE_ADDRESS = 0x08;

void setup() {
  pinMode(LED_PIN, OUTPUT);

void loop() {}

void wire_receive(int howMany) {
  if (Wire.available()) {
    digitalWrite(LED_PIN, Wire.read());

The following was loaded onto the NodeMCU board. Likewise derived from the ESP8266 Arduino Wire master-writer example. Set the local ESP8266 led when it sends the state over to the ATTiny85. The result is that the ATTiny85 and ESP8266 change their LEDs every 1 second together. The NodeMCU module is wired to light the LED on a LOW, the ATTiny85 to light on a HIGH, so when one is lit the other is not.

#include <Wire.h>
#include <PolledTimeout.h>

#define SDA_PIN 4
#define SCL_PIN 5
const int16_t I2C_SLAVE_ADDRESS  = 0x08;

void setup() {
  Wire.begin(SDA_PIN, SCL_PIN);

void toggle_led() {
    static bool led_state;
    led_state = !led_state;    
    digitalWrite(LED_BUILTIN, led_state);

void loop() {
  using periodic = esp8266::polledTimeout::periodicMs;
  static periodic nextPing(1000);

  if (nextPing) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.