Waga tensometryczna

Masz pomysł na funkcjonalność lub koncepcję na rozwój projektu. Opisz wszystko tutaj.
Awatar użytkownika
QLQ
Posty: 2276
Rejestracja: ndz wrz 03, 2017 9:13 am
Lokalizacja: Koszalin

Dobra to zrobię coś dla nas i naszych 2-gich połówek. Z oled oczywiście. Tak myślę aby schować to w łazience pod terakotą w podłodze a oled w lustrze. Już to ktoś z kolegów zrobił z tym lustrem ale nie pamiętam kto...fajnie wyglądało i prfeska w 100%.
jak coś nie działa to włącz zasilanie.....
Awatar użytkownika
lesny8
Posty: 2808
Rejestracja: pn gru 11, 2017 9:43 pm

Może o tym myślisz?
Czekam na kolejne Supla Offline Party 👍
Awatar użytkownika
QLQ
Posty: 2276
Rejestracja: ndz wrz 03, 2017 9:13 am
Lokalizacja: Koszalin

lesny8 pisze: ndz cze 16, 2019 10:07 pm Może o tym myślisz?
Tak to to. Kolega @Michael zrobił kawał roboty.
jak coś nie działa to włącz zasilanie.....
Awatar użytkownika
QLQ
Posty: 2276
Rejestracja: ndz wrz 03, 2017 9:13 am
Lokalizacja: Koszalin

Projekt zrealizowany. Poniżej filmik.

https://youtu.be/3bsao7FcjK4

Pod Filmem kod źródłowy - proszę nie mieć za złe - bo to tak na szybko przerobione z stacji pogody i innych. Oparte na kodzie shimano73 z BME280.
VideoCapture_20190621-142646.jpg
VideoCapture_20190621-142646.jpg (44.7 KiB) Przejrzano 3905 razy
KOD do kalibracji wagi (opis kalibracji w kodzie)
.

Kod: Zaznacz cały

/*
 Example using the SparkFun HX711 breakout board with a scale
 By: Nathan Seidle
 SparkFun Electronics
 Date: November 19th, 2014
 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

 This is the calibration sketch. Use it to determine the calibration_factor that the main example uses. It also
 outputs the zero_factor useful for projects that have a permanent mass on the scale in between power cycles.

 Setup your scale and start the sketch WITHOUT a weight on the scale
 Once readings are displayed place the weight on the scale
 Press +/- or a/z to adjust the calibration_factor until the output readings match the known weight
 Use this calibration_factor on the example sketch

 This example assumes pounds (lbs). If you prefer kilograms, change the Serial.print(" lbs"); line to kg. The
 calibration factor will be significantly different but it will be linearly related to lbs (1 lbs = 0.453592 kg).

 Your calibration factor may be very positive or very negative. It all depends on the setup of your scale system
 and the direction the sensors deflect from zero state
 This example code uses bogde's excellent library: https://github.com/bogde/HX711
 bogde's library is released under a GNU GENERAL PUBLIC LICENSE
 Arduino pin 2 -> HX711 CLK
 3 -> DOUT
 5V -> VCC
 GND -> GND

 Most any pin on the Arduino Uno will be compatible with DOUT/CLK.

 The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.

*/

#include "HX711.h"

#define DOUT  3
#define CLK  2

HX711 scale;

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.begin(DOUT, CLK);
  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;
  }
}



Natomiast kod pod czujnik wagi i HX711oraz przeróbka pod oled to moje dzieło

Kod: Zaznacz cały

                                              /**
   Supla.org NodeMCU WiFi minimal example
   Author: Programistyk - Kamil Kaminski <kamil@programistyk.pl>

   This example shows how to configure SuplaDevice for building for NodeMCU within Arduino IDE
*/
#define LIGHTSENSORPIN A0 //Ambient light sensor reading
#include <BH1750FVI.h>
#include <srpc.h>
#include <log.h>
#include <eh.h>
#include <proto.h>
#include <IEEE754tools.h>
// We define our own ethernet layer
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>
#include <lck.h>

#include <WiFiClient.h>
#include <ESP8266WiFiType.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiServer.h>
#include <ESP8266WiFiGeneric.h>
#include <WiFiClientSecure.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiSTA.h>
#include <WiFiUdp.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define OLED_RESET 0
Adafruit_SSD1306 display(OLED_RESET); // GPIO5 - SCL , GPIO4 -SDA
#include "HX711.h"
#define calibration_factor -24160.0 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define DOUT  12
#define CLK  14

HX711 scale;
String light;


#define SEALEVELPRESSURE_HPA (1023.0)

Adafruit_BME280 bme; // I2C

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2

BH1750FVI LightSensor(BH1750FVI::k_DevModeContLowRes);
#define LOGO32_GLCD_HEIGHT 32
#define LOGO32_GLCD_WIDTH  32
static const unsigned char PROGMEM temp_glcd_bmp[] =
{ // temp_home
  0x00, 0x03, 0xc0, 0x00, 0x00, 0x04, 0x20, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x50, 0x00, 
  0x00, 0x08, 0x50, 0x00, 0x00, 0x08, 0x50, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x09, 0x50, 0x00, 
  0x00, 0x08, 0xd0, 0x00, 0x00, 0x0b, 0x10, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 
  0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 
  0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 
  0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x17, 0xe8, 0x00, 
  0x00, 0x2f, 0xf4, 0x00, 0x00, 0x2f, 0x94, 0x00, 0x00, 0x2f, 0xb4, 0x00, 0x00, 0x2f, 0xf4, 0x00, 
  0x00, 0x07, 0xe0, 0x00, 0x00, 0x13, 0xc8, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x03, 0xc0, 0x00
};



static const unsigned char PROGMEM pressure_glcd_bmp[] =
{
  // 'pressure'
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 
  0x01, 0xc1, 0xc1, 0xf8, 0x03, 0xc3, 0xc1, 0xf8, 0x03, 0x83, 0x81, 0xf8, 0x03, 0x03, 0x00, 0x18, 
  0x07, 0x07, 0x00, 0x18, 0x07, 0x07, 0x00, 0xf8, 0x07, 0x07, 0x00, 0xf8, 0x07, 0x07, 0x00, 0xf8, 
  0x07, 0x07, 0x00, 0x18, 0x03, 0x03, 0x00, 0x18, 0x03, 0x83, 0x80, 0x18, 0x03, 0x83, 0x81, 0xf8, 
  0x03, 0x83, 0x81, 0xf8, 0x03, 0x83, 0x80, 0x18, 0x01, 0x81, 0x80, 0x18, 0x01, 0x81, 0x80, 0x18, 
  0x03, 0x83, 0x80, 0xf8, 0x03, 0x83, 0x80, 0xf8, 0x03, 0x83, 0x80, 0xf8, 0x13, 0x93, 0x80, 0x18, 
  0x1f, 0x1f, 0x00, 0x18, 0x1f, 0x1f, 0x01, 0xf8, 0x1e, 0x1e, 0x01, 0xf8, 0x1f, 0x1f, 0x01, 0xf8, 
  0x1f, 0x9f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

static const unsigned char PROGMEM waga_glcd_bmp[] =
{

 0x00,0x00,0x80,0x00, // ········▌·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x3F,0xFF,0xFF,0xFC, // ·██████████████·
  0x3F,0xFF,0xFF,0xFE, // ·██████████████▌
  0x3F,0xFF,0xFF,0xFE, // ·██████████████▌
  0x07,0x81,0xC0,0xF0, // ··▐█▌··▐█···██··
  0x07,0x81,0x80,0xF0, // ··▐█▌··▐▌···██··
  0x0F,0xC1,0xC1,0xF8, // ··███··▐█··▐██▌·
  0x1C,0xC1,0xC1,0x98, // ·▐█·█··▐█··▐▌▐▌·
  0x18,0xE1,0xC3,0x8C, // ·▐▌·█▌·▐█··█▌·█·
  0x38,0x61,0xC3,0x0E, // ·█▌·▐▌·▐█··█··█▌
  0x30,0x71,0xC7,0x06, // ·█··▐█·▐█·▐█··▐▌
  0xFF,0xF9,0xCF,0xFF, // ██████▌▐█·██████
  0xFF,0xF9,0xCF,0xFF, // ██████▌▐█·██████
  0xFF,0xF9,0xCF,0xFF, // ██████▌▐█·██████
  0x7F,0xF9,0xCF,0xFF, // ▐█████▌▐█·██████
  0x3F,0xF1,0xC7,0xFE, // ·█████·▐█·▐████▌
  0x3F,0xE1,0xC3,0xFE, // ·████▌·▐█··████▌
  0x0F,0xC1,0xC1,0xF8, // ··███··▐█··▐██▌·
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0x80,0x00, // ·······▐▌·······
  0x00,0x1F,0xFC,0x00, // ·····▐█████·····
  0x00,0x3F,0xFE,0x00, // ·····██████▌····
  0x00,0x3F,0xFE,0x00, // ·····██████▌····
  0x00,0x3F,0xFE,0x00, // ·····██████▌····
  0x00,0x1F,0xFC,0x00, // ·····▐█████·····
  0x00,0x00,0x00,0x00  // ················
};

static const unsigned char PROGMEM rain_glcd_bmp[] = 
{
0x00,0x00,0x00,0x00, // ················
  0x00,0x00,0x00,0x00, // ················
  0x00,0x00,0x00,0x00, // ················
  0x00,0x00,0x00,0x00, // ················
  0x00,0x00,0x00,0x00, // ················
  0x00,0x00,0x00,0x00, // ················
  0x00,0x00,0x00,0x00, // ················
  0x00,0x00,0x00,0x00, // ················
  0x00,0x00,0x00,0x00, // ················
  0x00,0x00,0x00,0x00, // ················
  0x00,0xF3,0xE0,0x00, // ····██·██▌······
  0x01,0x8E,0x18,0x00, // ···▐▌·█▌·▐▌·····
  0x03,0x0C,0x08,0x00, // ···█··█···▌·····
  0x04,0x38,0x0F,0x00, // ··▐··█▌···██····
  0x08,0x28,0x11,0x80, // ··▌··▌▌··▐·▐▌···
  0x10,0x40,0x00,0xC0, // ·▐··▐·······█···
  0x10,0x80,0x00,0x40, // ·▐··▌·······▐···
  0x0F,0x00,0x00,0x40, // ··██········▐···
  0x01,0x00,0x00,0x40, // ···▐········▐···
  0x01,0x00,0x00,0x80, // ···▐········▌···
  0x00,0xFF,0xFF,0x00, // ····████████····
  0x00,0x14,0x96,0x00, // ·····▐▐·▌▐▐▌····
  0x00,0x24,0xA4,0x00, // ·····▌▐·▌▌▐·····
  0x00,0x21,0x0C,0x00, // ·····▌·▐··█·····
  0x00,0x40,0x08,0x00, // ····▐·····▌·····
  0x00,0x10,0x80,0x00, // ·····▐··▌·······
  0x00,0x10,0x80,0x00, // ·····▐··▌·······
  0x00,0x00,0x00,0x00, // ················
  0x00,0x00,0x00,0x00, // ················
  0x00,0x00,0x00,0x00, // ················
  0x00,0x00,0x00,0x00, // ················
  0x00,0x00,0x00,0x00  // ················
};

static const unsigned char PROGMEM lux_glcd_bmp[] =
{


0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0xC1,0xC1,0x80, // ····█··▐█··▐▌···
  0x00,0xE1,0xC3,0x80, // ····█▌·▐█··█▌···
  0x00,0x71,0xC7,0x00, // ····▐█·▐█·▐█····
  0x00,0x70,0x87,0x00, // ····▐█··▌·▐█····
  0x00,0x30,0x06,0x00, // ·····█····▐▌····
  0x18,0x07,0xF0,0x0C, // ·▐▌···▐███····█·
  0x3E,0x1F,0xF8,0x3C, // ·██▌·▐████▌··██·
  0x1F,0x3F,0x7E,0x78, // ·▐██·███▐██▌▐█▌·
  0x07,0x78,0x0E,0x70, // ··▐█▐█▌···█▌▐█··
  0x00,0x70,0x07,0x00, // ····▐█····▐█····
  0x00,0xE0,0x03,0x80, // ····█▌·····█▌···
  0x00,0xE0,0x03,0x80, // ····█▌·····█▌···
  0x7C,0xC0,0x03,0x9F, // ▐██·█······█▌▐██
  0xFE,0xC0,0x01,0xBF, // ███▌█······▐▌███
  0x7C,0xC0,0x01,0x9F, // ▐██·█······▐▌▐██
  0x00,0xE0,0x03,0x80, // ····█▌·····█▌···
  0x00,0xE0,0x03,0x80, // ····█▌·····█▌···
  0x00,0x70,0x07,0x00, // ····▐█····▐█····
  0x07,0x78,0x0F,0x70, // ··▐█▐█▌···██▐█··
  0x0F,0x3E,0x3E,0x78, // ··██·██▌·██▌▐█▌·
  0x1E,0x1F,0xFC,0x3C, // ·▐█▌·▐█████··██·
  0x18,0x07,0xF0,0x0C, // ·▐▌···▐███····█·
  0x00,0x30,0x06,0x00, // ·····█····▐▌····
  0x00,0x70,0x87,0x00, // ····▐█··▌·▐█····
  0x00,0x71,0xC7,0x00, // ····▐█·▐█·▐█····
  0x00,0xE1,0xC3,0x80, // ····█▌·▐█··█▌···
  0x00,0xC1,0xC3,0x80, // ····█··▐█··█▌···
  0x00,0x01,0xC1,0x00, // ·······▐█··▐····
  0x00,0x01,0xC0,0x00, // ·······▐█·······
  0x00,0x00,0x80,0x00  // ········▌·······
};

static const unsigned char PROGMEM logo32_glcd_bmp[] =
{
  // 'logo SUPLA'
  0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00,
  0x0e, 0x0e, 0x00, 0x00, 0x0c, 0x06, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00,
  0x1c, 0x03, 0x00, 0x00, 0x0c, 0x07, 0x00, 0x00, 0x0e, 0x0f, 0x80, 0x00, 0x07, 0xfc, 0xe0, 0x00,
  0x03, 0xf8, 0x30, 0x00, 0x00, 0xf0, 0x0d, 0xe0, 0x00, 0x10, 0x07, 0x30, 0x00, 0x18, 0x02, 0x10,
  0x00, 0x18, 0x06, 0x18, 0x00, 0x08, 0x02, 0x10, 0x00, 0x08, 0x03, 0xf0, 0x00, 0x0c, 0x07, 0xc0,
  0x00, 0x04, 0x0c, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00,
  0x00, 0x03, 0xc0, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x00, 0x0c, 0x20, 0x00,
  0x00, 0x04, 0x40, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const unsigned char PROGMEM ASL_glcd_bmp[] =
{
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 
  0x00, 0x00, 0x60, 0x00, 0x00, 0x08, 0x21, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, 0x00, 0x62, 0x00, 
  0x00, 0x1f, 0xf8, 0x00, 0x00, 0x3f, 0x0c, 0x00, 0x00, 0x61, 0x84, 0x00, 0x00, 0xc0, 0xc4, 0xe0, 
  0x01, 0xc0, 0xf4, 0x00, 0x03, 0x00, 0x1c, 0x00, 0x06, 0x00, 0x0c, 0x00, 0x06, 0x00, 0x0c, 0x00, 
  0x06, 0x10, 0xcd, 0x00, 0x03, 0x10, 0x99, 0x00, 0x01, 0x84, 0x30, 0x00, 0x00, 0x25, 0x00, 0x00, 
  0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
  };

char* Message[] = {"This is string 1",
                   "Already initialized",
                   "Cb not assigned",
                   "Invalid GUID",
                   "Unknown server address",
                   "Unknow location ID",
                   "Initialized",
                   "Channel limit exceeded",
                   "Rozlaczony",
                   "Rejstracja w toku",
                   "Iterate fail",
                   "Protocol version error",
                   "Bad credentials",
                   "Temporarily unawaliable",
                   "Location conflict",
                   "Channel conflict",
                   "Polaczony i gotowy",
                   "Device is diasbled",
                   "Location is disabled",
                   "Device limit execeeded"
                  };



#if (SSD1306_LCDHEIGHT != 64)
//#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

// ***** logowanie WiFi ********************************************************************************
WiFiClient client;

// Setup Supla connection
const char* ssid     = "xxx";
const char* password = "xxxxxx";

char str[10];
char StatCommStr[25];
int StatCommInt;
byte Icon;
byte FiveSek;



/*
//// ******* BME280 Temperatura i wilgotnosc *********************************

void get_temperature_and_humidity (int channelNumber, double *temp, double *humidity){
  
    *temp = bme.readTemperature();
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" *C");

  
    *humidity = bme.readHumidity();
    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity());               // wyremowane dla BMP280   
    Serial.println(" %");
    if ( isnan(*temp) || isnan(*humidity) ) {
      *temp = -275;
      *humidity = -1;
    }

  }
///***********DESZCZ*******************************************************
double get_rain(int channelNumber, double rain) {
   
 rain = 10;
    Serial.print("Rain = ");
    Serial.print(rain);
    Serial.println(" mm");
   return  rain; 

   
}



//// ******* Ciśnienie *****************************************************  
double get_pressure(int channelNumber, double pressure) {
   
 pressure = bme.readPressure() / 100.0F;
    Serial.print("Pressure = ");
    Serial.print(bme.readPressure()/100);
    Serial.println(" hPa");
   return  pressure; 

   
}

////******* Natężenie zrobione obsługą czujnika odległości

double get_distance(int channelNumber, double t) {

 // float lux = analogRead(LIGHTSENSORPIN);             //TEMT6000
   double lux = LightSensor.GetLightIntensity();     //BH1750
    t = abs(lux);
    Serial.print("Natezenie swiatla = ");
    Serial.print(LightSensor.GetLightIntensity());
    delay(1250);
    return t;

}
*/

double get_weight(int channelNumber, double t) {

 
   double lux = (scale.get_units()*1000);    
    t = abs(lux);
    Serial.print("Twoja waga= ");
    Serial.print(scale.get_units());
    Serial.print(" kg");
    delay(1250);
    return t;
    }

void timer0_ISR (void) {
  FiveSek++;
  if (FiveSek==2) {
    FiveSek=0;
    Icon++;
    if (Icon==3) Icon=1;
  }
  timer0_write(ESP.getCycleCount() + 80000000L); // 80MHz == 1sec 
}

//// ******* Funkcja główna *********************************************************************************
void setup() {
  
  Serial.begin(9600); //BH1750
  scale.begin(DOUT, CLK);
  scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale.tare(); //Assuming there is no weight on the scale at start up, 
  
   
  noInterrupts();
  timer0_isr_init();
  timer0_attachInterrupt(timer0_ISR);
  timer0_write(ESP.getCycleCount() + 80000000L); // 80MHz == 1sec
  interrupts();
 
/*  if (!bme.begin(0x76)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
    }  */

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x64)
 
  Icon = 0;

  // Clear the buffer.
  display.clearDisplay();

  // text display tests
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.setRotation(2);
  display.setCursor(30, 25);
  display.print("SUPLA");
  drawbitmap(logo32_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH);
  display.display();





  // Replace the falowing GUID
char GUID[SUPLA_GUID_SIZE] = {0x8B,0x4A,0x5B,0xB5,0x6B,0x68,0x76,0x5B,0xF5,0xEA,0x9A,0x8C,0x73,0xC6,0x38,0x1D};

  //  GUID that you can retrieve from https://www.supla.org/arduino/get-guid

  // Ethernet MAC address
  uint8_t mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

  /*
     Having your device already registered at cloud.supla.org,
     you want to change CHANNEL sequence or remove any of them,
     then you must also remove the device itself from cloud.supla.org.
     Otherwise you will get "Channel conflict!" error.
  */
    
          // CHANNEL0 
            SuplaDevice.addWeightSensor(); //wagi czujnik
          //  SuplaDevice.addDHT22(); // ten objekt jest tylko po to aby w aplikacji wyświetlic temp i wilgotnosc
	        //  SuplaDevice.addDistanceSensor(); // ten obiekt wyswietla natezenie niestety bez jednostek (LUX)
	       //   SuplaDevice.addPressureSensor();  // cisnienie
 
     

  

  SuplaDevice.setName("R@F_Waga");
  SuplaDevice.setStatusFuncImpl(&status_func);

  SuplaDevice.begin(GUID,              // Global Unique Identifier
                    mac,               // Ethernet MAC address
                    "svrX.supla.org",  // SUPLA server address
                    111,                 // Location ID
                    "77777");               // Location Password

}


// ***********************************************************************************************************
void loop() {
  SuplaDevice.iterate();
  DisplayTemp();

}

// ****   Obsługa OLED    ****************************************************************************************************

void DisplayTemp() {

   double waga = scale.get_units();
double Light_Intensity = LightSensor.GetLightIntensity();
int rain=0.01;
 
  display.clearDisplay();
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.setRotation(2);
  display.setCursor(45, 25);  
 
  switch (Icon) {
      case 1:
        display.setTextSize(4);
        display.setCursor(39, 20 );  
        display.print(waga, 0);
        display.print("kg" );
        drawbitmap(waga_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH);
        
        break;
        
        case 2:
        display.setTextSize(4);
        display.setCursor(39, 20 );  
        display.print(waga, 0);
        display.print("kg" );
      
        drawbitmap(waga_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH);
        
        break;
     
    

//---------------------        
  };
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 55);
  display.print(Message[StatCommInt - 1]);
  display.display();
  display.display();

}; //DisplayTemp

void drawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  uint8_t icons[NUMFLAKES][3];

  display.drawBitmap(0, 0, bitmap, w, h, WHITE);
} //drawbitmap


// Supla.org ethernet layer
int supla_arduino_tcp_read(void *buf, int count) {
  _supla_int_t size = client.available();

  if ( size > 0 ) {
    if ( size > count ) size = count;
    return client.read((uint8_t *)buf, size);
  };

  return -1;
};

int supla_arduino_tcp_write(void *buf, int count) {
  return client.write((const uint8_t *)buf, count);
};

bool supla_arduino_svr_connect(const char *server, int port) {
  return client.connect(server, 2015);
}

bool supla_arduino_svr_connected(void) {
  return client.connected();
}

void supla_arduino_svr_disconnect(void) {
  client.stop();
}

void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) {

  // Serial.println("WiFi init");
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
        Serial.print(".");
  }

 // Serial.print("\nlocalIP: ");
 // Serial.println(WiFi.localIP());
  //Serial.print("subnetMask: ");
 // Serial.println(WiFi.subnetMask());
  //Serial.print("gatewayIP: ");
  //Serial.println(WiFi.gatewayIP());
}

SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
  SuplaDeviceCallbacks cb;

  cb.tcp_read = &supla_arduino_tcp_read;
  cb.tcp_write = &supla_arduino_tcp_write;
  cb.eth_setup = &supla_arduino_eth_setup;
  cb.svr_connected = &supla_arduino_svr_connected;
  cb.svr_connect = &supla_arduino_svr_connect;
  cb.svr_disconnect = &supla_arduino_svr_disconnect;
  cb.get_weight = get_weight;
  cb.get_temperature_and_humidity = NULL;
  cb.get_pressure = NULL; 
  cb.get_temperature = NULL;
  cb.get_rgbw_value = NULL;
  cb.set_rgbw_value = NULL;
  cb.get_distance= NULL;

  return cb;
}



void status_func(int status, const char *msg) {
  Serial.print("Status : ");
  Serial.print(status);
  StatCommInt = status;
  Serial.print(" - ");
  Serial.println(Message[StatCommInt - 1]);
  display.fillRect(0, 55, 128, 65, BLACK);

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setRotation(2);
  display.setCursor(0, 55);
  display.print(Message[StatCommInt - 1]);
  display.display();

}


Tymczasem trwa montaż aby miało ręce i nogi:
IMG_20190621_160814.jpg
IMG_20190621_160814.jpg (264.63 KiB) Przejrzano 3884 razy
Ostatnio zmieniony pt cze 21, 2019 6:36 pm przez QLQ, łącznie zmieniany 1 raz.
jak coś nie działa to włącz zasilanie.....
Awatar użytkownika
Lector
Posty: 1398
Rejestracja: pt lis 17, 2017 2:26 pm
Lokalizacja: Poznań
Kontakt:

A jakie zasilanie przewidujesz do tej wagi?
Niespełniony automatyk. :mrgreen:
https://3d-lamp.photos/
Awatar użytkownika
QLQ
Posty: 2276
Rejestracja: ndz wrz 03, 2017 9:13 am
Lokalizacja: Koszalin

Lector pisze: pt cze 21, 2019 2:26 pm A jakie zasilanie przewidujesz do tej wagi?
No tu jest jeszcze nie ogarnięte . Jakiś reaktor by się przydał. Na razie chyba zrobię z zasilacza.
Szykuje się do remontu i wagę chce ukryć jakoś przy umywalkę, wyświetlacz za lustro, a zasilanie j/W z zasilacza.
Miejsce gdzie będą tensometry też chce wrzucić czujnik zalania. Jak na razie taki plan.
jak coś nie działa to włącz zasilanie.....
Awatar użytkownika
QLQ
Posty: 2276
Rejestracja: ndz wrz 03, 2017 9:13 am
Lokalizacja: Koszalin

KONIEC PROJEKTU - TESTY DZIAłANIA NA ŻYWYM ORGANIŹMIE :D :lol:

https://youtu.be/RDsYlxqhj90

.
20190621_173613.jpg
20190621_173613.jpg (302.75 KiB) Przejrzano 3858 razy
jak coś nie działa to włącz zasilanie.....
Awatar użytkownika
lesny8
Posty: 2808
Rejestracja: pn gru 11, 2017 9:43 pm

Fajnie by było, gdyby dane z pomiarów były zapamiętywane w bazie danych. Soft musiałby też wspierać możliwość zmiany użytkowników dokonujących pomiaru, tak aby wynik zapisywał się na właściwym koncie. Można by potem pokusić się o wykres w apce i przeglądać zmiany naszej wagi :)
Czekam na kolejne Supla Offline Party 👍
Awatar użytkownika
QLQ
Posty: 2276
Rejestracja: ndz wrz 03, 2017 9:13 am
Lokalizacja: Koszalin

lesny8 pisze: sob cze 22, 2019 12:27 am Fajnie by było, gdyby dane z pomiarów były zapamiętywane w bazie danych. Soft musiałby też wspierać możliwość zmiany użytkowników dokonujących pomiaru, tak aby wynik zapisywał się na właściwym koncie. Można by potem pokusić się o wykres w apce i przeglądać zmiany naszej wagi :)
To nie na moje umiejętności.

Prosiłbym tylko jeszcze @pzygmunt aby zmniejszyć opóźnienie, czy też odświeżanie wartości w apce.
Druga rzecz o czym zawsze zapominam: pod ikonami w Cloud temp i wilgotność mają wyświetlane wartosci a ciśnienie, waga, deszcz nie. Czy można to zrobić jak dla temp i wilgotnosci? Chyba że dużo roboty to nie.
A i trzecia dziwna rzecz - jak waga wskazuje w apce 0 to miano p9trafi zmienić się z gramów na milimetry??
.
IMG_20190622_113746.jpg
IMG_20190622_113746.jpg (56.05 KiB) Przejrzano 3787 razy
jak coś nie działa to włącz zasilanie.....
Awatar użytkownika
pzygmunt
Posty: 18282
Rejestracja: wt sty 19, 2016 9:26 am
Lokalizacja: Paczków
Kontakt:

Opóźnienie zależy od urządzenia wykonawczego.
Z tymi mm to muszę sprawdzić.
ODPOWIEDZ

Wróć do „Pomysły i koncepcje”