SparkFun Forums 

Where electronics enthusiasts find answers.

Questions &/or issues related to products in the Qwiic category should be posted in this forum. To learn more about Qwiic, consider checking out our pillar page on the Qwiic system.
User avatar
By searayca
#205043
I would like to Daisy chain 10 of them. Do I need to set the addresses individually on each one before adding to the chain. A tech note would be very helpful here. Do I need to create a Twist instance for each one?

Please advise. Thank you. Greg
User avatar
By TS-Mark
#205111
Hi Greg,

Setting the address of each individually would be the best option here. You can use the Change Address Example from the Arduino library to set the addresses for each Qwiic Twist in your circuit.

After you have set the addresses, you will need to define each TWIST instance so the I2C master knows which slave device it is talking to. You will also need to include a Wire.begin(); function for each instance to set the custom address you have defined in the previous example. Here is the demo code we used in the Product Showcase Video for reference:
Code: Select all
#include "SparkFun_Qwiic_Twist_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_Twist
#include <Wire.h>
#include <Servo.h>

TWIST twistLR; //Create instance of this object for Left Right
TWIST twistUD; //Create instance of this object Up Down
TWIST twistHead;

int eyesLRPosition;
int eyesUDPosition;
int headPosition;

Servo eyesLRServo;
Servo eyesUDServo;
Servo headServo;

void setup() {

  eyesLRServo.attach(8);
  eyesUDServo.attach(9);
  headServo.attach(10);
  
  Serial.begin(9600);
  Serial.println("Qwiic Twist Example");

  if(twistLR.begin(Wire, 0x3F) == false) 
  {
    Serial.println("Twist does not appear to be connected. Please check wiring. Freezing...");
    while(1);
  }
  twistUD.begin(Wire, 0x41);
  twistHead.begin(Wire, 0x42);

  twistLR.setColor(255/2, 0, 255/2); //Set Red and Blue LED brightnesses to half of max.
  twistLR.connectRed(-10); //Red LED will go down 10 in brightness with each encoder tick
  twistLR.connectBlue(10); //Blue LED will go up 10 in brightness with each encoder tick

  twistUD.setColor(255/2, 255/2,0);
  twistUD.connectRed(-10); //Red LED will go down 10 in brightness with each encoder tick
  twistUD.connectGreen(10); //Blue LED will go up 10 in brightness with each encoder tick

  twistHead.setColor(0, 255/2, 255/2);
  twistHead.connectBlue(-10);
  twistHead.connectGreen(10);

  twistLR.setCount(1000);
  twistUD.setCount(1000);
  twistHead.setCount(1000);

}

void loop() {
  Serial.print("LR Count: ");
  if ((twistLR.getCount() < 990)){
    twistLR.setCount(990);
  }
  if ((twistLR.getCount() > 1010)){
    twistLR.setCount(1010);
  }
  Serial.print(twistLR.getCount()); 
  eyesLRPosition = map(twistLR.getCount(), 990, 1010, 130, 50);
 
  Serial.print("     LR Servo Position: ");
  Serial.print(eyesLRPosition);
  eyesLRServo.write(eyesLRPosition);

  if(twistLR.isPressed()) Serial.print(" LR knob is Pressed!");
  Serial.println();

//*****************END OF EYES LR SECTION*********************
  
  Serial.print("UD Count: ");
  if ((twistUD.getCount() < 990)){
    twistUD.setCount(990);
  }
  if ((twistUD.getCount() > 1010)){
    twistUD.setCount(1010);
  }
  Serial.print(twistUD.getCount()); 
  eyesUDPosition = map(twistUD.getCount(), 990, 1010, 90, 0);
 
  Serial.print("     UD Servo Position: ");
  Serial.print(eyesUDPosition);
  eyesUDServo.write(eyesUDPosition);

  if(twistUD.isPressed()) Serial.print(" UD knob is Pressed!");
  Serial.println();

//*****************END OF EYES UD SECTION*********************

  Serial.print("Head Count: ");
  if ((twistHead.getCount() < 990)){
    twistHead.setCount(990);
  }
  if ((twistHead.getCount() > 1010)){
    twistHead.setCount(1010);
  }
  Serial.print(twistHead.getCount()); 
  headPosition = map(twistHead.getCount(), 990, 1010, 180, 0);
 
  Serial.print("     Head Servo Position: ");
  Serial.print(headPosition);
  headServo.write(headPosition);

  if(twistHead.isPressed()) Serial.print(" Head knob is Pressed!");
  Serial.println();
  
//*****************END OF HEAD TURN SECTION*********************
  
  delay(100);
}
One last thing regarding using more than seven Qwiic Twists on the same bus. You will almost certainly need to disable the pull-up resistors on several of the Qwiic Twists in this circuit so the microcontroller can still pull them LOW for communication. The jumper labeled I2C can be severed to disable the pull-up resistors. We show this in a little better detail in this section of the Hookup Guide. If you have not worked with cutting jumpers and trace on a PCB before, I would recommend reading through our "How to Work with Jumper Pads and PCB Traces" Tutorial.