RPi Pico & ADS1115 only the half value ???

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
errorflash
 
Posts: 6
Joined: Sun Jul 25, 2021 10:30 am

RPi Pico & ADS1115 only the half value ???

Post by errorflash »

I have connect an ADS1115 for Input 4 Potentiometer for a custom Joystick.
The Adc from the Pico direct recognize the value from 65535 steps.
The Adc from the ADS1115 recognize only the half 32767 steps.

Have i maybe a mapping Problem ?

Thanks for Help!

Code:

Code: Select all

import board
import busio
import time
import digitalio
import usb_hid
import analogio
#-----analog setup-----
i2c = busio.I2C(board.GP1, board.GP0)
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
ads = ADS.ADS1115(i2c)
#-----joystick setup-----
from adafruit_hid.gamepad import Gamepad
gp = Gamepad (usb_hid.devices)
button_pins = (board.GP10, board.GP11, board.GP12, board.GP13, board.GP14, board.GP15)
gamepad_buttons = (1, 2, 3, 11, 12, 13)
buttons = [digitalio.DigitalInOut(pin) for pin in button_pins]
for button in buttons:
    button.direction = digitalio.Direction.INPUT
    button.pull= digitalio.Pull.UP
ads.gain = 4    
  
ay = AnalogIn(ads, ADS.P0)
ax = analogio.AnalogIn(board.A1)
#az = analogio.AnalogIn(board.A2)
#ar_z = analogio.AnalogIn(ads, ADS.P2)
#az = analogio.AnalogIn(ads, ADS.P3)

def range_map(x, in_min, in_max, out_min, out_max):
    return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min


while True:

    for i, button in enumerate(buttons):
        gamepad_button_num = gamepad_buttons[i]
        if button.value:
            gp.release_buttons(gamepad_button_num)
        else:
            gp.press_buttons(gamepad_button_num)
    print(ay.value)
    time.sleep(1)
      
    gp.move_joysticks(
       x=range_map(ax.value, 0, 65535, -127, 127),
       y=range_map(ay.value, 0, 65535, -127, 127),
#       r_z=range_map(ar_z.value, 0, 65535, -127, 127),
#       z=range_map(az.value, 0, 65535, -127, 127),
   )
    


User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: RPi Pico & ADS1115 only the half value ???

Post by adafruit_support_mike »

The ADS1115 produces signed output. The range of possible values is -32768 to 32767.

You can only get negative values from relative measurements (the voltage at input B is higher or lower than the voltage at input A). Single-ended readings (relative to GND) can only produce positive values.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”