esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
422 stars 27 forks source link

Add multiple Grove TB6612FNG drivers #2411

Closed simonyel closed 1 year ago

simonyel commented 1 year ago

Describe the problem you have/What new integration you would like o Would love to ability to configure multiple instances of the driver boards

Please describe your use case for this integration and alternatives you've tried: I am making a chemical dispenser for my aquarium and need the ability to drive 4 pumps. To do this I would need two Grove TB6612FNG drivers. Currently, I don't see an option to configure multiples.

Additional context

PXL_20231015_024847871 PORTRAIT PXL_20231015_024659552 PORTRAIT ORIGINAL image

simonyel commented 1 year ago

@max246

max246 commented 1 year ago

I will have a look :) I suppose you managed to change the address of each one, right?

simonyel commented 1 year ago

Does the same address matter when the controllers are on different buses?

I will have a look :) I suppose you managed to change the address of each one, right?

— Reply to this email directly, view it on GitHubhttps://github.com/esphome/feature-requests/issues/2411#issuecomment-1745690601, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHKF4N64AN24SJXOT5EPZE3X5RZYVAVCNFSM6AAAAAA5MUAOUKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONBVGY4TANRQGE. You are receiving this because you authored the thread.Message ID: @.***>

max246 commented 1 year ago

Usually you would use the same i2c bus but with a different address. I am not sure the esp has two different i2c controllers and if that the case, I suppose you could setup at the moment without doing any changes.

simonyel commented 1 year ago

I'll change the address if it comes to that. Would that make the code change easier for you?

Usually you would use the same i2c bus but with a different address. I am not sure the esp has two different i2c controllers and if that the case, I suppose you could setup at the moment without doing any changes.

— Reply to this email directly, view it on GitHubhttps://github.com/esphome/feature-requests/issues/2411#issuecomment-1747500952, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHKF4NZ3RKKGBHBJD3CIJCTX5WZRVAVCNFSM6AAAAAA5MUAOUKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONBXGUYDAOJVGI. You are receiving this because you authored the thread.Message ID: @.***>

max246 commented 1 year ago

Right , what it can be done is :

void set_i2c_addr(uint8_t addr);

I can expose this as action and you would need to run the system once and trigger the action to change the address, you can have two on the same bus.

I can see here in the example of setup a new motor, you just going to copy and paste the block , change the address and id. https://esphome.io/components/grove_tb6612fng.html

simonyel commented 1 year ago

I got the address changed for my second driver via Arduino IDE. Now the driverA is at 0x14, and driverB is at 0x15. What's next?

max246 commented 1 year ago

Please take this as assumption since I dont have two motors board:

I would guess you will have to do something like

grove_tb6612fng:
    id: test_motor_a
    name: motor_outside
    address: 0x14

grove_tb6612fng:
    id: test_motor_b
    name: motor_outside
    address: 0x15

then when you control the motor you use the ID to identify which motor you want to control.

simonyel commented 1 year ago

You can't have duplicate grove_tb6612fng: keys, nor can I nest a list of them under a single entry.

simonyel commented 1 year ago

You can't have duplicate grove_tb6612fng: keys, nor can I nest a list of them under a single entry.

For instance. I can't do:

grove_tb6612fng:
  - id: driverA
    name: "Driver A"
    address: 0x14   
  - id: driverB
    name: "Driver B"  
    address: 0x15

or

grove_tb6612fng:
    id: test_motor_a
    address: 0x14

grove_tb6612fng:
    id: test_motor_b
    address: 0x15
simonyel commented 1 year ago

Any thoughts?

max246 commented 1 year ago

Sorry, got busy with work....

I talked to jess and I just need to add an extra parameter in the code to allow multi blocks.

I will make the change over the weekend, you might need to test my PR if you can

simonyel commented 1 year ago

I will gladly test and report back.

From: Christian @.> Sent: Friday, October 13, 2023 11:50 AM To: esphome/feature-requests @.> Cc: Simon @.>; Author @.> Subject: Re: [esphome/feature-requests] Add multiple Grove TB6612FNG drivers (Issue #2411)

Sorry, got busy with work....

I talked to jess and I just need to add an extra parameter in the code to allow multi blocks.

I will make the change over the weekend, you might need to test my PR if you can

— Reply to this email directly, view it on GitHubhttps://github.com/esphome/feature-requests/issues/2411#issuecomment-1761736736, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHKF4N2M7EQF7OCZTKHPY7DX7FPLFAVCNFSM6AAAAAA5MUAOUKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRRG4ZTMNZTGY. You are receiving this because you authored the thread.Message ID: @.**@.>>

max246 commented 1 year ago

ok done it.

I have updated the doc and tested the code, it works.

Check the doc PR to understand how to setup a multi conf

https://github.com/esphome/esphome/pull/5492

simonyel commented 1 year ago

I tested the github://pr#5492, and it works as expected. I have two driver boards and 4 DC motors\peri-pumps. I was able to address and execute commands on each device. Start > Break >Stop.

simonyel commented 1 year ago

Here is my config:

substitutions:
  device_name: 'quadpump'
  friendly_name: quadpump
  device_comment: "Mounted in the aquarium cabinet"
  entity_prefix: "qp1"
  device_type: "SVYtech"

packages:
  core: !include _config/core.yaml

esphome:
  name: quadpump
  friendly_name: quadpump

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "<redacted>"

status_led:
  pin:
    number: GPIO2 
    inverted: false  

external_components:
  - source: github://pr#5492
    components: [ grove_tb6612fng ]
    refresh: 0s

i2c:
  sda: GPIO19
  scl: GPIO23
  scan: true    

grove_tb6612fng:
  - address: 0x14   
    id: driverA
  - address: 0x15
    id: driverB

globals:
  - id: pump1_runtime
    type: int
    restore_value: yes
    initial_value: '0'
  - id: pump2_runtime
    type: int
    restore_value: yes
    initial_value: '0'  
  - id: pump3_runtime
    type: int
    restore_value: yes
    initial_value: '0'  
  - id: pump4_runtime
    type: int
    restore_value: yes
    initial_value: '0'          

button:
  - platform: template
    name: $entity_prefix Dispense 1
    id: run_pump1
    on_press:
      then:
        - grove_tb6612fng.run:
            id: driverA
            channel: 0
            speed: 90
            direction: FORWARD
        - delay: !lambda 'return id(pump1_runtime);'
        - grove_tb6612fng.break:
            id: driverA
            channel: 0             
        - grove_tb6612fng.stop:
            id: driverA
            channel: 0 
  - platform: template
    name: $entity_prefix Dispense 2
    id: run_pump2
    on_press:
      then:
        - grove_tb6612fng.run:
            id: driverA
            channel: 1
            speed: 90
            direction: FORWARD
        - delay: !lambda 'return id(pump2_runtime);'
        - grove_tb6612fng.break:
            id: driverA
            channel: 1    
        - grove_tb6612fng.stop:
            id: driverA
            channel: 1    
  - platform: template
    name: $entity_prefix Dispense 3
    id: run_pump3
    on_press:
      then:
        - grove_tb6612fng.run:
            id: driverB
            channel: 0
            speed: 90
            direction: FORWARD
        - delay: !lambda 'return id(pump3_runtime);'
        - grove_tb6612fng.break:
            id: driverB
            channel: 0             
        - grove_tb6612fng.stop:
            id: driverB
            channel: 0 
  - platform: template
    name: $entity_prefix Dispense 4
    id: run_pump4
    on_press:
      then:
        - grove_tb6612fng.run:
            id: driverB
            channel: 1
            speed: 90
            direction: FORWARD
        - delay: !lambda 'return id(pump4_runtime);'
        - grove_tb6612fng.break:
            id: driverB
            channel: 1    
        - grove_tb6612fng.stop:
            id: driverB
            channel: 1    

switch:                 
  - platform: template
    id: sw_feed_pump1
    name: $entity_prefix Feed pump 1
    turn_on_action:
      then:
        - switch.template.publish:
            id: sw_feed_pump1
            state: ON
        - grove_tb6612fng.run:
            id: driverA
            channel: 0
            speed: 90
            direction: FORWARD
    turn_off_action:
      then:
        - grove_tb6612fng.break:
            id: driverA
            channel: 0             
        - grove_tb6612fng.stop:
            id: driverA
            channel: 0        
        - switch.template.publish:
            id: sw_feed_pump1 
            state: OFF          
  - platform: template
    id: sw_feed_pump2
    name: $entity_prefix Feed pump 2
    turn_on_action:
      then:
        - switch.template.publish:
            id: sw_feed_pump2
            state: ON
        - grove_tb6612fng.run:
            id: driverA
            channel: 1
            speed: 90
            direction: FORWARD
    turn_off_action:
      then:
        - grove_tb6612fng.break:
            id: driverA
            channel: 1             
        - grove_tb6612fng.stop:
            id: driverA
            channel: 1        
        - switch.template.publish:
            id: sw_feed_pump2
            state: OFF                                    
  - platform: template
    id: sw_feed_pump3
    name: $entity_prefix Feed pump 3
    turn_on_action:
      then:
        - switch.template.publish:
            id: sw_feed_pump3
            state: ON
        - grove_tb6612fng.run:
            id: driverB
            channel: 0
            speed: 90
            direction: FORWARD
    turn_off_action:
      then:
        - grove_tb6612fng.break:
            id: driverB
            channel: 0             
        - grove_tb6612fng.stop:
            id: driverB
            channel: 0        
        - switch.template.publish:
            id: sw_feed_pump3 
            state: OFF          
  - platform: template
    id: sw_feed_pump4
    name: $entity_prefix Feed pump 4
    turn_on_action:
      then:
        - switch.template.publish:
            id: sw_feed_pump4
            state: ON
        - grove_tb6612fng.run:
            id: driverB
            channel: 1
            speed: 90
            direction: FORWARD
    turn_off_action:
      then:
        - grove_tb6612fng.break:
            id: driverB
            channel: 1             
        - grove_tb6612fng.stop:
            id: driverB
            channel: 1        
        - switch.template.publish:
            id: sw_feed_pump4
            state: OFF
number:
  - platform: template
    id: pump1_dose
    name: $entity_prefix Dose 1
    min_value: 0.1
    max_value: 2.5
    step: 0.1
    optimistic: True
    restore_value: True
    on_value:
      - globals.set:
          id: pump1_runtime
          value: !lambda 'return id(pump1_dose).state * 1000;'
  - platform: template
    id: pump2_dose
    name: $entity_prefix Dose 2
    min_value: 0.1
    max_value: 2.5
    step: 0.1
    optimistic: True
    restore_value: True
    on_value:
      - globals.set:
          id: pump2_runtime
          value: !lambda 'return id(pump2_dose).state * 1000;'
  - platform: template
    id: pump3_dose
    name: $entity_prefix Dose 3
    min_value: 0.1
    max_value: 2.5
    step: 0.1
    optimistic: True
    restore_value: True
    on_value:
      - globals.set:
          id: pump3_runtime
          value: !lambda 'return id(pump3_dose).state * 1000;'
  - platform: template
    id: pump4_dose
    name: $entity_prefix Dose 4
    min_value: 0.1
    max_value: 2.5
    step: 0.1
    optimistic: True
    restore_value: True
    on_value:
      - globals.set:
          id: pump4_runtime
          value: !lambda 'return id(pump4_dose).state * 1000;'