RAK12023/RAK12035 with multiple sensors

Are there any code examples for using multiple sensors with the RAK12023/RAK12035?

I see there is code to change the I2C address on a sensor, so I expect I’ll leave one at default and change the other two to something else.

In the code, though, I assume when I instantiate the sensor I’ll have to specify the I2C address - looking through the library, it seems like it supports that.

I’m not 100% sure of the format though.

The declaration in the arduino example for a single sensor:

 /** Sensor */
RAK12035 sensor;

So for multiple sensors is it something like the following (assuming I already changed the addresses on sensor2 and 3 with the change address arduino example):

/** Sensor 1 (default address) */
RAK12035 sensor1;
/** Sensor 2 (0x21) */
RAK12035(0x21) sensor2;
/** Sensor 3 (0x22) */
RAK12035(0x22) sensor3;

Something else?

Hi @Botched1

You can find examples including how to change the I2C address in our WisBlock repo

Thank you. Yes, I saw that example, and that looks easy.

I did not see an example of actually addressing multiple sensors / how to specify the address for each sensor in one .ino file though.

I’ll figure it out when they get here, but thought I would ask in advance of that.

You have to create a separate instance for each of the sensors with their I2C address:

RAK12035 sensor_1; // Using default address 0x20
RAK12035 sensor_2(0x21); // Second sensor set to I2C address 0x21
RAK12035 sensor_3(0x22); // Third sensor set to I2C address 0x22
1 Like

That makes sense - thanks!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.