Reputation: 57
I'm struggling with my Raspberry. The Terminal prints out that there's a float division by zero but I don't divide anything in the code. I already reseted the entire Pi and reinstalled everything. The first run after the reset was successful but afterwards every run shows up the error below.
Would be awesome if you could help me! Thanks!
Traceback (most recent call last):
File "robot2.py", line 43, in <module>
kit.servo[servo1].angle = length1
File "/usr/local/lib/python3.6/site-packages/adafruit_servokit.py", line 150, in __getitem__
servo = adafruit_motor.servo.Servo(self.kit._pca.channels[servo_channel])
File "/usr/local/lib/python3.6/site-packages/adafruit_motor/servo.py", line 103, in __init__
super().__init__(pwm_out, min_pulse=min_pulse, max_pulse=max_pulse)
File "/usr/local/lib/python3.6/site-packages/adafruit_motor/servo.py", line 45, in __init__
self.set_pulse_width_range(min_pulse, max_pulse)
File "/usr/local/lib/python3.6/site-packages/adafruit_motor/servo.py", line 49, in set_pulse_width_range
self._min_duty = int((min_pulse * self._pwm_out.frequency) / 1000000 * 0xffff)
File "/usr/local/lib/python3.6/site-packages/adafruit_pca9685.py", line 71, in frequency
return self._pca.frequency
File "/usr/local/lib/python3.6/site-packages/adafruit_pca9685.py", line 145, in frequency
return self.reference_clock_speed / 4096 / self.prescale_reg
ZeroDivisionError: float division by zero
Traceback (most recent call last):
File "robot2.py", line 43, in <module>
kit.servo[servo1].angle = length1
File "/usr/local/lib/python3.6/site-packages/adafruit_servokit.py", line 150, in __getitem__
servo = adafruit_motor.servo.Servo(self.kit._pca.channels[servo_channel])
File "/usr/local/lib/python3.6/site-packages/adafruit_motor/servo.py", line 103, in __init__
super().__init__(pwm_out, min_pulse=min_pulse, max_pulse=max_pulse)
File "/usr/local/lib/python3.6/site-packages/adafruit_motor/servo.py", line 45, in __init__
self.set_pulse_width_range(min_pulse, max_pulse)
File "/usr/local/lib/python3.6/site-packages/adafruit_motor/servo.py", line 49, in set_pulse_width_range
self._min_duty = int((min_pulse * self._pwm_out.frequency) / 1000000 * 0xffff)
File "/usr/local/lib/python3.6/site-packages/adafruit_pca9685.py", line 71, in frequency
return self._pca.frequency
File "/usr/local/lib/python3.6/site-packages/adafruit_pca9685.py", line 145, in frequency
return self.reference_clock_speed / 4096 / self.prescale_reg
ZeroDivisionError: float division by zero
Traceback (most recent call last):
File "robot2.py", line 43, in <module>
kit.servo[servo1].angle = length1
File "/usr/local/lib/python3.6/site-packages/adafruit_servokit.py", line 150, in __getitem__
servo = adafruit_motor.servo.Servo(self.kit._pca.channels[servo_channel])
File "/usr/local/lib/python3.6/site-packages/adafruit_motor/servo.py", line 103, in __init__
super().__init__(pwm_out, min_pulse=min_pulse, max_pulse=max_pulse)
File "/usr/local/lib/python3.6/site-packages/adafruit_motor/servo.py", line 45, in __init__
self.set_pulse_width_range(min_pulse, max_pulse)
File "/usr/local/lib/python3.6/site-packages/adafruit_motor/servo.py", line 49, in set_pulse_width_range
self._min_duty = int((min_pulse * self._pwm_out.frequency) / 1000000 * 0xffff)
File "/usr/local/lib/python3.6/site-packages/adafruit_pca9685.py", line 71, in frequency
return self._pca.frequency
File "/usr/local/lib/python3.6/site-packages/adafruit_pca9685.py", line 145, in frequency
return self.reference_clock_speed / 4096 / self.prescale_reg
ZeroDivisionError: float division by zero
Traceback (most recent call last):
File "robot2.py", line 43, in <module>
kit.servo[servo1].angle = length1
File "/usr/local/lib/python3.6/site-packages/adafruit_servokit.py", line 150, in __getitem__
servo = adafruit_motor.servo.Servo(self.kit._pca.channels[servo_channel])
File "/usr/local/lib/python3.6/site-packages/adafruit_motor/servo.py", line 103, in __init__
super().__init__(pwm_out, min_pulse=min_pulse, max_pulse=max_pulse)
File "/usr/local/lib/python3.6/site-packages/adafruit_motor/servo.py", line 45, in __init__
self.set_pulse_width_range(min_pulse, max_pulse)
File "/usr/local/lib/python3.6/site-packages/adafruit_motor/servo.py", line 49, in set_pulse_width_range
self._min_duty = int((min_pulse * self._pwm_out.frequency) / 1000000 * 0xffff)
File "/usr/local/lib/python3.6/site-packages/adafruit_pca9685.py", line 71, in frequency
return self._pca.frequency
File "/usr/local/lib/python3.6/site-packages/adafruit_pca9685.py", line 145, in frequency
return self.reference_clock_speed / 4096 / self.prescale_reg
ZeroDivisionError: float division by zero
Upvotes: 1
Views: 486
Reputation: 193
As others have noted, the error is from the library code and hasn't been caught with try
to turn it into a friendly error message. You can only tell by inspecting the implementation of another library but the offending value in self.prescale_reg
is actually a value read from the controller device over the i2c bus.
There's a similar case of this mentioned on Adafruit Forums: RaspberryPi Stepper HAT - example code not working which was diagnosed as a conflict between two progams using GPIO running.
I would double-check the physical i2c connectivity to the controller device, make sure it responds when you scan the i2c bus with i2cdetect
(example in Adafruit Learn: Adafruit 16 Channel Servo Driver with Raspberry Pi: Configuring Your Pi for I2C) and ensure you do not have any other conflicting use of GPIO pins for i2c in your code.
Upvotes: 0