I am getting a strange error message that I need help decoding it.
Number Of Smack Val = 100
Smack Delay Val = 100
Intensity >> 50%
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 365, in _to_gpio
return _BOARD_MAP[channel]
~~~~~~~~~~^^^^^^^^^
KeyError: (32, 26, 24, 22)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.11/tkinter/__init__.py", line 1948, in __call__
return self.func(*args)
^^^^^^^^^^^^^^^^
File "/home/spanker/Python/SmackerCode_V10.py", line 352, in SmackBottomSelected
print(' Smack Bottom Selected -->> IntensitySelect_Pins >> ' , GPIO.input(IntensitySelect_Pins))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 721, in input
gpio = _to_gpio(channel)
^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 367, in _to_gpio
raise ValueError('The channel sent is invalid on a Raspberry Pi')
ValueError: The channel sent is invalid on a Raspberry Pi
spanker@spanker:~/Python $
intensity >> 50% is not a correct way to assign a value.
Try instead:
intensity = 0.5
As a side note or fyi, >> means shift to the right. If you’re familiar with working with base two numbers, the integer that you include to the right of the two right arrows implies the power that two will be be raised to. The result is the divisor by which you will divide your number by. Here are two examples:
num = 100
result = num >> 1 # Eq. to div by 2^1 = 2
print(result)
result = num >> 2 # Eq. to div by 2^2 = 4
print(result)
In embedded programming, shifting to the right is a handy trick to use for division versus using a regular division instruction. Microcontroller/processers generally use some type of shift register that can easily execute this instruction within no more than two instruction cycles (tops four). Regular division, depending the mc or processor used, can take upwards of ~17ish instruction cycles. This can become critial when when you’re working with time constrained clock cycles (small periods).
From this exception:
Implies:
A KeyError in Python arises when attempting to access a dictionary key that doesn’t exist. Somewhere in your script you are perhaps attempting to either provide a wrong value or attemptingn to access a key / value pair that does not exist. Check your values. Use the print function to print the variable (dictionary) just prior to where it is being used and where the exception is being generated to verify that the expected value is being passed in. Are you actually attemping to pass a list instead of a dictionary (i.e., (32, 26, 24, 22))?
From this exception:
Implies:
In Python, a ValueError is raised when a function receives an argument of the correct data type but an inappropriate value. This means that the input is syntactically correct, but semantically incorrect, causing the function to be unable to process it.
Hard to tell unless you provide more of the script.