two_socks
Posts: 6
Joined: Thu Aug 15, 2019 8:49 pm

I2C - read_byte_data() error 121 with DC motor

Fri Aug 23, 2019 8:57 pm

Hi,
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
motor.JPG
Schema
motor.JPG (91.08 KiB) Viewed 266 times

With the follow python commmand I read the analogic input:

Code: Select all

value = bus.read_byte_data(ad_da_converter_address, register)
With the follow one I update the motor parameters:

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)
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.
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,
thanks

User avatar
joan
Posts: 14179
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C - read_byte_data() error 121 with DC motor

Fri Aug 23, 2019 9:04 pm

Triggered by vibration? I'd triple check the wiring. A clear photo will help.

two_socks
Posts: 6
Joined: Thu Aug 15, 2019 8:49 pm

Re: I2C - read_byte_data() error 121 with DC motor

Fri Aug 23, 2019 9:58 pm

Umh... I don't think so because the motor is connected using a long wire and usually I kept it up in the air.

The wires are a little bit messy but they are right :oops:
circuit.jpg
circuit.jpg (100.11 KiB) Viewed 242 times

User avatar
joan
Posts: 14179
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C - read_byte_data() error 121 with DC motor

Sat Aug 24, 2019 8:18 am

To make out the wiring we would need multiple clear photos of your setup. A clear photo showing the wiring at the I2C device will be most helpful.

danjperron
Posts: 3390
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: I2C - read_byte_data() error 121 with DC motor

Sat Aug 24, 2019 12:08 pm

Could you put the motor controller on another power supply. At least put a LC filter at the power of your motor's driver.

Add capacitors to your power line between 0 and 5V! 0.1µF in parallel with a 100µF. Also add a 0.1µF next to your i2c chip (gnd and digitial VCC has close has possible).

Motor creates a lot of transient noises. I had to deal with this problem more than ones.

Also use ferrite and pass all the wire from your motor into it. This will reduce high frequency transient.

Be sure that the ground and power are not in the opposite side of your power source to the raspberry Pi. The breadboard is not for high current. On a breadboard even 1A is a lot

P.S. Also I don't think that a 9V battery is a good choice. The motors maximum current is way higher than the 9V battery could deliver.

two_socks
Posts: 6
Joined: Thu Aug 15, 2019 8:49 pm

Re: I2C - read_byte_data() error 121 with DC motor

Mon Aug 26, 2019 6:14 pm

Yes,
I think the problem is about a lack of insulation in the DC motor wires causing noise.

Thanks

Return to “Interfacing (DSI, CSI, I2C, etc.)”