-Bourns EAW encoder-
Reducing the number of pins required using the i2C Expander board
All my content is free.
If you feel that my videos are helping and you would like to contribute, you can toss some coins in the Tip Jar via PayPal.
Select amount then click the “Donate” button.
In the previous tutorial we had a look at the ‘Bourns EAW’ absolute contacting encoder.
It’s great in many ways but it does require eight pins on the Arduino and if you’re using the Arduino UNO, just can run out of pins pretty fast!
In this quick tutorial we will see how to connect it using two pins instead of eight.
We can do this by using an I2C Expansion board which will enable us to communicate with the encoder using the I2C protocol which uses only two pins.
In the next tutorial we will look at how I2C communcation works and more in depth at this little module.
Like I said we will look at the I2C protocol and this I2C expansion module in more details in the next tutorial, but here’s how we will use it today.
The I2C expansion module has eight pins (P0 – P7) that can be use for input or output, kinda like the ones on the Arduino.
So instead of connecting the eight pins of the encoder directly to the Arduino UNO we will connect them to this I2C expansion module.
The only connections we need to make to the Arduino UNO are the 5V and ground, and the I2C pins (A4-SDA, A5-SCL) to be able to read all eight pins of the encoder through this module.
The connections are the same as in the previous tutorial, except that the encoder pins are connected to the I2C expansion module and not to the UNO.
I2C Expansion module connections:
5V and Ground from the Arduino and A4 – A5 to SDA and SCL on the I2C module
5v and Ground from the Arduino and A4 – A5 to SDA and SCL of the backpack
Pin 10 and 11 of Arduino to DIR and STEP pin of the driver
Ground of Arduino to Ground of driver
The EasyDriver is connected to a 12V power supply
Bourns EAW connections:
P0 to P7 of the I2C module connected to Pin 1 to 8 of the encoder
Ground of Arduino connected to a Common pin of the encoder
We are using the same library as in the previous tutorial, last time we used it with the encoder connected directly to the Arduino, but this library also as the capability to use I2C as a connection.
The code is pretty much the same, but we added the I2C address of the I2C expansion module and the library declaration to use I2C instead of direct connection.
On this I2C module you can select the I2C address with the dip switches from 0x20 to 0x27. Since we know the I2C LCD backpack uses by default 0x27 we set the I2C expansion module to 0x20 since we can’t have two I2C modules with the same address.
Here’s a table of the possible addresses using the dip switches:
A0 A1 A2
off off off 0x20
off off on 0x21
off on off 0x22
off on on 0x23
on off off 0x24
on off on 0x25
on on off 0x26
on on on 0x27
Like before I think this encoder is great for some projects and is pretty cheap for what it can do.
But if you are running out of available pins on your Arduino you might want to use this I2C connection method to use two pins instead of eight.
In my testing I didn’t feel much of a slow down in the response of the encoder when using it, but using I2C does introduce some overhead.
So depending on your project you might still want to use the full eight pin connection, but that would be only in certain cases.
Thank you for stopping by!
Copy and Paste the above code/sketch in your Arduino IDE software.
Link to the libraries used in this tutorial:
- I2C LCD library by Francisco Malpartida: https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
- AccelStepper library by Mike McCauley : https://www.arduinolibraries.info/libraries/accel-stepper
- Bourns EAW Encoder library: https://github.com/arielnh56/ACE128