Hello,
if got some problems with my Arduino-System.
I want to send some information from my Arduino-Board to my Attiny45. I know it is possible to communicate in the other way. For example the Attiny send some temperature values to the master.
But that's not my problem. I want to send commands from my Arduino to the slaves and then they change the output ports LOW and HIGH.
Here is my master code:
#include <TinyWireM.h>
#include <USI_TWI_Master.h>
void setup()
{
// put your setup code here, to run once:
TinyWireM.begin();
TinyWireM.requestFrom(requestEvent);
}
void loop()
{
}
void requestEvent(uint8_t slaveAddr)
{
TinyWireM.beginTransmission(2); //start of transmission
TinyWireM.send('F'); //transfers a char to the Slave
TinyWireM.endTransmission(); //end of transmission
delay(500);
TinyWireM.beginTransmission(2); //start of transmission
TinyWireM.send('d'); //transfers a char to the Slave
TinyWireM.endTransmission(); //end of transmission
delay(500);
}
Here the slave code:
//i2c Slave
#include <TinyWireS.h>
#include <Wire.h>
void setup()
{
TinyWireS.begin(2); // join i2c bus with address #2
TinyWireS.onReceive(receiveEvent); // register event
pinMode(1 ,OUTPUT);
}
void loop()
{
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(TinyWireS.available())
{
char c = TinyWireS.receive(); // receive byte as a character
switch (c)
{
case 'd':
digitalWrite(1 ,LOW);
break;
case 'F':
digitalWrite(1 ,HIGH);
break;
}
}
}
The LED on port 1 should blink... But I just get error messages.
Here are the Keywords from the libraries
#######################################
Syntax Coloring Map For TinyWireS
#######################################
#######################################
Datatypes (KEYWORD1)
#######################################
#######################################
Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
send KEYWORD2
available KEYWORD2
receive KEYWORD2
#######################################
Instances (KEYWORD2)
#######################################
TinyWireS KEYWORD2
#######################################
Constants (LITERAL1)
#######################################
#######################################
Syntax Coloring Map For TinyWireM
#######################################
#######################################
Datatypes (KEYWORD1)
#######################################
#######################################
Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
beginTransmission KEYWORD2
endTransmission KEYWORD2
requestFrom KEYWORD2
send KEYWORD2
receive KEYWORD2
#######################################
Instances (KEYWORD2)
#######################################
TinyWireM KEYWORD2
#######################################
Constants (LITERAL1)
#######################################
Thank you very much in advance.