The TCA9548A soldered onto a Schmartboard w/ male pins |
I posted a while back about getting the TCA9548A I2C multiplexing chip and the Schmartboard and just now finally got it all soldered up and tested it out. The soldering was ridiculously easy for a chip this size. Got to hand it to Schmartboard for finding a slick, easy to use design. Literally took me 10 minutes from start to finish including heating up the iron and soldering a test chip. In retrospect, I should have soldered female connections onto this board or even gotten the Schmartboard arduino shield, but I'm definitely a noob and this is what happens. It'll work for now.
The longest part of the whole ordeal was figuring out how to wire the thing up, but in the end, I got it all working and was even able to hookup two ADXL-345 accelerometers to it and get readings from both. Again, the main point of this chip is that I want to hook 4 accelerometers up to my board over I2C but all the accelerometers have the same I2C address hardcoded. So, with the TCA9548A, I can control which one I'm talking to at any point in time.
Here's the sample Arduino sketch I threw together to demo things:
#include <Wire.h>
#include <ADXL345.h>
#include <SPI.h>
#include <TCL.h>
#define TCA9548AADDR 0x74 //1110100
// For now, one object works...
ADXL345 adxl;
unsigned long lastStatus = millis();
double xyz[3];
void setup()
{
Serial.begin(9600);
Wire.begin();
Serial.print("initing adxl0...");
selectI2CChannels(0x1);
adxl.powerOn();
Serial.println("done");
Serial.print("initing adxl1...");
selectI2CChannels(0x2);
adxl.powerOn();
Serial.println("done");
}
void loop()
{
unsigned long currentTime = millis();
bool printStatus = false;
if (currentTime > (lastStatus + 500))
{
printStatus = true;
lastStatus = currentTime;
}
selectI2CChannels(0x1);
adxl.getAccelemeter(xyz);
if (printStatus)
printXYZ("ONE");
selectI2CChannels(0x2);
adxl.getAccelemeter(xyz);
if (printStatus)
printXYZ("TWO");
}
void selectI2CChannels(int channels)
{
Wire.beginTransmission(TCA9548AADDR);
Wire.write(channels);
Wire.endTransmission();
}
void printXYZ(char label[])
{
Serial.print(label); Serial.print(": ");
Serial.print(xyz[0]); Serial.print(",");
Serial.print(xyz[1]); Serial.print(",");
Serial.println(xyz[2]);
}
I'm pretty excited about things at this point, they are really starting to come together. I think I'm past due for a cool video update showing a lot of what I've done come together. Back with that as soon as I can...
No comments:
Post a Comment