I have asked in the past about the possibilities of cross-platform multiplayer, but I only recently started trying to implement a little test. Unfortunately I don’t exactly know what I’m doing when it comes to I2C, just the high-level concepts.
I’m trying to do something a bit weird, where I’m trying to interface with a Gamebuino Classic running a simple 2-player pong game, but right now I’m just trying to get it to acknowledge that the Pokitto is sending anything, even wrong data. The Gamebuino is using the Arduino Wire library, but I figured if the protocol is the same it should work across libraries and devices. Right now I’m trying to have the Pokitto be the slave and the Gamebuino be the master, so I just try to detect on the Pokitto that data is requested of it and to send garbage data back. However, the Pokitto never acknowledges it got any messages from the master at all, and the Gamebuino acts like nothing is connected.
Here’s my test code I’m running on the Pokitto:
#include "Pokitto.h"
Pokitto::Core pokitto;
I2CSlave slave(P0_5, P0_4);
int my_status = 0;
uint8_t try_address = 0;
int main()
{
char buf[10];
char msg[] = "Slave!";
pokitto.begin();
pokitto.setFrameRate(60);
int x = 0;
while (pokitto.isRunning())
{
if (pokitto.update())
{
slave.address(try_address);
int i = slave.receive();
switch (i) {
case I2CSlave::ReadAddressed:
slave.write(msg, strlen(msg) + 1); // Includes null char
my_status = 1;
break;
case I2CSlave::WriteGeneral:
slave.read(buf, 10);
printf("Read G: %s\n", buf);
my_status = 2;
break;
case I2CSlave::WriteAddressed:
slave.read(buf, 10);
printf("Read A: %s\n", buf);
my_status = 3;
break;
}
if( my_status == 0 ){
try_address++;
}
pokitto.display.clear();
pokitto.display.setCursor(1,1);
pokitto.display.println(x);
++x;
pokitto.display.println(my_status);
pokitto.display.println(try_address);
pokitto.display.println(buf);
if( my_status == 0 ){
for(int i = 0; i < 10; i++) buf[i] = 0; // Clear buffer
}
}
}
return 0;
}
Right now I’m cycling through every i2c slave address and trying to receive with that address just in case I don’t have the right address, because I don’t know if I have the right address.
On the gamebuino it apparently is using address 2, which is supposedly reserved. However, the Wire lib docs say it uses 7-bit addresses and that some addresses needed to be shifted, so I just wasn’t sure whether there would be a difference in the way addresses are handled in each library.
Here’s the code for the master in the multiplayer pong game on Gamebuino: https://github.com/Gamebuino/Gamebuino-Classic/blob/master/examples/3.Advanced/PongMulti/master.ino
I also have double and triple checked that my wires are connected to the correct pins. I can verify the game works between a Gamebuino Classic and Makerbuino.