Skip to content

Commit daa9adb

Browse files
committed
external i2c
1 parent 57d3411 commit daa9adb

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/Arduino_Robot_Firmware.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ int Arduino_Robot_Firmware::begin(){
4949

5050
beginAPDS();
5151
beginServo();
52+
beginI2Cselect();
53+
connectExternalI2C();
5254

5355
return 0;
5456
}
@@ -120,4 +122,24 @@ void Arduino_Robot_Firmware::setServoA(int position){
120122

121123
void Arduino_Robot_Firmware::setServoB(int position){
122124
servo_B->write(position);
125+
}
126+
127+
/******************************************************************************************************/
128+
/* RC Servo A & B */
129+
/******************************************************************************************************/
130+
131+
int Arduino_Robot_Firmware::beginI2Cselect(){
132+
pinMode(SELECT_I2C_BUS,OUTPUT);
133+
}
134+
135+
void Arduino_Robot_Firmware::setExternalI2C(uint8_t state){
136+
digitalWrite(SELECT_I2C_BUS,state);
137+
}
138+
139+
void Arduino_Robot_Firmware::connectExternalI2C(){
140+
setExternalI2C(LOW);
141+
}
142+
143+
void Arduino_Robot_Firmware::disconnectExternalI2C(){
144+
setExternalI2C(HIGH);
123145
}

src/Arduino_Robot_Firmware.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,15 @@ class Arduino_Robot_Firmware{
5050

5151
// Servo
5252
int beginServo(); // initialize Servo interfaces
53-
void setServoA(int position); // 0°-180° servo position
54-
void setServoB(int position); // 0°-180° servo position
53+
void setServoA(int position); // 0°-180° servo position
54+
void setServoB(int position); // 0°-180° servo position
55+
56+
57+
// I2C select
58+
int beginI2Cselect(); // initialize I2C bus selector
59+
void setExternalI2C(uint8_t state); // set A4,A5 connection on I2C bus 2
60+
void connectExternalI2C(); // allow A4,A5 on nano connector to be attached to I2C bus 2
61+
void disconnectExternalI2C(); // disable the connection on A4,A5
5562
};
5663

5764
#endif

src/pinout_definitions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@
4444
#define APDS_LED PB6
4545
#define APDS_INT PC10
4646

47+
// I2C ports
4748
#define I2C_1_SDA PB7
4849
#define I2C_1_SCL PB8
50+
#define SELECT_I2C_BUS PB2
51+
4952

5053

5154

0 commit comments

Comments
 (0)