Arduino - TCA9548a (I2C Multiplexer) C++ Integration - Stack Overflow
Arduino - TCA9548a (I2C Multiplexer) C++ Integration - Stack Overflow
Asked 3 years, 8 months ago Modified 3 years, 8 months ago Viewed 844 times
I have 4 VL680 laser distance sensors to use with à Raspberry. It is a I2C bus compatible sensor but we can't change the address. So, I use the TCA9548a
Adafruit board I2C multiplexer. I can run only one VL680 directly on my I2C bus but it won't work trough the multiplexer. Datasheet is not clear and I
0 find only code for Arduino or bad Python example.
Here I am :
char filename[20];
const int adapter_nr = 1;
snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
file = open(filename, O_RDWR);
if (file < 0)
{
printf("Unable to connect reach I2C bus \n");
exit(EXIT_FAILURE);
}
// multiplex address
const int addr = 0x70;
char buf[10];
buf[0] = 0x01; // to select channel 0
write(file, buf, 1);
I2C_init();
doTheSameAsOneOnlyVL680();
...
I don't know how I must do and nothing help. Is that the way to select the channel ? How write and read then ?
void I2C_init()
{
const int addr = 0x29;
if(setup == 1)
{
printf("Init all registers \n");
write_byte(file, 0x0207, 0x01);
...
}
else
Join Stack Overflow to find
{ the best answer to your technical question, help
Sign up with email Sign up with Google Sign up with GitHub Sign up with Facebook
others answer theirs. printf("Fail \n");
}
set_scaling(file, 1);
}
Share Follow edited Apr 18, 2019 at 13:40 asked Apr 17, 2019 at 20:48
NicolasColsoul
31 1 5
Totally unrelated to your problem, but the size you pass to the snprintf function is including the terminator. Therefore you can pass e.g. sizeof filename instead of
using a magic number. Also, if you program in C++, why don't you use std::string ? – Some programmer dude Apr 17, 2019 at 21:02
When ioctl(file, I2C_SLAVE, addr) runs you're saying "On I2C talk to the multiplexer."
1 Then, with
you make the multiplexer connect the VL680 that's connected to multiplexer first port to the I2C bus.
doTheSameAsOneOnlyVL680();
you need to run some code in order to say "On I2C talk to the distance sensor."
Something like:
, where vl680Addr is the address (you'll need to define that) for the VL680 laser distance sensor,
Thanks for your answer. I thing we are in the right direction. I am able to connect to the sensors because ioctl is showing no error. But I can't read/write to sensor regs.
Here is the initialize code of each sensor (first step of doTheSameAsOneOnlyVL680). I have edited my question. – NicolasColsoul Apr 18, 2019 at 13:37
I change in my I2C_init() function file to file2 for the test and there it says unable to reach laser... I am bad with my channel select. – NicolasColsoul Apr 18, 2019 at 13:59
Join Stack Overflow to I'm
findnot
theclear...,
best without
answerthe
to multiplexer,
your technical question, help
are you able to write/read to/from
Signone
up sensor? If not, I think you'll need to get that working before connecting more sensors.
with email
others answer theirs.
– Alex Baban Apr 18, 2019 at 18:04
Maybe try I2C_SLAVE_FORCE instead of I2C_SLAVE – Alex Baban Apr 19, 2019 at 16:48
Join Stack Overflow to find the best answer to your technical question, help
Sign up with email
others answer theirs.