Giter Site home page Giter Site logo

evc_pt2257's Introduction

Evc_pt2257

Arduino Library for using PT2257 - Electronic Volume Controller IC (a.k.a Digital Potentiometer)

Connect the IC to the following pins, you can change it in the .c file.
Pull-up resistors are required on both pins (4K7 or 10K should be fine).
SCL -> A0
SDA -> A1

Datasheet - http://www.princeton.com.tw/Portals/0/Product/PT2257.pdf

Pinout

   |----._.----|
1 -| Lin   Rin |- 8
2 -| Lout Rout |- 7
3 -| Gnd    V+ |- 6
4 -| SDA   SCL |- 5
   |-----------|

API

Volume Attenuation are expressed as unsigned integers
e.g. : to set the attenuation to -21dB express it as 21

  • void evc_init();
    Start the I2C communication
    Call this on setup(); to ensure a reliable initialization, this will delay for 200ms.

  • void evc_setVolume(uint8_t dB);
    Set the attenuation on both channels (between 0dB and -79dB)

  • void evc_setVolumeLeft(uint8_t dB);
    Set the attenuation on the Left channel (between 0dB and -79dB)
    Use this for implementing left/right balance offset.

  • void evc_setVolumeRight(uint8_t dB);
    Set the attenuation on the right channel (between 0dB and -79dB)
    Use this for implementing left/right balance offset.

  • void evc_mute(bool toggle);
    toggle:

    • true: Mute both channels.
      This mode have an effective attenuation of -95dB (+5/-2dB)
    • false: Unmute both channels.

    Note: It will preserve the set Volume when mute is toggled (This behavior is not documented on the datasheet).

  • void evc_off();
    Function OFF (-79dB)
    The exact purpose of this instruction is not clear on the datasheet.


Initialization

The datasheet does not mention anything about it being volatile or not, but it seems to hold state after power cycle, I'm not sure about about if it's just an artifact, but I recommend setting it to a known state just after initialization, so you will not be in a situation that you are changing volume but nothing happens because you have mute on, after a power cycle. So does not expect it to be in a known state just after power on, handle it yourself.

void setup(){
    evc_init();
    
    //ensure power on consistency
    evc_setVolume(79);
    evc_mute(false);
	...
    /* recover state from arduino eeeprom if desired */
	//set the volume to stored state.
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.