Stránka 1 z 1
Wiring - příkaz scale
Napsal: 04 led 2018, 18:34
od Axamith
Snažím se něco spatlat na poli vážení, AD převodník HX711, tenzometr ... Prošel jsem dost kalibračních sketchí, jako velmi podařená se mi jeví
https://learn.sparkfun.com/tutorials/lo ... 1492100024
Kód: Vybrat vše
Arduino pin 2 -> HX711 CLK
3 -> DOUT
5V -> VCC
GND -> GND
*/
#include "HX711.h"
#define DOUT 3
#define CLK 2
HX711 scale(DOUT, CLK);
float calibration_factor = -7050; //-7050 worked for my 440lb max scale setup
void setup() {
Serial.begin(9600);
Serial.println("HX711 calibration sketch");
Serial.println("Remove all weight from scale");
Serial.println("After readings begin, place known weight on scale");
Serial.println("Press + or a to increase calibration factor");
Serial.println("Press - or z to decrease calibration factor");
scale.set_scale();
scale.tare(); //Reset the scale to 0
long zero_factor = scale.read_average(); //Get a baseline reading
Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
Serial.println(zero_factor);
}
void loop() {
scale.set_scale(calibration_factor); //Adjust to this calibration factor
Serial.print("Reading: ");
Serial.print(scale.get_units(), 1);
Serial.print(" lbs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();
if(Serial.available())
{
char temp = Serial.read();
if(temp == '+' || temp == 'a')
calibration_factor += 10;
else if(temp == '-' || temp == 'z')
calibration_factor -= 10;
}
}
Narazil jsem zde na příkaz
Je mi jasné, že jde o nastavení měřítka. V kódu je použitý v různých formách zadání (výběr příkazů z kódu):
Kód: Vybrat vše
HX711 scale(DOUT, CLK);
scale.set_scale();
scale.tare();
long zero_factor = scale.read_average();
scale.set_scale(calibration_factor);
Serial.print(scale.get_units(), 1);
Snažil jsem se funkci kódu pochopit a hledal jsem nějaké bližší informace o tomto příkazu, formu zadání, použití, parametry ... Nikde nic rozumného jsem nenašel. Máte někdo s ním zkušenost?
Re: Wiring - příkaz scale
Napsal: 04 led 2018, 19:15
od pavel1tu
to patří ke knihovně, tam to na github není popsané ?
Re: Wiring - příkaz scale
Napsal: 04 led 2018, 20:21
od ohruska
Mám použit tento kód:
Kód: Vybrat vše
#include "HX711.h"
// HX711.DOUT - pin #A1
// HX711.PD_SCK - pin #A0
HX711 scale(A1, A0); // parameter "gain" is ommited; the default value 128 is used by the library
void setup() {
Serial.begin(57600);
Serial.println("HX711 Demo");
Serial.println("Before setting up the scale:");
Serial.print("read: \t\t");
Serial.println(scale.read()); // print a raw reading from the ADC
Serial.print("read average: \t\t");
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
Serial.print("get value: \t\t");
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet)
Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided
// by the SCALE parameter (not set yet)
scale.set_scale(2280.f); // this value is obtained by calibrating the scale with known weights; see the README for details
scale.tare(); // reset the scale to 0
Serial.println("After setting up the scale:");
Serial.print("read: \t\t");
Serial.println(scale.read()); // print a raw reading from the ADC
Serial.print("read average: \t\t");
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
Serial.print("get value: \t\t");
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare()
Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided
// by the SCALE parameter set with set_scale
Serial.println("Readings:");
}
void loop() {
// Serial.print("one reading:\t");
// Serial.print('H');
// Serial.print(',');
Serial.print(scale.get_units()/100, 4);
// Serial.print("\t| average:\t");
// Serial.println(scale.get_units(2), 1);
Serial.println();
// scale.power_down(); // put the ADC in sleep mode
delay(100);
// scale.power_up();
}
Jediné co jsem udělal, tak jsem změnil hodnotu 2280 v kódu, tak aby odpovídala měřená hmotnost, podle použitého tenzometru.
Re: Wiring - příkaz scale
Napsal: 04 led 2018, 22:12
od martinius96
Ahoj, toto som robil pre jeden obchod s Arduinom + Ethernet shieldom. Vytiahni si, čo potrebuješ:
Kód: Vybrat vše
#include "HX711.h"
#include <Ethernet.h>
#include <SPI.h>
#define Hostname "Arduino" //Meno arduina v siti
byte mac[] = { 0xAA, 0xBB, 0xAA, 0xBB, 0xAA, 0xBB }; //MAC ADRESA ARDUINA --> VOLITELNA
char server[] = "www.web.cz"; //ADRESA WEBSERVERA (MOZE BYT AJ IP ADRESA)
IPAddress ip(10, 0, 0, 151); //IP ADRESA ZARIADENIA V SIETI V LOKALNEJ SIETI
EthernetClient client; //SPUSTENIE ETHERNETU AKO CLIENTA
HX711 scale (A2, A3); //definovane piny pre cip HX711
int led1 = 5;
int led2 = 4;
int led3 = 3;
int led4 = 2;
int PRETIZENI = 4000;
int PRAZDNY = 10;
double momentalnahodnota=0;
double predchadzajucahodnota=0;
int rozdiel=0;
unsigned long pocitadlo= 0;
void setup()
{
Serial.begin(9600);
scale.set_scale(300.f);
scale.tare(); // NASTAVI VAHU NA 0
pinMode (led1, OUTPUT);
pinMode (led2, OUTPUT);
pinMode (led3, OUTPUT);
pinMode (led4, OUTPUT);
}
void resetdiod(){
digitalWrite (led1, LOW);
digitalWrite (led2, LOW);
digitalWrite (led3, LOW);
digitalWrite (led4, LOW);
}
void loop()
{
if(pocitadlo < 1){
momentalnahodnota = scale.get_units();
if(0<= momentalnahodnota && momentalnahodnota <= 5 || 0>= momentalnahodnota && momentalnahodnota >= -5){
scale.tare();
momentalnahodnota=0;}
predchadzajucahodnota = scale.get_units();
pocitadlo++;
delay(3000);
}else{
if (Ethernet.begin(mac) == 0) {
Serial.println("Chyba konfiguracie cez DHCP"); //SERIOVY VYPIS CHYBY KONFIGURACIE DHCP
Ethernet.begin(mac, ip); //NASTAVENIE IP A MAC ADRESY PRE ETHERNET MODUL
}
momentalnahodnota = scale.get_units();
if(0<= momentalnahodnota && momentalnahodnota <= 5 || 0>= momentalnahodnota && momentalnahodnota >= -5){
scale.tare();
momentalnahodnota=0;}
rozdiel = (momentalnahodnota - predchadzajucahodnota);
if (rozdiel > 30){
if (rozdiel > 50){
Serial.println("Pridani vice polozek");
if (client.connect(server, 80)) {
client.print("GET /pridanivicepolozek.php?momentalnahodnota=");
client.print(momentalnahodnota);
client.print("&predchadzajucahodnota=");
client.print(predchadzajucahodnota);
client.print("&rozdiel=");
client.print(rozdiel);
client.print("&stav=Pridani%20vice%20polozek");
client.println(" HTTP/1.1");
client.println("Host: www.web.php5.cz");
client.println("Connection: close");
client.println();
client.stop();
}
}
else{
Serial.println("Pridani polozky");
if (client.connect(server, 80)) {
client.print("GET /pridanipolozky.php?momentalnahodnota=");
client.print(momentalnahodnota);
client.print("&predchadzajucahodnota=");
client.print(predchadzajucahodnota);
client.print("&rozdiel=");
client.print(rozdiel);
client.print("&stav=Pridani%20polozky");
client.println(" HTTP/1.1");
client.println("Host: www.web.php5.cz");
client.println("Connection: close");
client.println();
client.stop();
}
}}
if (rozdiel < -30){
if (rozdiel < -50){
digitalWrite (led4, HIGH);
Serial.println("Pozor - odebrání více položek");
if (client.connect(server, 80)) {
client.print("GET /odebranivicepolozek.php?momentalnahodnota=");
client.print(momentalnahodnota);
client.print("&predchadzajucahodnota=");
client.print(predchadzajucahodnota);
client.print("&rozdiel=");
client.print(rozdiel);
client.print("&stav=Pozor%20odebrani%20vice%20polozek");
client.println(" HTTP/1.1");
client.println("Host: www.webs.php5.cz");
client.println("Connection: close");
client.println();
client.stop();
}
}else{
Serial.println("Odebrani polozky");
digitalWrite (led3, HIGH);
if (client.connect(server, 80)) {
client.print("GET /odebranipolozky.php?momentalnahodnota=");
client.print(momentalnahodnota);
client.print("&predchadzajucahodnota=");
client.print(predchadzajucahodnota);
client.print("&rozdiel=");
client.print(rozdiel);
client.print("&stav=Odebrani%20polozky");
client.println(" HTTP/1.1");
client.println("Host: www.dsfsdf.php5.cz");
client.println("Connection: close");
client.println();
client.stop();
}}
}
if (momentalnahodnota < PRAZDNY) {
Serial.println("Prazdny regal");
digitalWrite (led1, HIGH);
delay(350);
digitalWrite (led1, LOW);
delay(350);
if (client.connect(server, 80)) {
client.print("GET /prazdnyregal.php?momentalnahodnota=");
client.print(momentalnahodnota);
client.print("&predchadzajucahodnota=");
client.print(predchadzajucahodnota);
client.print("&rozdiel=");
client.print(rozdiel);
client.print("&stav=Prazdny%20regal");
client.println(" HTTP/1.1");
client.println("Host: www.shelfgdssdfdsfuard.php5.cz");
client.println("Connection: close");
client.println();
client.stop();
}
}
if (momentalnahodnota > PRETIZENI) {
Serial.println("Pretizeny regal");
digitalWrite (led2, HIGH);
if (client.connect(server, 80)) {
client.print("GET /pretizenyregal.php?momentalnahodnota=");
client.print(momentalnahodnota);
client.print("&predchadzajucahodnota=");
client.print(predchadzajucahodnota);
client.print("&rozdiel=");
client.print(rozdiel);
client.print("&stav=Pretizeny%20regal");
client.println(" HTTP/1.1");
client.println("Host: www.dsfdsf.php5.cz");
client.println("Connection: close");
client.println();
client.stop();
} else {
Serial.println("Pripojenie zlyhalo"); //SERIOVY VYPIS O NEUSPESNOSTI PRIPOJENIA
}
}
if(pocitadlo>=150){
if (momentalnahodnota > PRETIZENI) {
if (client.connect(server, 80)) {
client.print("GET /reference.php?momentalnahodnota=");
client.print(momentalnahodnota);
client.print("&stav=Pretizeny%20regal");
client.println(" HTTP/1.1");
client.println("Host: www.fdsf.php5.cz");
client.println("Connection: close");
client.println();
client.stop();
}
}
if (momentalnahodnota < PRAZDNY) {
Serial.println("Prazdny regal");
digitalWrite (led1, HIGH);
delay(350);
digitalWrite (led1, LOW);
delay(350);
if (client.connect(server, 80)) {
client.print("GET /reference.php?momentalnahodnota=");
client.print(momentalnahodnota);
client.print("&stav=Prazdny%20regal");
client.println(" HTTP/1.1");
client.println("Host: www.sdfdfdf.php5.cz");
client.println("Connection: close");
client.println();
client.stop();
}
}
if (rozdiel < -30){
if (rozdiel < -50){
digitalWrite (led4, HIGH);
Serial.println("Pozor - odebrání více položek");
if (client.connect(server, 80)) {
client.print("GET /reference.php?momentalnahodnota=");
client.print(momentalnahodnota);
client.print("&stav=Pozor%20odebrani%20vice%20polozek");
client.println(" HTTP/1.1");
client.println("Host: www.dsfdsfds.php5.cz");
client.println("Connection: close");
client.println();
client.stop();
}
}else{
Serial.println("Odebrani polozky");
digitalWrite (led3, HIGH);
if (client.connect(server, 80)) {
client.print("GET /reference.php?momentalnahodnota=");
client.print(momentalnahodnota);
client.print("&stav=Odebrani%20polozky");
client.println(" HTTP/1.1");
client.println("Host: www.aaaa.php5.cz");
client.println("Connection: close");
client.println();
client.stop();
}}
}
if (rozdiel > 30){
if (rozdiel > 50){
Serial.println("Pridani vice polozek");
if (client.connect(server, 80)) {
client.print("GET /reference.php?momentalnahodnota=");
client.print(momentalnahodnota);
client.print("&stav=Pridani%20vice%20polozek");
client.println(" HTTP/1.1");
client.println("Host: www.abc.php5.cz");
client.println("Connection: close");
client.println();
client.stop();
}
}
else{
Serial.println("Pridani polozky");
if (client.connect(server, 80)) {
client.print("GET /reference.php?momentalnahodnota=");
client.print(momentalnahodnota);
client.print("&stav=Pridani%20polozky");
client.println(" HTTP/1.1");
client.println("Host: www.host.php5.cz");
client.println("Connection: close");
client.println();
client.stop();
}
}}
pocitadlo=1;
}
predchadzajucahodnota = scale.get_units();
if(0<= predchadzajucahodnota && predchadzajucahodnota <= 5 || 0>= predchadzajucahodnota && predchadzajucahodnota >= -5){
scale.tare();
predchadzajucahodnota=0;}
delay(4000); //pockame 6 sekund pred novym meranim vahy
resetdiod(); //vypneme vsetky ledky pred novym meranim, aby bol ich stav aktualny
pocitadlo++;
}
}}
Re: Wiring - příkaz scale
Napsal: 05 led 2018, 08:13
od Axamith
pavel1tu píše: ↑04 led 2018, 19:15
to patří ke knihovně, tam to na github není popsané ?
Mohl bych poprosit o ještě větší nakopnutí? Jaké konkrétní knihovny? Asi na Githubu neumím hledat, nic konkrétního jsem nenašel.
Proč to vlastně potřebuji, napadlo udělal autokalibrační sketch.
Mám vstupní veličiny:
- základní kalibrační konstantu (Kt)
- krok kalibrační konstanty (Kx)
- aktuálně naměřenou hmotnost (X)
- požadovanou kalibrační hmotnost (0)
Podmínkou by šlo nechat dopočítávat kalibrační konstatntu.
Je-li měření větší než nula, Kt=Kt+Kx, následně proveď další porovnání výpočtu ve smyčce. Směr výpočtu (+ nebo -) by určila předešlá podmínka, která by analyzovala kladnou nebo zápornou hodnotu měření. Už jsem se díval na nějaké podmínky a vzorce, mělo by to fungovat. A výsledek uložit do EEprom přes knihovnu EEproMex, takže kalibrační koeficient by byl dostupný bez zásahu do sketche.
Možná je to blbost, ale chtěl jsem to zkusit, tak jsem si našel nějakou funkční kalibraci a procházel detaily kódu, nějak jsem ale nepochopil práci s příkazem scale, respektice rozumím, k čemu ve sketchi je, ale nevím, jaké má možnosti, detaily práce s ním. Rád věci chápu, nechci se jen spokojit s tím, že něco funguje.
Re: Wiring - příkaz scale
Napsal: 12 led 2018, 16:52
od jankop
Nejsem expertem přes knihovny, ale ten tvůj scale je podle mě prostě funkcí (metodou?) knihovny HX711.h, kterou vkládáš. Tak se do ní podívej, prostuduj případné examples a projdi si její soubory *.h a *.cpp to by ti mělo poskytnout dostatečný obraz.