iot.device.motorhat和Raspberry Pi4
我使用iot.device.motorhat在Raspberry Pi 4上使用Debian-Bullseye 11遇到问题。我尝试通过Motor Hat PCA9685从Raspberry运行DCMotor。我的代码是:
public class DCMotorController : BaseClass
{
public void StartMotor()
{
using (var motorHat = new MotorHat(1000d, 0x40))
{
var dcMotorOne = motorHat.CreateDCMotor(1); // The error is thrown here
dcMotorOne.Speed = 1;
Wait(1500);
dcMotorOne.Speed = 0;
}
}
}
但是在createCmotor上,我会遇到一个我不知道的错误
Unhandled exception. System.InvalidOperationException: Unexpected value of duty cycle (9766, 10280)
at Iot.Device.Pwm.Pca9685.<OnOffToDutyCycle>g__OnOffToDutyCycleSampled|16_0(UInt16 onCycles, UInt16 offCycles)
at Iot.Device.Pwm.Pca9685.OnOffToDutyCycle(UInt16 on, UInt16 off)
at Iot.Device.Pwm.Pca9685.GetDutyCycle(Int32 channel)
at Iot.Device.Pwm.Pca9685PwmChannel.get_ActualDutyCycle()
at Iot.Device.Pwm.Pca9685PwmChannel..ctor(Pca9685 parent, Int32 channel)
at Iot.Device.Pwm.Pca9685.CreatePwmChannel(Int32 channel)
at Iot.Device.MotorHat.MotorHat.CreateDCMotor(Int32 motorNumber)
at projectV2.DCMotorController.StartMotor() in /home/pi/test/DCMotorController.cs:line 13
I have A problem using Iot.Device.MotorHat on Raspberry Pi 4 with Debian-bullseye 11. I am trying run a DcMotor from the raspberry through motor hat pca9685 . My code is:
public class DCMotorController : BaseClass
{
public void StartMotor()
{
using (var motorHat = new MotorHat(1000d, 0x40))
{
var dcMotorOne = motorHat.CreateDCMotor(1); // The error is thrown here
dcMotorOne.Speed = 1;
Wait(1500);
dcMotorOne.Speed = 0;
}
}
}
But on the CreateDCMotor I get an error that I can't figure out
Unhandled exception. System.InvalidOperationException: Unexpected value of duty cycle (9766, 10280)
at Iot.Device.Pwm.Pca9685.<OnOffToDutyCycle>g__OnOffToDutyCycleSampled|16_0(UInt16 onCycles, UInt16 offCycles)
at Iot.Device.Pwm.Pca9685.OnOffToDutyCycle(UInt16 on, UInt16 off)
at Iot.Device.Pwm.Pca9685.GetDutyCycle(Int32 channel)
at Iot.Device.Pwm.Pca9685PwmChannel.get_ActualDutyCycle()
at Iot.Device.Pwm.Pca9685PwmChannel..ctor(Pca9685 parent, Int32 channel)
at Iot.Device.Pwm.Pca9685.CreatePwmChannel(Int32 channel)
at Iot.Device.MotorHat.MotorHat.CreateDCMotor(Int32 motorNumber)
at projectV2.DCMotorController.StartMotor() in /home/pi/test/DCMotorController.cs:line 13
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当当前的Motorhat配置不在启动时设置的值之内时,库似乎行为不正确。而且马车装订无法纠正这一点。以下解决方法可能会有所帮助(直到固定行为为止):
即使您使用的构造函数在I2C地址上使用0x60的偏移,地址似乎是有效的,因此在将0x40指定为参数为0xA0时,实际地址实际上是在I2C的有效范围之外(仅允许7位)。我不知道这有什么影响。还有其他设备连接到I2C总线吗?否则,错误的地址会出现不同的错误。
我没有测试上述解决方法,因为我没有所需的硬件。
编辑:更新以反映所需的确切构造函数调用,发现OP显然具有“ WaveShare”模块。并且在正确使用的地址上有很多混乱。
It appears the library behaves incorrectly when the current MotorHat configuration is not within the values it would set itself at startup. And the MotorHat binding has no way of correcting this. The following workaround might help (until the behavior is fixed):
The address appears to work, even though the constructor you use uses an offset of 0x60 on the I2C address, so the actual address when specifying 0x40 as argument is 0xA0, which is actually outside the valid ranges for I2C (only 7 bits allowed). I do not know what effect this has. Are there any other devices connected to the I2C bus? Otherwise, a wrong address would give a different error.
I didn't test the above workaround, since I do not have the required hardware.
Edit: Updated to reflect the exact constructor call required, after finding that the OP apparently has the "Waveshare" module. And there's quite a bit of confusion on the correct address to use.