I made a very simple circuit to pilot a DC motor using an AD converter.
If I disable the motor, the circuit will works with no problem, but when I enable the motor sometimes the I2C command "read_byte_data()" give me back a "Remote I/O error (Error 121)"
I use a potentiometer as analogic input (AIN0) for the AD chip (PCF8591) and the value is sent to the Raspberry by I2C protocol (SDA/SCL).
From here the Raspberry drives the motor (In1/In2) using a Motor Driver IC (L293D).
The value (or position) of potentiometer decides rotation and power of the DC motor, with the motor halted when it is in the central position.
I attached the schema for clarity
With the follow python commmand I read the analogic input:
With the follow one I update the motor parameters:
Code: Select all
value = bus.read_byte_data(ad_da_converter_address, register)
Like I said, when I comment out "motor.ChangeDutyCycle(duty_cycle)" I have no problem at all, but when the motor is running the I2C command "bus.read_byte_data()" give back error.
Code: Select all
if value > 128: GPIO.output(motoRPin1, GPIO.HIGH) GPIO.output(motoRPin2, GPIO.LOW) # print('Turn Forward...') elif value < 128: GPIO.output(motoRPin1, GPIO.LOW) GPIO.output(motoRPin2, GPIO.HIGH) # print('Turn Backward...') else: GPIO.output(motoRPin1, GPIO.LOW) GPIO.output(motoRPin2, GPIO.LOW) # print('Motor Stop...') duty_cycle = calculate_duty_cycle(value) motor.ChangeDutyCycle(duty_cycle)
The error appears very often when the motor goes CCW or near to 128 (when the motor is halting) but in general always appear in less than 3 or 5 seconds after started.
It's not a problem about wiring (I double checked them) or power (I use the breadboard power HW-131).
Could be some sort of spurious signals injected in the electric line from the DC motor giving false reading to the AD chip?
I doubt about that because the motor is already filtered from the L293D.
Should I use a capacitor to reduce interferences? Where should I put it?
Do you have any idea what I should check?
Any help is very appreciate,