Encoders compatable with I2C?

Can you use I2C and wheel encoders at the same time? It looks like they both use ADC 4,5

This is a 328p baby orangutan.

Hello.

You can use the wheel encoders on any digital inputs. The pins used by the encoders are specified by an array.

- Ben

But the defaults, encoders.init(16,17,18,19) are analog. I understand you can use analog pins as digital but why do you make the distinction that you should use digital inputs?

I’m currently trying to get encoders.init(0,1,2,4) pins PD4,PD2,PD1,PD0 to work without much luck. Should I be able to reverse the order of the pins in the array or will I have re-solder the connections? I’m working in really tight spaces and hate to fiddle with the connections.

First, let me clarify that I was wrong about the pins being specified in an array. Rather, the init() function just takes four pins as arguments.

It doesn’t really make sense to say that “the defaults are analog” in response to a piece of sample code. The init function doesn’t have any defaults; you have to specify the pins that your encoders are connected to on your AVR. The encoder outputs are digital signals and the encoder library uses the specified pins as digital inputs to read the encoders, so only digital inputs can be used. This means that you cannot use the pins ADC6 or ADC7, since these pins are dedicated analog inputs.

The order of the arguments provided to the encoder init() function must be as documented in the command reference. Specifically, the first two arguments must be the outputs from encoder 1 and the last two arguments must be the outputs from encoder 2. You don’t need to resolder anything; just make the code match the pinout for your setup.

Are you using the Arduino version of the library (what IDE are you using?)? If you still have trouble getting it to work, let me know and I’ll try to help you figure out what might be wrong.

- Ben

I’m using the arduino IDE.

I wasn’t able to get port D to work for me so I’m back to encoders.init(16,17,18,19) which does work.

Now I have to find a way to use the uart, instead of i2c, to talk to the orangutan. So far that hasn’t worked out but I have to use a software serial port on the arduino side so I guess it’s not that surprising. Too many variables. I’m going to have to break down and get a usb-serial adapter which should make de-bugging the orangutan code possible. Then, when I know that’s working I can worry about using the software serial port on the arduino.