Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 11 of 11

Thread: Would I need an ADC if using pots with a i2c GPIO expander?

  1. #1
    Junior Member
    Join Date
    Aug 2020
    Posts
    7

    Would I need an ADC if using pots with a i2c GPIO expander?

    Hello,

    I'm looking to attach 16 10k pots to an MCP23017 i2c GPIO expander, and connect that to a Teensy 4.1. The i2c ports on the 4.1 are on the same pins as the analog pins.

    Would the i2c ports on the 4.1 automatically work as ADC converters, or would I need to get an additional ADC breakout to convert the analog potentiometers to digital via the i2c bus?

    I'm very new to these concepts to let me know if that is unclear. Thank you.

  2. #2
    Member
    Join Date
    Apr 2020
    Location
    Tucson
    Posts
    83
    An mcp230017 is a digital chip. It does not have analog inputs to connect to pots, for that you need a/d conversion. The teensy can connect to many pots, but if you have 16 I'd suggest a 74c4067 analog mux. The teensy has many analog input pins to connect a mux, but if you're using 16 you'll be using nearly all the teensy's analog pins (which may be ok) as well as using nearly half the available pins to control other stuff (which might not).

  3. #3
    Junior Member
    Join Date
    Aug 2020
    Posts
    7
    Oh I get it, because you would want to convert it to digital *before* the mcp23017. That makes more sense. I had thought that the chip could read analog signal. Thank you.

  4. #4
    Member
    Join Date
    Apr 2020
    Location
    Tucson
    Posts
    83
    I give you an A for effort, but I admit to seeing you have much to learn. But keep trying.


    No, you don't want to convert to digital before the 23017, you don't need th 23017. Get familiar with the teensy and you'll get it.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,513
    Normally you would use 74HC4051 chips for this. Check out "Connecting Many Buttons & Knobs/Sliders" on the USB MIDI page.

    https://www.pjrc.com/teensy/td_midi.html

  6. #6
    Senior Member
    Join Date
    Jul 2020
    Posts
    120
    "GPIO expander" is another way of saying "two-way shift register." Those are always purely digital. Each line is a single bit, so it can only be 1 or 0. It is possible to have some Rube Goldberg contraption ADC each input and transfer the result bit-by-bit through the register, and that is more or less what you get from the 74HC4051. Like a port expander, it is bidirectional, so you can also output some analog voltage if you like. Quite a versatile little package!

  7. #7
    Junior Member
    Join Date
    Aug 2020
    Posts
    7
    Wonderful, thank you for your input, all. If this means anything, I'm building a midi controller for the Axoloti, which is essentially a synthesizer/music-ready microcontroller with its own software. Many people have hooked analog pots up to MCP230XX chips, which is why I may have seemed so set on using them (they're already in my possession).

    This is purely for my own knowledge (not necessary for my project), but the people who I've spoken to who have recommended the GPIO expanders have used them with results that have lasted a few years now. The output from the chip simply goes into the analog inputs of the Axoloti. Clearly there's something different about the hardware of the Axoloti. Is there a reason that anyone can glean from a cursory glance as to why the MCP chips work with the Axoloti and not the Teensy? Only asking because the pinout on the Axoloti is very similar.

    Either way, thank you all and I look forward to returning with results!

  8. #8
    Senior Member
    Join Date
    Jul 2020
    Posts
    120
    Shift registers (such as port expanders) will work with Teensy just as well as they would with any other microcontroller, assuming they have the same interface. Some are SPI, some are I2C, and some are driven directly by GPIO pins (data, clock, latch.) Specialized ones (like what's built into WS2811/12 LEDs) speak their own protocol. The one thing they have in common is that they do not do analog.

    If someone is hooking up pots to an Axoloti, or a Teensy or MCP, they are not using shift registers. Shift registers are great for when you have a large array of buttons, which could be what they're talking about.

    Another possibility is that they're calling the 74HC4051 (or similar chip) a "port expander," which could be seen as correct, although I have not seen the term used in this way. The chip itself is marketed as an "analog multiplexer." Think of it as a port expander with a lot of extra stuff (like DACs and ADCs) on the same die. So, it's not exactly a port expander because it's not directly relaying the signal, but acting like its own complete GPIO + other circuitry that you can talk to. I think it's most likely that the disconnect between what they said and what's being said here is simply nomenclature.

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,513
    Quote Originally Posted by Hitachii View Post
    Many people have hooked analog pots up to MCP230XX chips
    Maybe you could give us links to the info you've seen? I'm personally curious to see how they managed to make an analog part work with something that isn't made for analog signals.

    This might also be a good moment to mention the distinction between analog pots which produce 1 analog signal representing the angular position and rotary encoders which give you 2 digital signals which encode relative motion (but not absolute position). Physically they look quit similar. Both usually have 3 wires. Maybe what you saw was actually rotary encoders?

  10. #10
    Senior Member
    Join Date
    Jul 2020
    Posts
    120
    A shift register would work fine with encoders, if it was sampled fast enough. You would have to poll it continuously, or you'd miss pulses. How frequently depends on how many pulses per revolution, and how fast a human could realistically be expected to operate the knob.

    Someone else probably has a better idea; but if I was starting down this path, I would figure out the maximum number of pulses per second I could expect from a human twiddling the knob (however energetically you want to try it), and then sample at least twice that often. If the knob has a specified range (which will be the usual case), you must minimize the probability of a lost pulse, else the range will drift the longer the program runs. In practice I would probably hook everything up and try different sampling intervals until the code told me 0.000 when it's rotated all the way to the left, and 1.000 when it's rotated all the way to the right, even if I swept it across the full range a hundred times at different speeds. If it starts drifting so it never goes below 0.01, or never goes above 0.99, then I know there is a problem and I have to sample faster (or at least at a different rate.)

  11. #11
    Junior Member
    Join Date
    Aug 2020
    Posts
    7
    I have realized the issue, and it is my na´vetÚ.

    Somewhere in the middle of my original interaction with the person using the expander, they mentioned that they were using the MCP3208, which is (has?) a ADC converter. They suggested in the same sentence that I use an MCP23017, and in the course of the conversation, the MCP23008 came up. If I seem clueless now, imagine how confusing that was 3 weeks ago. I ordered the latter two, thinking that the former was a typo. They suggested the MCP23017 because of other peripherals they were using.

    So, I am taking @PaulStoffregen advice and getting the multiplexer, while using the many many available Analog pins in the meantime (and to get familiar with using Arduino, as this project has equipped me with the hubris to embark on other digital adventures).

    Case closed. Thank you for your time, everybody.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •