0.1.0 PERIPUMP

This commit is contained in:
rob tillaart 2022-10-14 20:14:47 +02:00
parent dabf9ca300
commit 21a024c37e
18 changed files with 822 additions and 0 deletions

View File

@ -0,0 +1,31 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
# selected only those that work
platforms:
- uno
# - due
# - zero
# - leonardo
# - m4
# - esp32
# - esp8266
# - mega2560
- rpipico
libraries:
- "Servo"

View File

@ -0,0 +1,4 @@
# These are supported funding model platforms
github: RobTillaart

View File

@ -0,0 +1,13 @@
name: Arduino-lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
compliance: strict

View File

@ -0,0 +1,17 @@
---
name: Arduino CI
on: [push, pull_request]
jobs:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -0,0 +1,18 @@
name: JSON check
on:
push:
paths:
- '**.json'
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
pattern: "\\.json$"

View File

@ -0,0 +1,16 @@
# Change Log PERIPUMP
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.0] - 2022-10-13
- initial version
- add stop(), get- and setpercentage()
- add getSeconds(), resetSeconds() for simple duration management.
- low percentages < 50% do not work.

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022-2022 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,100 @@
//
// FILE: PERIPUMP.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2022-10-13
// PURPOSE: Arduino library for peristaltic pump
#include "PERIPUMP.h"
// CONSTRUCTOR
PERIPUMP::PERIPUMP(uint8_t pumpPin)
{
_pin = pumpPin;
_percentage = 0;
_sumTime = 0;
}
void PERIPUMP::begin()
{
_myServo.attach(_pin);
stop();
resetRunTime();
}
void PERIPUMP::stop()
{
_myServo.writeMicroseconds(1500);
if (_start != 0)
{
_sumTime += (millis() - _start);
_start = 0;
}
}
void PERIPUMP::setPercentage(float percentage)
{
// weighted runtime ?
// _sumTime += (millis() - _start) * abs(_percentage);
_percentage = constrain(percentage, -100, 100);
uint16_t ms = 0;
if (_percentage == 0)
{
ms = 1500;
if (_start != 0)
{
_sumTime += (millis() - _start);
_start = 0;
}
}
else if (_percentage > 0)
{
// 1600 - 2500
ms = 1600 + 9 * _percentage; // 9 == 900 / 100%
if (_start == 0) _start = millis();
}
else if (_percentage < 0)
{
// 500 - 1400
ms = 1400 + 9 * _percentage;
if (_start == 0) _start = millis();
}
_myServo.writeMicroseconds(ms);
}
float PERIPUMP::getPercentage()
{
return _percentage;
}
//////////////////////////////////////////////////////
//
// DURATION
//
float PERIPUMP::getRunTime()
{
float seconds = _sumTime;
if (_start != 0) seconds += (millis() - _start);
return seconds * 0.001;
}
float PERIPUMP::resetRunTime()
{
float s = getRunTime();
_sumTime = 0;
_start = 0;
return s;
}
// -- END OF FILE --

View File

@ -0,0 +1,52 @@
#pragma once
//
// FILE: PERIPUMP.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2022-10-13
// PURPOSE: Arduino library for peristaltic pump
//
// Tested with dfrobot peristaltic pump DFR0523
//
#include "Arduino.h"
#include "Servo.h"
#define PERIPUMP_LIB_VERSION (F("0.1.0"))
class PERIPUMP
{
public:
PERIPUMP(uint8_t pumpPin);
void begin();
//////////////////////////////////////////////////////
//
// RUNNING
//
void stop();
void setPercentage(float percentage);
float getPercentage();
//////////////////////////////////////////////////////
//
// DURATION
//
float getRunTime(); // total seconds running since last reset / start.
float resetRunTime();
private:
uint8_t _pin;
float _percentage;
Servo _myServo;
uint32_t _sumTime = 0;
uint32_t _start = 0;
};
// -- END OF FILE --

View File

@ -0,0 +1,133 @@
[![Arduino CI](https://github.com/RobTillaart/PERIPUMP/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/PERIPUMP/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/PERIPUMP/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/PERIPUMP/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/PERIPUMP/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/PERIPUMP/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/PERIPUMP.svg?maxAge=3600)](https://github.com/RobTillaart/PERIPUMP/releases)
# PERIPUMP
Arduino library for peristaltic pump DFR0523 and compatibles.
## Description
VERY EXPERIMENTAL - AVR (UNO) only for now.
The DFR0523 is a peristaltic pump which can be controlled by a PWM signal.
This PWM (Pulse Width Modulation) is provided by the Arduino Servo library.
To hide the details of the Servo library and provide an easy to use interface,
this PERIPUMP library gives control by setting the speed of the pump as a percentage
ranging from -100.0% .. 100.0%.
The Servo library allows 900 steps for 0..100% so in theory the precision is
approximately around 1 decimal.
In my first tests however with a 5Volt lab power supply, the pump only started
to run around 60% at 5 volt and around 50% at 6 volt.
Not measured if the behaviour was linear for the remaining 50%.
This implies that the actual flow depends on BOTH the voltage used and the percentage set.
The library provides also a minimalistic time registration.
It measures how long the pump has been running since the start of the sketch or
since the last call to **resetRunTime()**.
This run time does not take into account the speed of the pump, a feature that might
be implemented in the future.
Note however that given that the pump only runs from 50-60% the output of **getRunTime()**
is not accurate.
Feedback on the library is welcome.
## Hardware schema
In my first tests the DFR0523 pump drew a current between 330 -360 mA at full speed.
This implies an external power supply of 5 (or 6) volts is mandatory.
```
// POWER SUPPLY PROCESSOR PUMP
//
// PWM----------PWM
// GND---------GND----------GND
//
// 5-6 Volts VCC----------------------VCC
//
```
## Interface
### Base
- **PERIPUMP(uint8_t pumpPin)** constructor. pumpPin should be a PWM supporting pin.
- **void begin()** initialize the internal variables.
- **void stop()** set speed percentage to zero, effectively stop the pump.
Also stops the run time measurement counter.
- **void setPercentage(float percentage)** sets speed as a percentage of the full speed.
The range goes from -100.0 % .. +100.0 %.
- If percentage == 0, the pump stops.
- Negative values set the pump in reverse.
- Positive values set the pump in forward mode.
- **float getPercentage()** returns set speed: -100.0 % .. +100.0 %.
### RunTime
- **float getRunTime()** returns total seconds running since last reset / start.
- **float resetRunTime()** returns total seconds running since last reset / start.
Resets the internal time counter to zero again.
## Operation
The examples show the basic working of the functions.
#### 0.1.0 release
- low percentages < 50% do not work.
## Future
#### Must (next release)
- investigate a possible solution for the **lower 50% problem**.
- map the range 1-100% only on the top 500 steps of the underlying Servo lib.
- initial speed as parameter for **begin()**
- default percentage == 0 ?
#### Should
- update readme.md
- test more
- examples
- investigate flow rate == (non) linear
- investigate startup behaviour (had some hickups)
#### Could
- investigate flow support
- add **void setVolumePerSecond(float flow)** indication cm^3 / sec
- at full speed only?
- linear / non linear interpolatable (multiMap).
- investigate calibration process.
- add **void forward()** **void reverse()**
- add **void setInvert(bool true)** (if pump is connected reverse it would be easy to fix in software.
#### Won't (for now lowest prio)
- unit test possible?
- No servo.h include fails.
- compilation of examples works for UNO and RP2040 pico.
- add **void pump_ml(int ml)** auto stop after X ml? possible?
- investigate difference per pump (one pump behaves different enough)
- investigate flow-accounting?
- sum += time x speed - is that better?
- two counters needed, one per direction

View File

@ -0,0 +1,39 @@
//
// FILE: peripump_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: minimal demo
// URL: https://github.com/RobTillaart/PERIPUMP.git
//
#include "PERIPUMP.h"
PERIPUMP pump(5);
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("PERIPUMP_LIB_VERSION: ");
Serial.println(PERIPUMP_LIB_VERSION);
pump.begin();
pump.stop();
}
void loop()
{
int pos = analogRead(A0) - 512; // assumes UNO 10 bits ADC
pump.setPercentage(pos / 5.12);
Serial.print(pos);
Serial.print('\t');
Serial.print(pump.getPercentage());
Serial.println();
delay(100);
}
// -- END OF FILE --

View File

@ -0,0 +1,58 @@
//
// FILE: peripump_runtime.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/PERIPUMP.git
//
#include "PERIPUMP.h"
PERIPUMP pump(5);
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("PERIPUMP_LIB_VERSION: ");
Serial.println(PERIPUMP_LIB_VERSION);
pump.begin();
pump.stop();
Serial.println(pump.getRunTime());
delay(5000);
Serial.println(pump.getRunTime());
delay(1000);
pump.setPercentage(50);
delay(2000);
Serial.println(pump.getRunTime());
pump.setPercentage(75);
delay(2000);
Serial.println(pump.getRunTime());
pump.stop();
delay(2000);
Serial.println(pump.getRunTime());
pump.resetRunTime();
pump.setPercentage(50);
delay(2000);
Serial.println(pump.getRunTime());
pump.stop();
Serial.println("\ndone...");
}
void loop()
{
}
// -- END OF FILE --

View File

@ -0,0 +1,60 @@
//
// FILE: peripump_servo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: test for peri pump with servo library only.
// URL: https://github.com/RobTillaart/PERIPUMP.git
//
#include "Arduino.h"
#include "Servo.h"
Servo s;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.println("PERIPUMP SERVO ONLY TEST");
s.attach(5); // Connect to PIN 5
// EXTREMES test
s.write(0);
delay(5000);
s.write(90);
delay(5000);
s.write(180);
delay(5000);
s.write(0);
delay(5000);
// RANGE test
for (int i = 0; i <= 180; i += 5)
{
Serial.write(i);
s.write(i);
delay(5000);
}
// VERY slow test.
for (int i = 90; i <= 180; i++)
{
Serial.write(i);
s.write(i);
delay(10000);
}
s.write(90);
delay(2000);
}
void loop()
{
}
// -- END OF FILE --

View File

@ -0,0 +1,141 @@
//
// FILE: peripump_slow_start_stop.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/PERIPUMP.git
//
#include "PERIPUMP.h"
PERIPUMP pump(5);
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("PERIPUMP_LIB_VERSION: ");
Serial.println(PERIPUMP_LIB_VERSION);
pump.begin();
pump.stop();
pump.setPercentage(100);
delay(2000);
pump.stop();
delay(1000);
pump.setPercentage(-100);
delay(2000);
pump.stop();
delay(1000);
pump.setPercentage(10);
Serial.println(pump.getPercentage());
delay(2000);
pump.setPercentage(20);
Serial.println(pump.getPercentage());
delay(2000);
pump.setPercentage(30);
Serial.println(pump.getPercentage());
delay(2000);
pump.setPercentage(40);
Serial.println(pump.getPercentage());
delay(2000);
pump.setPercentage(50);
Serial.println(pump.getPercentage());
delay(2000);
pump.setPercentage(60);
Serial.println(pump.getPercentage());
delay(2000);
pump.setPercentage(70);
Serial.println(pump.getPercentage());
delay(2000);
pump.setPercentage(80);
Serial.println(pump.getPercentage());
delay(2000);
pump.setPercentage(90);
Serial.println(pump.getPercentage());
delay(2000);
pump.setPercentage(100);
Serial.println(pump.getPercentage());
delay(2000);
// pump.setPercentage(0);
// Serial.print(millis());
// Serial.print('\t');
// Serial.print(pump.getPercentage());
// Serial.println();
//
// // take 0.5 seconds to go to 100%
// slowStart(100.0, 5000);
// Serial.print(millis());
// Serial.print('\t');
// Serial.print(pump.getPercentage());
// Serial.println();
// delay(1000);
//
// slowStop(2000);
// Serial.print(millis());
// Serial.print('\t');
// Serial.print(pump.getPercentage());
// Serial.println();
// delay(1000);
//
// slow(0, 100, 5000);
// Serial.print(millis());
// Serial.print('\t');
// Serial.print(pump.getPercentage());
// Serial.println();
// delay(1000);
//
// slowStop(10000);
// Serial.print(millis());
// Serial.print('\t');
// Serial.print(pump.getPercentage());
// Serial.println();
// delay(1000);
pump.stop();
delay(1000);
}
void loop()
{
}
void slowStart(float perc, uint32_t mils)
{
slow(0, perc, mils);
}
void slowStop(uint32_t mils)
{
slow(pump.getPercentage(), 0, mils);
}
// blocking slow speed adjustment
uint32_t slow(float percStart, float percStop, uint32_t mils)
{
uint32_t count = 0;
uint32_t start = micros();
float step = (percStop - percStart) / (mils * 1000.0);
while (micros() - start < (mils * 1000))
{
float speed = percStart + step * (micros() - start);
pump.setPercentage(speed);
// Serial.println(speed);
count++;
}
pump.setPercentage(percStop);
// Serial.println(count);
return count;
}
// -- END OF FILE --

View File

@ -0,0 +1,19 @@
# Syntax Colouring Map For peristaltic
# Data types (KEYWORD1)
PERIPUMP KEYWORD1
# Methods and Functions (KEYWORD2)
begin KEYWORD2
stop KEYWORD2
setPercentage KEYWORD2
getPercentage KEYWORD2
getRunTime KEYWORD2
resetRunTime KEYWORD2
# Constants (LITERAL1)
PERIPUMP_LIB_VERSION LITERAL1

View File

@ -0,0 +1,23 @@
{
"name": "PERIPUMP",
"keywords": "peristaltic, pump, DFR0523",
"description": "Arduino library for peristaltic pump DFR0523 and compatibles.",
"authors":
[
{
"name": "Rob Tillaart",
"email": "Rob.Tillaart@gmail.com",
"maintainer": true
}
],
"repository":
{
"type": "git",
"url": "https://github.com/RobTillaart/PERIPUMP.git"
},
"version": "0.1.0",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",
"headers": "PERIPUMP.h"
}

View File

@ -0,0 +1,11 @@
name=PERIPUMP
version=0.1.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for peristaltic pump DFR0523 and compatibles.
paragraph=
category=Motors
url=https://github.com/RobTillaart/PERIPUMP.git
architectures=*
includes=PERIPUMP.h
depends=

View File

@ -0,0 +1,66 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2022-10-13
// PURPOSE: unit tests for the peristaltic pump (DFR0523).
// https://github.com/RobTillaart/peristaltic
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
// supported assertions
// ----------------------------
// assertEqual(expected, actual)
// assertNotEqual(expected, actual)
// assertLess(expected, actual)
// assertMore(expected, actual)
// assertLessOrEqual(expected, actual)
// assertMoreOrEqual(expected, actual)
// assertTrue(actual)
// assertFalse(actual)
// assertNull(actual)
#include <ArduinoUnitTests.h>
#include "Arduino.h"
#include "Servo.h"
#include "PERIPUMP.h"
#define pumpPin 5
unittest_setup()
{
fprintf(stderr, "PERIPUMP_LIB_VERSION: %s\n", (char *) PERIPUMP_LIB_VERSION);
}
unittest_teardown()
{
}
unittest(test_percentage)
{
PERIPUMP pump(5);
pump.begin();
assertEqual(0, pump.getPercentage(), 1);
pump.stop();
assertEqual(0, pump.getPercentage(), 1);
for (int pos = -100; pos <= 100; pos += 10)
{
pump.setPercentage(pos);
assertEqual(pos, pump.getPercentage(), 1);
}
pump.stop();
assertEqual(0, pump.getPercentage(), 1);
}
unittest_main()
// -- END OF FILE --