I am using an ultrasound sensor HC-SR04 and it works fine using an I/O pin for the tigger and another for the echo. I would like to use it via a hub. The hub has the I2C address of 0x61 and the CH0 write address is 0x42 and the CH0 read address is 0x46. How do I use the hub adresses in my script instead of the pin numbers?
What exactly is a hub in your context? It sounds like an I/O extender on the I2C bus but you failed to tell us the exact type if my guess is correct.
I am looking for a general solution to using a hub rather than just pins. The hub I am using is described as a "IoT MEGA328-Modul für Arduino". It is as you say an I/O extender on the I2C bus.
Don't use the work "hub" for this as that term is used for something different in technical documents.
Post a link to the used component!
You cannot use the I/O extender as a direct replacement of the I/O pins built into the microcontroller but you can change the corresponding code to change the pin on the extender instead of the internal one or read from there. Most I/O extenders have corresponding Arduino libraries which make that process quite easy and come with example code about how to use it.
I use the word "hub" because that is what the manufacturer refers to it as. m5-docs
Just because a Chinese manufacturer uses misleading terms you don't have to do the same.
But thanks for the link. Did you realize that the vendor offers Arduino code support?
The board isn't using an I2C I/O extender but microcontroller board (as the Arduino) with an ATmega328p and a special firmware.
You won't get lucky with that project. As the you extension board uses a microcontroller to set and read the extension pins, the response time isn't exactly deterministic and the delay much too long to get reasonable results. Usually the few milliseconds needed to transfer the command over the I2C bus doesn't matter but using sound a delay of 1ms means an error of about 30cm.