hotgarbage
Posts: 23
Joined: Thu Feb 13, 2020 8:48 pm

unsupported operand type() * generator and float

Wed Mar 25, 2020 3:11 am

Hi, i am stuck at what to do with code has anyone come across this.


from gpiozero import MCP3008
import time
adc = MCP3008(channel=0)
count = 0
values = []

while True:
wind =round(adc.values * 3.3,1)
if not wind in values:
values.append(wind)
count +=1
print(count)
>>%Run wind_direction_byo.py
Traceback (most recent call last):
File "/home/pi/weather-station/wind_direction_byo.py", line 8, in <module>
wind =round(adc.values * 3.3,1)
TypeError: unsupported operand type(s) for *: 'generator' and 'float'
>>>

pcmanbob
Posts: 8392
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: unsupported operand type() * generator and float

Wed Mar 25, 2020 9:13 am

Edit...
Removed incorrect answer to prevent confusion.

and when using code tags you use them like this


Add [code] at the top

code goes here

and [/code] at the bottom.
Last edited by pcmanbob on Wed Mar 25, 2020 9:31 am, edited 1 time in total.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

scotty101
Posts: 3868
Joined: Fri Jun 08, 2012 6:03 pm

Re: unsupported operand type() * generator and float

Wed Mar 25, 2020 9:18 am

That's not it.

Round supports two arguments.

Code: Select all

round(...)
    round(number[, ndigits]) -> number
    
    Round a number to a given precision in decimal digits (default 0 digits).
    This returns an int when called with one argument, otherwise the
    same type as the number. ndigits may be negative.
OP should be doing the following

Code: Select all

wind =round(adc.value * 3.3,1)
value not values. values is a generator where as value is the current numerical ADC reading.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

hotgarbage
Posts: 23
Joined: Thu Feb 13, 2020 8:48 pm

Re: unsupported operand type() * generator and float

Thu Mar 26, 2020 6:51 pm

ok . i see that i have values not value . I have been reading up on code and was getting lost . Thank you for your help. I now have great respect for those that code it has been a trying laguage for me to grasp . :)

Return to “Python”