I2C address changing

Hi there,
I’m trying to use two of your sparkfun 7 segment serial displays. SKU: COM-11442
I’ve built two units that use an arduino uno and two rotary sensors to delay a relay triggering.
Object is to fire two separate air cylinders at around 50 to 100 milliseconds apart. The precise timing needs to be adjustable on the fly, so I have the LED displays to show the values of the rotary sensors scaled to 999. The sensors are working but currently I’ve only got the code to display the output of one of them. I know from the serial.print option that they are both working tho.
The problem I need a pointer with is how to change the address of the second display since they both have x71 as default.
I can probably take it from there. I’ll just fiddle about with the code to make the second display show the second rotary sensor.
I think I just need to know how to change the address.
Any ideas?

Many thanks
Chris

/*
Cobbled up from various sketches in examples
*/
int buttonPin = 6;    // digital pin that switch is connected to
int potPin = A0;      // select the input pin for the fire delay potentiometer
int potdurPin = A1;   // select the input pin for duration potentiometer
int ledPin = 13;      // select the pin for the LED
int relayPin = 12;    // pin to trigger relay circuit


int potValue = 0;     // variable to store the value of firing delay potentiometer
int potdurValue = 0;  // varialbe to store the value of duration potentiometer
int buttonState = 0;  // current state of the button

const byte s7sAddress = 0x71;
#include <Wire.h>
byte rcvData;


int s7sSendStringI2C();

void setup() {
  // Must begin s7s software serial at the correct baud rate.
  //  The default of the s7s is 9600.
  Wire.begin();


                     // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
                     // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
                     // initialise the trigger delay potentiometer as an input:
  pinMode(potPin, INPUT);
                       // initialise the duration potentiometer as an input:
  pinMode(potdurPin, INPUT);
                     // initialise the relay as an output:
  pinMode(relayPin, OUTPUT);                   
                     // initialize serial communications:
  Serial.begin(9600);
}


void loop() { 
                    
                    // read the value from pot:
  potValue = map(analogRead(potPin),0,1023,0,100);
                   // print the analog value to computer:
  Serial.println(potValue);
  delay(1);        // delay in between reads for stability
  Wire.beginTransmission(s7sAddress);
                  //print analog value to lCD
  Wire.print(potValue);
  Wire.write(0x79); // Send the Move Cursor Command
  Wire.write(0x00); // Send the data byte, with value 1
  Wire.write(0x77); //send the decimal point
  Wire.write(0b00000100);
  Wire.endTransmission();

  delay(50); //to stop flicker...but too much makes reaction to switch too slow


                 
                   // read the value from pot:
  potdurValue = analogRead(potdurPin);
                   // print the analog value:
  Serial.println(potdurValue);
  delay(1);        // delay in between reads for stability
                   //read the state of the trigger switch 
  buttonState = digitalRead(buttonPin);
                   //check to see if button has been pressed
  if (buttonState == LOW) {
                   // stop the program for <potValue> milliseconds - this is the firing delay
  delay(potValue*10);
 
                   // turn the ledPin on
  digitalWrite(ledPin, HIGH);
                   // turn the relay on
  digitalWrite(relayPin, HIGH);
                   // read the second potdurValue (time the trigger is held open) 
                   // this should be variable to 5 seconds
  potdurValue = analogRead(potdurPin);  
  Serial.println(potdurValue);              
                    // stop the program for <potdurValue> milliseconds - this is the duration delay
  delay(potdurValue*1);
                    // turn the ledPin off:
  digitalWrite(ledPin, LOW);
                    // turn the relay on
  digitalWrite(relayPin, LOW);
  }
}
3 Likes

Hi Chris,

Good news! SparkFun thought of that when designing that part, and the I2C Address is completely configurable.

Take a look at this example from their GitHub:

Let us know if this sparks more questions :slight_smile:
-James

3 Likes

Fantastic!
All good, thanks so much :slight_smile:

Chris

4 Likes

It’s worth mentioning to only execute this address-change when connected to a single unit - lest you change the address of both at the same time :wink:

3 Likes