Unsupported type for__gt__ Not sure what this is

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
RainySun
 
Posts: 73
Joined: Thu Nov 18, 2021 2:55 pm

Unsupported type for__gt__ Not sure what this is

Post by RainySun »

Hey, I am new to circuit python; I used to mostly work with Arduino IDE but slowly shifting towards circuit python.
I have written a code below that compares previous value to a recent value. Looked at the REPL, and not sure what this is talking about.
I hope to hear your response.

Code: Select all

import time
import board
from analogio import AnalogIn

def get_voltage(pin):
    return (pin.value * 3.3) / 65536

analog_in1 = 0

while True:

    for i in range(100):
        analog_in2 = AnalogIn(board.A1)
        if analog_in2 > analog_in1:      # line 14
            analog_in1 = analog_in2
            time.sleep(0.5)
    print(get_voltage(analog_in1))

Attachments
REPL.PNG
REPL.PNG (15.21 KiB) Viewed 104 times

User avatar
dastels
 
Posts: 15817
Joined: Tue Oct 20, 2015 3:22 pm

Re: Unsupported type for__gt__ Not sure what this is

Post by dastels »

analog_in2 is an instance of AnalogIn representing the ADC pin (i.e. A1). That can't be compared to an integer, which is the complaint. To read the analog value on the pin you need to access its value property as described in https://learn.adafruit.com/circuitpytho ... -analog-in.

So before the loop:

Code: Select all

analog_pin = AnalogIn(board.A1)
then in the loop:

Code: Select all

analog_in2 = analog_pin.value
Dave

User avatar
RainySun
 
Posts: 73
Joined: Thu Nov 18, 2021 2:55 pm

Re: Unsupported type for__gt__ Not sure what this is

Post by RainySun »

Thank you, Dave! That worked.

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

Return to “Adafruit CircuitPython”