I have 2 trinkets and a mega 1280 (i know the schematic says 2560...but it doesn't have my model) talking via I2C...i have the master trinket 5V take input from a button...when pressed it is supposed light the LED connected to it and send a "1" to the 2 slaves...when you let go it sends a "0"...the slave trinket 3.3V waits for message...when receiving a 1 it turns on the led...a 0 turns is off...the mega does the opposite...0 turns it on the led and 1 turns it off.
what i have got working:
Trinket to Trinket I2C is working fine...where my issue comes into play is when i add in the mega...so i tried just trinket to mega...still a no go...so is there something i am doing wrong on the mega side??? the trinkets and the 4 bit level shifter are brand new from adafruit...the mega i have had for a while and have used to talk to other megas...i have attached code and schematic.
Trinket Master code
Code:
Code: Select all
#include <TinyWireM.h>
#define SWITCH 3
#define LED 4
void setup()
{
TinyWireM.begin();
pinMode(LED, OUTPUT);
pinMode(SWITCH, INPUT);
digitalWrite(SWITCH, HIGH);
}
void loop()
{
if (! digitalRead(SWITCH)) {
digitalWrite(LED, HIGH);
TinyWireM.beginTransmission(4);
TinyWireM.send(1);
TinyWireM.endTransmission();
TinyWireM.beginTransmission(5);
TinyWireM.send(1);
TinyWireM.endTransmission();
}
else {
digitalWrite(LED, LOW);
TinyWireM.beginTransmission(4);
TinyWireM.send(0);
TinyWireM.endTransmission();
TinyWireM.beginTransmission(5);
TinyWireM.send(0);
TinyWireM.endTransmission();
}
}
Code:
Code: Select all
#include <TinyWireS.h>
void setup()
{
TinyWireS.begin(4);
pinMode(3, OUTPUT);
digitalWrite(3, LOW);
}
void loop()
{
while(0 < TinyWireS.available())
{
if (TinyWireS.receive() == 1) {
digitalWrite(3, HIGH);
}
else {
digitalWrite(3, LOW);
}
}
}
Code:
Code: Select all
#include <Wire.h>
void setup() {
Wire.begin(5);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
Wire.onReceive(receiveEvent);
Serial.begin(9600);
}
void loop() {
}
void receiveEvent(int howMany)
{
while(0 < Wire.available())
{
byte c = Wire.read();
Serial.println(c);
if (0 == c) {
digitalWrite(13, HIGH);
}
else {
digitalWrite(13, LOW);
}
}
}