Hi, I am using trill hub that connects to three different trills. I saw the example of multiple device seems to use a loop to scan through all the i2c path:

void readLoop(void*)
{
	while(!Bela_stopRequested())
	{
		for(unsigned int n = 0; n < gTouchSensors.size(); ++n)
		{
			Trill* t = gTouchSensors[n];
			t->readI2C();
		}
		usleep(50000);
	}
} 

Is it mandatory to use this method for reading data from multiple trill using the Trill Hub?

    That is a pretty common method: there is a single resource (the I2C bus) that is accessed sequentially by each sensor with no sleep in between them, and only sleeping between batches of readings. That sleep is probably too large and could go down to 5000 (5 ms).

    Keyi using the Trill Hub?

    This method is good for accessing multiple devices connected on a single bus, regardless of whether you are using Trill Hub or not.

    Keyi is it mandatory to use this method for reading data from multiple trill

    Sure other approaches are possible. What alternatives would you suggest?

    • Keyi replied to this.

      giuliomoro Hi giulio, thank you for the advice. The method goes very well with my trill hub. The only thing now is that the output is clicking when I constantly changing the position on the trill ring. Is that because the touch position value is not smoothed out? Hoe could I fix that.

      giuliomoro Sure other approaches are possible. What alternatives would you suggest?

      I used to think having two threads for each trill could work, but that would be computational expensive right?

        Keyi is that the output is clicking when I constantly changing the position on the trill rin

        Do you get any printout warnings in the console? It could be that you need to scan more often. As mentioned, the code you posted scans every 50 ms, try making it 5 ms instead by using usleep(5000).

        Keyi I used to think having two threads for each trill could work,

        What would each of the two threads for each Trill do?

        • Keyi replied to this.

          giuliomoro I didn't get any warnings. Using usleep(5000) improves a little bit but still not that smooth.

          giuliomoro What would each of the two threads for each Rrill do?

          I used to think it could be using void loopTrillRing(void), and void loopTrillSquare(void), and in the setup function using Bela_runAuxiliaryTask(loopTrillRing) and Bela_runAuxiliaryTask(loopTrillSquare);;
          I just want to let one control the filter cut-off and one for the delaytime. I didn't try since the scanning-all-i2c example works well.

            Keyi I used to think it could be using void loopTrillRing(void), and void loopTrillSquare(void), and in the setup function using Bela_runAuxiliaryTask(loopTrillRing) and Bela_runAuxiliaryTask(loopTrillSquare);;

            That's one thread for each trill, not "two threads for each trill". That is less appropriate than the approach above, because it has some extra overhead but doesn't actually improve scan rate because only one of the two threads at a time can access the I2C bus.

            Keyi mproves a little bit but still not that smooth.

            make it as small as usleep(1000) and see if that helps

            a month later

            @giuliomoro Hi Giulio, how should I add a trill on the trill hub if one column is full? I tried to add it on the other column but it seems that it messed up the trill number of my current setting.
            The code that I have for reading the trills is:

            for(uint8_t addr = 0x20; addr <= 0x50; ++addr)
            	{
            		Trill::Device device = Trill::probe(i2cBus, addr);
            		if(Trill::NONE != device && Trill::CRAFT != device)
            		{
            			gTouchSensors.push_back(new Trill(i2cBus, device, addr));
            			gTouchSensors.back()->printDetails();
            		}
            	}

            You can add them to the other column, just make sure they each have a unique address across the board. In what way does it mess up your program? Does it stop detecting one or more sensors? Does it print anything?

            • Keyi replied to this.

              giuliomoro hi Giulio, thank you for the reply. Once I plug it in the other column, I suppose it becomes be touchSensor(5). But it then controls the parameter that touchSensor(0) used to control.

              That probably means that it has the same address as touchSensor(0). You have to change the solder pads on the sensors to make sure that all sensors connected on the same I2C bus (that includes all sensors on a single Trill Hub) are such that each have a unique address.

              • Keyi replied to this.

                giuliomoro the are a bar and a square, would that cause address conflict? All the sensors I use are different trill types.

                no that should not cause any conflict, unless the address on the BAR has been changed via the solder pads.

                • Keyi replied to this.

                  giuliomoro The address of the bar is not changed, the only thing that I changed is the bno-055. I soldered it to 29 to not conflict with the trill square, and it functions well with the square, hex, and ring. I replaced the bar with a potentiometer, so it won't be using the bar for now. Maybe it's the problem of the code?

                    The snippet you posted here should identify all relevant devices.

                    Keyi Maybe it's the problem of the code?

                    I need to see more of the code to be able to comment on that.