Grove I2C Motor driver support

Here’s Test 03 for the v1.0 board. I found an erroneous conditional in output_switch() and fixed the amount code.

grove_motor_driver_v1_0_03.py (14.8 KB)

I found that too:)

And a lot of errors in the volume dispense functions. I think it was originally copied from the GPIO example and I don’t think that part has been used before. Anyway I think I got it all working now. Just doing some cleanups and adding some more stuff, like a cap on the speed and naming for the channel. Plus a couple of sanity checks on the input variables. I’ll post a copy when im done @bartonio maybe you could test it as well?

There shouldn’t be errors in volume dispense. Though, I did modify it slightly to calculate the speed based on the calculated duty cycle. This was taken from one of the other pump Outputs. No other outputs dispense volume and hence, do not have pump-related functions.

Edit: I do now see there’s an issue with modulating on/off in the rate dispense function and setting the pump speed. You cannot do both. Either it’s full speed and modulated on/off or the speed is set and it’s only turned on for the appropriate duration once. I don’t believe the speed has a linear relationship with duty cycle, but that’s something only you can test because I don’t have this hardware. Even if it is with your motor, it may not be with other motors or across the whole range of speeds. In any case, I think it should be set to full speed for the rate dispense function.

Test 04 attached: grove_motor_driver_v1_0_04.py (15.3 KB)

Changes:

  • changed many “0” to channel variable
  • added speed user option
  • removed speed calculations in place of user-set speed

Thx. I made somewhat the same changes. Your code is referring to a channel option called minimum_sec_on_per_min
image

It looks like your volume dispense logic is derived from a module where the pump is connected via a relay and, as such doesn’t have the ability to throttle down and instead is cycling on / off at full speed. in this case, since we can control the speed with the I2C module, we don’t even need that ability, we can just set the desired max speed and measure the flowrate and enter it into max flowrate and then always dispense at full speed.

An alternative is to change it to be speed dependent (as I did), it does require the output to be somewhat linear with the speed. For instance
max speed = 200
max flowrate = 100 ml/min (at 200 speed)
specific flowrate = 25 ml/min
→ Motor speed 25% of max speed, that would be 50 (of 255).

I think I will go with simple solution. I doubt I will ever have the need to do variable speed.

No matter what, hurray, its working:)

1 Like

I will download this file, can test it tomorrow

Here is my simplified version, tried and tested. I added naming to ease

grove_motor_driver_v1_0_05.py (10.6 KB)

@bartonio could you try this as well

1 Like

But as I alluded to earlier, if the relationship between your set speed and pump rate is nonlinear, then you will not be pumping accurately. This is why I added the user option Speed for each channel, which allows the user to calibrate to a desired speed. This is the principle of how the Atlas Scientific peristaltic pumps work using DC motors: they periodically turn the motor on and off at full speed to attain the desired dispense time and volume rather than modulating the speed. This module would allow calibrating to any speed rather than just full speed. This allows a very accurate dispense rate for whichever duration of dispensing that’s desired. This is what I mimicked in my Generic Peristaltic Pump output.

I’ll check out the working version.

This is fixed in the latest version (Test 6), below.

I do not advise going in the direction of your Test 04 version, as it removes a lot of options that users desire, namely the ability to specify the flow rate. Since the DC motor response is not likely to be linear, the speed is specified and the user calibrates to that speed. If the user then wants to operate at a different flow rate, they can easily change this without having to recalibrate, as the pump is merely pulsing at the calibrated speed rather than changing the speed itself.

Can you test my latest version, TEST 06, and verify if it works? This is the version I would like to include in the built-in set.

grove_motor_driver_v1_0_06.py (15.9 KB)

Perfect. I’ll test it

1 Like

Today i‘ve conected the 1.0 grove motor driver, found them in i2c, load the 1.0 driver Testmodul 06, but only errors appear when i try to switch on or off.I dont know what to do it, because i dont have the knowledge like you
I need some help to get it running.

Could you expand the output, so we can see your settings:)

The only setting i have done is the correct i2c adress in the field, all other settings are unchanged,

Nevermind. I get the same error. Kyle have to look into it.

You can use the 05 version for now, if you dont need the pulsing output.

@kyle When using the manual buttons, I guess no amount is send and as such it looks like amount = None, which it apparently doesn’t like:) You can delete the rotation thingy all together as it is not used as of now. Alternatively you have to change the output function to flip command to 0x03 which is run in reverse.

Also I think none of the dispense functions are working, when calling them, not enough parameters are sent, channel is missing

write_db = threading.Thread(
    target=self.dispense_volume_fastest,
    args=(amount, total_dispense_seconds,))
write_db.start()
1 Like


Here is the log with version no 5 and the (motors)pumps are working

When i set duration to 10 sec, the motor is turning for 10 seconds,
when i get the pumps i can test the volume action

Perfect. You can test the volume function as well, just set flowrate to 100 ml and tell it to dispense 10 ml, it should run for 6 sec then. If you enable the debug log you should see more data in the log file.

But in the end its probably better to use kyles version when the bugs are fixed

I think I fixed the bugs in version 06. You could give it a spin

grove_motor_driver_v1_0_07.py (15.6 KB)