Arduino and Digispark communication

How can i make Arduino nano and Digispark communicate? I tried i2c but i can't do this. And i searched for spi but can't find anything. How can i do this?

enes3626:
How can i make Arduino nano and Digispark communicate?

You can use Serial, I2C, SPI, or any of the numerous other communication protocols.

enes3626:
I tried i2c but i can't do this.

Why not? What stopped you? That's most likely your best bet.

enes3626:
And i searched for spi but can't find anything.

Bullshit! Google has thousands of hits for how SPI works and this site has great tutorials on how it works for Arduino. There is plenty out there. You might not have found something specific to doing it with an Arduino and a Digispark, but there is definitely more than enough information out there on SPI for you to make it work.

enes3626:
How can i do this?

I would start by trying to figure out what you did wrong when you tried to use I2C.

My code didn't work. I didn't got how tinywire library works. And wire library didn't work.

enes3626:
My code didn't work.

Well that's a shame. You must have done it wrong. If only there was a place where you could get help fixing it. Oh yeah, right here. Why do you just give up? Why don't you ask someone for help with it?

enes3626:
I didn't got how tinywire library works.

Why not? What part is confusing you?

enes3626:
And wire library didn't work.

Why not? What did you try? What code did you use? What happened?

I have to ask, do you want help or are you just here to lament the fact that you can't do it. If you want help then give us a chance to help you. Post the code. Be detailed.

If you just want to complain that your code "didn't work" for whatever that means, then you're done. I commiserate. Sometimes my code doesn't work too. But I don't give up, I keep learning and trying until it does.

I haven't time for understanding how they work so i copied code from internet. But it didn't work. Maybe i made the connections wrong. D13(SCK) to P2 and A4(SDA) to P0 right?

enes3626:
I haven't time for understanding

Then perhaps you should buy something ready made or hire someone to build it for you.

enes3626:
so i copied code from internet.

That almost never works.

enes3626:
But it didn't work. Maybe i made the connections wrong. D13(SCK) to P2 and A4(SDA) to P0 right?

This shouldn't come as a surprise, but I haven't seen this code you tried to use so I don't know what pins it expects you to connect. How do you think I would know what code you tried when you haven't told us anything?

I have deleted the code. I am gonna try more. Maybe i can find.

I fixed it with help of ATtiny i2c Slave – The Wandering Engineer this. And my connection was wrong. A4 to P0 and A5 to P2.

My digipark code:

// Code for the ATtiny85
#define I2C_SLAVE_ADDRESS 0x4 // Address of the slave
 
#include <TinyWireS.h>
#include <TrinketKeyboard.h>
int i=0;
 
void setup()
{
    TinyWireS.begin(I2C_SLAVE_ADDRESS); // join i2c network
    //TinyWireS.onReceive(receiveEvent); // not using this
    TinyWireS.onRequest(requestEvent);
 
    // Turn on LED when program starts
    pinMode(2, OUTPUT);
    digitalWrite(2, HIGH);
}
 
void loop()
{
    // This needs to be here
    TinyWireS_stop_check();
}
 
// Gets called when the ATtiny receives an i2c request
void requestEvent()
{
char    a = TinyWireS.receive();
    TrinketKeyboard.print(a);
    delay(100);
}

And my Arduino code :

#include <Wire.h>
 
void setup()
{
 Wire.begin(); // join i2c bus (address optional for master)
 
}
 
void loop()
{
 int i = 0;
  Wire.write(i); 
  ++ i;
 
 
 
delay(500);
}

when i want to make the arduino sender it is not working.

enes3626:
when i want to make the arduino sender it is not working.

You will have to describe what you mean by "not working". What did you expect to happen. What actually happened? How do those two things differ?

I wanted to Arduino send command to digispark and digispark will type it. But it is not working nothing happened..I don't know why.

TinyWireS_stop_check();

What does that line do? Why is it there?

So you want your Arduino to just send a 0 over and over? When you read the 0 into a char and then print it, would that make a printable character? Would it make more sense to send '0', a 0 in ascii instead of a 0 which is an ascii code for something unprintable?

I found this on internet. Do you have a tinyWire library code for Arduino nano as sender.

enes3626:
I found this on internet.

I didn't ask where you found it. I asked why that line is there. What is its purpose?

enes3626:
Do you have a tinyWire library code for Arduino nano as sender.

You already have it. What more do you want. Try sending a printable character.

What does printable character mean? I have sent a number. And found this on internet means i have no information about this.

When you print a char variable, it is interpreted to be ascii code. So if you have:

char c = 77;
Serial.print(c);

Then it will print an 'M' to the screen.

You are printing the ascii code 0 which doesn't translate to any normal printable character. Try sending 'A' or '1' instead.

And found this on internet means i have no information about this.

So that means you should not use it until you have learned why it is there. If you are using code you don't understand then you are just asking to frustrate both you and me. You need to do some reading on TinyWire and find out what that is and what it does and why it is there.

Can you give me a link for TinyWire? I can't find anything.

Does google not work today? You obviously got it from somewhere.