I2C Between Gamebuino and Mega 2560
Posted: Sat Oct 17, 2015 9:03 pm
Hi everybody! I'm making an 8 bit "mini computer" from the gamebuino. The 2560 is supposed to handle the keyboard, which is a 4x4 tactile button matrix. By the way, if you are wondering how I'm going to write 26 letters with it, 13 buttons will be used to write the first 13 letters of the alphabet, and the other 13 will be used by holding the 14th button and pressing one of the 13 buttons, to write the other half of the alphabet. The remaining 2 buttons will be used for backspace and space. Anyways I am using the wire library, and the gamebuino is the host, and the mega is the slave. When I run the host hex file for the gamebuino, it crashes. The size of the sketch is less than 30,000, and is exactly 12,778 bytes. The mega seems to be running fine. Here is the code:
Host(Gamebuino) file:
Slave(Mega) Code:
Help, as always, is appreciated.
Thanks!
Host(Gamebuino) file:
- Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
#include <Wire.h>
int x = 0;
Gamebuino gb;
void setup()
{
// put your setup code here, to run once:
gb.begin();
gb.titleScreen(F("I2C Arduinos"));
Wire.begin();
}
void loop()
{
if(gb.update()) {
Wire.beginTransmission(9); // transmit to device #9
Wire.write(x); // sends x
gb.display.println("Transmitting...");
Wire.endTransmission(); // stop transmitting
}
}
Slave(Mega) Code:
- Code: Select all
#include <Wire.h>
int x = 0;
void setup()
{
// put your setup code here, to run once:
Wire.begin(9);
Wire.onReceive(receiveEvent);
Serial.begin(9600);
}
void receiveEvent(int bytes) {
x = Wire.read(); // read one character from the I2C
}
void loop()
{
Serial.println(x);
}
Help, as always, is appreciated.
Thanks!