Coder Social home page Coder Social logo

waterpump's Introduction

Firmware for controlling a custom built water pump using an esp32 microcontroller.
Detailed documentation of this project: https://pfusch.zone/regulated-waterpump

Features

  • hardware
    • read pressure-sensor
    • read flow-sensor
    • control VFD
    • control servo motor
    • monitor temperature
  • regulate pressure
    • motor RPM (VFD)
    • bypass valve position (servo)
    • dynamic target pressure (e.g. reduce pressure when no flow)
  • hardware control interface
    • set target pressure poti
    • status leds
    • 3x 7-segment display
    • timeout/powersave mode (turn off VFD, servo, display)
  • remote web interface (MQTT)
    • connect to wifi
    • connect to mqtt broker
    • control (subscribe topics)
      • set PID parameters
      • set target pressure
      • turn on/off
    • status (publish data)
      • pressure
      • PID debug data
      • flow, volume

Hardware Setup

The wiring and all components used are described in the document doc/connection-plan.drawio.pdf.
Photos of pump and control cabinet:

Install

Currently using ESP-IDF version v5.2.1

git clone -b v5.2.1 --recursive https://github.com/espressif/esp-idf.git /opt/esp-idf-v5.2.1
/opt/esp-idf-v5.2.1/install.sh

Compile

setup

run once per terminal:

. /opt/esp-idf-v5.2.1/export.sh

build

idf.py build

Upload/Flash

  • connect FTDI programmer to board (VCC to VCC; TX to RX; RX to TX)
  • press REST and BOOT button
  • release RESET button (keep pressing boot)
  • release BOOT button
  • run flash command:
idf.py flash monitor
  • click RESET button to startup and monitor

Troubleshooting

In this project I often had trouble flashing the firmware, thus requiring multiple attempts.
Invalid head of packet (0xXX): Possible serial noise or corruption.

  • The most significant problem is the VFD causing EMI even in idle -> Turn off VFD (400 V supply) and power the board externally
  • Unreliable jumper cables -> use actual 6 pin connector or tighten jumper contacts

waterpump's People

Contributors

jonny999999 avatar

Watchers

 avatar

waterpump's Issues

TODO - Hardware

  • CAD

    • design distribution box pump
    • design servo - valve mount
    • design user interface panel insert
    • design housing / mount for pcb inside cabinet
    • design caps for closing holes cabinet
  • ELECTRICAL

    • re-wire vfd
    • wire pump components to distribution box
      • pressure sensor
      • flow sensor
      • servo
    • pin assignment parallel port cable
    • pin assignment cable vfd control
  • MECHANICAL

    • replace broken valves
    • clean cabinet
    • lid for cabinet floor
    • pipe assembly top
    • pipe assembly bottom
    • pipe assembly reservoir
    • attach hoses

Relay unreliable - Servo not working (supply only 1.2V)

After the last larger wiring action, the servo does not work reliably anymore.
when measuring the voltage on relay terminals i only see about 1.3V on NO but 12V on COM the relay is certainly on and fuse is ok

  • relay defective?
  • board trace broken?
  • screw terminal?

re-attached wire to terminal, it works for now for some reason (terminal loose?)
-> observe this

Flowsensor: use precision Timer for measuring flow rate

Instead of counting pulses and calculating the rate every few seconds it would be way better to measure the time between each pulse...

Tasks

  • noise must be eliminated in hardware
  • read up how to use precision timer with interrupt

Advantages

  • -> gets rate update as fast as possible (useful when used in control)
  • -> precision is not determined by low measure rate

Display Glitches due to noise

When VFD is running or idling the following happens:

  • bugged characters (rarely and not significant)
  • brightness resets and segment goes to full brightness
  • after some time single modules shut down entirely

ideas

  • lower SPI frequency?
  • re-initialize display repeatedly

Fix memory leak in mqtt task? 'esp_mqtt_client_publish'

After some time wifi crashes
fixed at first by adding missing deletion of json object
however still slowly runs out when publish function is commented in

So after approx 10minutes wifi stops working again

D (256532) mqtt-task: free Heap:170372,170372
I (256532) pressure: adc=0, voltage=0.000000, pressure=-1.250000
D (257042) mqtt-task: Stack high water mark: 2100 bytes

D (257042) mqtt-task: free Heap:170284,170284
I (257042) pressure: adc=0, voltage=0.000000, pressure=-1.250000
D (257552) mqtt-task: Stack high water mark: 2100 bytes

D (257552) mqtt-task: free Heap:170196,170196
I (257552) pressure: adc=0, voltage=0.000000, pressure=-1.250000
D (258062) mqtt-task: Stack high water mark: 2100 bytes

D (258062) mqtt-task: free Heap:170108,170108
I (258062) pressure: adc=0, voltage=0.000000, pressure=-1.250000
D (258572) mqtt-task: Stack high water mark: 2100 bytes

D (258572) mqtt-task: free Heap:170020,170020
I (258572) pressure: adc=0, voltage=0.000000, pressure=-1.250000
D (259082) mqtt-task: Stack high water mark: 2100 bytes

D (259082) mqtt-task: free Heap:169932,169932
I (259082) pressure: adc=0, voltage=0.000000, pressure=-1.250000
D (259592) mqtt-task: Stack high water mark: 2100 bytes

D (259592) mqtt-task: free Heap:169844,169844
I (259592) pressure: adc=0, voltage=0.000000, pressure=-1.250000
D (260102) mqtt-task: Stack high water mark: 2100 bytes

D (260102) mqtt-task: free Heap:169756,169756
I (260102) pressure: adc=0, voltage=0.000000, pressure=-1.250000
D (260612) mqtt-task: Stack high water mark: 2100 bytes

D (260612) mqtt-task: free Heap:169668,169668
I (260612) pressure: adc=0, voltage=0.000000, pressure=-1.250000
D (261122) mqtt-task: Stack high water mark: 2100 bytes

D (261122) mqtt-task: free Heap:169580,169580
I (261122) pressure: adc=0, voltage=0.000000, pressure=-1.250000

Pressure Control Optimization (ideas)

Ideas / Notes to optimize the automatic pressure control:

statemachine

  • Timeout pressure at zero for too long (dry run) - added no flow and no pressure timeout in a912fd4

control algorithm

  • regulateMotor: add min duration - only change speed when valve at max/min pos for certain time - added in e0791d4
  • make valve and motor control communicate in some way e.g. immediately reset variables when changing speed?

PID Library

maybe use existing library or even an autotune library?

Bugged Pressure-sensor ADC readout

The ADC value seems wrong at least in low voltage range (measuring too low) thus showing negative pressure even though its zero or positive

Tested with applying 0-5V voltage using poti and measuring actual voltage at pin after voltage divider (at diode) (0-2.5V) using multimeter:

measured: 2.4V
log:  adc value 2768

measured: 2.403  
log: pressure: adc=2768, voltage=2.230623, pressure=29.709341

measured 0.45 
log: W (144818) pressure: adc=329, voltage=0.265128, pressure=0.226923

measured 1.371
log: W (191858) pressure: adc=1493, voltage=1.203150, pressure=14.297253

measured 0
log:  0adc

tasks

  • compare to other ADC pin with poti connected
  • do more measurements
  • calibrate adc?!

Feature ideas

control cycle

  • idle / timeout mode
    turn off devices to save power and be less annoying (standby for next turn on via mqtt)

    • turn off vfd
    • turn off display
    • turn off servo
    • kepp led on
  • reduce pressure when no flow - a912fd4

  • over temperature also use onboard ds18b20?

user interface

  • 7 set display
    • show pressure
    • show flow
    • show volume
  • button set pressure
  • poti select pressure

webinterface

  • input
    • change target pressure
  • output
    • show current stats
    • chart
      • pressure
      • flow
      • speed
      • show run duration
      • liters
      • status in start/stop button

Implement Flow-Sensor

tasks

HW

  • inspect signal using scope
    • pulldown/up necessary?
    • voltage divider necessary 5v?
  • calibrate liters

FW

  • add custom class to handle the sensor
  • show flow and volume on display

Flowsensor: ISR triggers at noise - unusable (idle flow-rate 200k)

When flow sensor in actual setup (long cable, VFD idling) the liters constantly count up, randomly it stops tough.
image
image
expected about 2 new pulses but counted > 200

ideas

  • calculate max occurring frequency
  • hardware low pass filter
  • ignore too fast pulses in software?

Optimize flow measurement

currently fow sensor has very crude resolution since it only counts one or two pulses per readout

image
image

  • increase read interval
  • implement a rolling window of measurements for calculating the flow rate
    -> e.g. take pulse count of past 10 seconds to calculate rate instead of since last read() call

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.