TodBot's I2C Library Help!

Hello,

I'm using TodBot's library and can't get it to work. The example code doesn't tell me what goes where and on master or slave devices. Can anyone familiar with I2C or this library help? I've pasted my code below.

Here's the URLs:
https://todbot.com/blog/2010/09/25/softi2cmaster-add-i2c-to-any-arduino-pins/

MASTER DEVICE:

#include "SoftI2CMaster.h"
//const int sdaPin = A4;
//const int sclPin = A5;
const int sdaPin = 4;
const int sclPin = 5;
SoftI2CMaster i2c = SoftI2CMaster( sdaPin,sclPin );

void setup()
{
  Serial.begin(9600);  // start serial for output
}

void loop()
{
  i2c.requestFrom( 9 ); // register event
  
  // Request data from slave.
  i2c.beginTransmission(9);
  
  int receivedValue = i2c.receive();
  Serial.println(receivedValue);
 
  i2c.endTransmission();
 
  delay(1000);
}

SLAVE DEVICE:

#include "SoftI2CMaster.h"
//const int sdaPin = A4;
//const int sclPin = A5;
const int sdaPin = 4;
const int sclPin = 5;
SoftI2CMaster i2c = SoftI2CMaster( sdaPin,sclPin );

void setup()
{
  i2c.beginTransmission( 9 );  // send to address 9
}
 
void loop()
{
  delay(100);
  requestCallback();
}
 
void requestCallback()
{
  i2c.beginTransmission(9);
  i2c.send(9);
  i2c.send("#9");
  i2c.endTransmission();
}

Thank you for any help ya'll can offer! I'll take what I can get :slight_smile:

  • John

The example code doesn't tell me what goes where and on master or slave devices

That should be obvious, shouldn't it? The master wants some data. The slave has the data (or makes it up or reads it from a sensor, etc).

What are YOU trying to do?

Yes, trust me I know how a Master and Slave device works. You would think it is intuitive as to what the code is doing, but since I have not been able to get it working and am making this post there's obviously something missing. Whether it's on my end or his. I just need some help. We all need help sometimes! :slight_smile:

Please take a look at my code above and see if it's an easy fix. Maybe I've just been staring at it too long hahaha

Thanks in advance!

  • John

Also, what I want to do is simple. Have a slave being controlled by a master device. I got it working with the Wire library, but that library doesn't work well with LED matrices which is why I need to use TodBot's. The matrix library I am using works fine with it.

  • John

You would think it is intuitive as to what the code is doing, but since I have not been able to get it working and am making this post there's obviously something missing.

What is missing is an explanation of what the code actually does, and how that differs from what you want it to do.

From what I understood it was an alternative and lighter version of what the Wire library does. Am I incorrect?

  • John

Am I incorrect?

I'm not saying that. What I'm saying is that the code you posted does something, even if you can't observe it doing anything. You need to tell us what you at least observe.

You want the code to do something. You need to tell us what you want it to do, with what sensors. You need to tell us how they are connected.

You might want to explain why you are looking for an alternate to hardware I2C.

Sorry for the confusion or lack of details. I need an alternate to the Wire library because what I'm doing is using Arduino's to control 16x32 LED matrices. I have 5 total LED panels and want them all independently controlled by its own Arduino. Those are the slave Arduinos and are all controlled by one master Arduino. I need an alternate because the Wire library is too demanding. When using it the LED matrices don't work correctly because Arduino's don't have enough memory to handle driving the LEDs and running Wire. I had TodBot's library working with the LED matrices, but was having trouble communicating with the Master/Slaves. I had looked at FPGA boards and kept hitting a wall because I don't know how to use them. Also, I want to use Arduino's because I want it all controlled by Voice Commands using the EasyVR Shield.

When the code is ran all that is returned is either 0, 255, or 32. That's all I've been able to get out of it by changing the above code slightly.