A7 GPA6 -> B6 GPA5 -> C4 GPA4 -> D2 GPA3 -> E1"> A7 GPA6 -> B6 GPA5 -> C4 GPA4 -> D2 GPA3 -> E1">

Subscribe to Arduino Academy and start learning today for FREE!

Arduino Scale Speedometer Part 3 – Port Expander

The three 7 segment LED’s from part 2 require 24 i/o pins on the Arduino. We can use port expanders to limit that to 2 pins, the I2c connections. Each MCP23017 chip supports 16 i/o pins, so two chips will do, and still only use the two lines on the Arduino, as they are addressable. In our previous two MCP23017 posts we show how to connect and address the MCP23017 chips and provide a link to the datasheet.

1st Digit – Chip 1 Port A Connections:
GPA7 -> A7
GPA6 -> B6
GPA5 -> C4
GPA4 -> D2
GPA3 -> E1
GPA2 -> F9
GPA1 -> G10
GPA0 -> DP5

2nd Digit – Chip 1 Port B Connections:

Become the Maker you were born to be. Try Arduino Academy for FREE!

GPB7 -> A7
GPB6 -> B6
GPB5 -> C4
GPB4 -> D2
GPB3 -> E1
GPB2 -> F9
GPB1 -> G10
GPB0 -> DP5

3rd Digit – Chip 2 Port A Connections:
GPA7 -> A7
GPA6 -> B6
GPA5 -> C4
GPA4 -> D2
GPA3 -> E1
GPA2 -> F9
GPA1 -> G10
GPA0 -> DP5

To send the speed determined in part 1 to the 3 digit display, we need to break up the number into 3 separate numbers, the hundreds, tens, and ones position. This is done with a simple calculation:

first=number/100;
second=number%100/10;
third=number%10;

Then in a case statement you can send the correct code to each chip:

switch (var) {
case 0:
Wire.write(244); //11110100
break;
case 1:
Wire.write(96); //01100000
break;
case 2:
Wire.write(218); //11011010
break;
case 3:
Wire.write(242); //11110010
break;
case 4:
Wire.write(102); //01100110
break;
case 5:
Wire.write(182); //10110110
break;
case 6:
Wire.write(190); //10111110
break;
case 7:
Wire.write(224); //11100000
break;
case 8:
Wire.write(254); //11111110
break;
case 9:
Wire.write(230); //11100110
break;
case DP:
Wire.write(1); //00000001
break;
default:
// if nothing else matches, do the default
// default is optional
break;
}

Now, if all this seems very complicated, and the 24 wires from the 3 digits to the two MCP23017 chips seems like spaghetti, you are right, and we have chosen to go a different path. The Adafruit I2C 4 digit display. More on that tomorrow …..

Become the Maker you were born to be. Try Arduino Academy for FREE!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Archives

0
Would love your thoughts, please comment.x
()
x