Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert to voltage #3

Open
tomjoro opened this issue Feb 15, 2022 · 0 comments
Open

convert to voltage #3

tomjoro opened this issue Feb 15, 2022 · 0 comments

Comments

@tomjoro
Copy link
Collaborator

tomjoro commented Feb 15, 2022

Should we add support for final voltage conversion?

  • Reading will be between (1015) is 12 bits: -2048 and 2047
  • Reading will be between (1115) is 16 bits: -32,768 and 32,767

In the data sheet table 3 there is the voltage conversion instructions.

So to convert to volts I did the following: (for the 1015)

 @doc """
   This is for ADS1015
      see data sheet Table 3
  """
  def convert_to_voltage(fsr, gain \\ 2048) do
    factor = gain / 1000
    # 32768 bit shifted >> 4
    {:ok, fsr * (factor / (32768.0 / 16.0))}
  end

The only catch here is to be sure to use the same gain that was used when making the reading. The read and conversion both default to 2048 (for the ADS1015). ADS1115 has the same gain settings, but the FSR range is 16 bit so it'd be the following final line.

{:ok, fsr * (factor / (32768.0))}. # For ADS1115

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant