Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **Sensor Measurement**
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-01-22 14:27:23
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* serial print output with errors */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <DS18B20.h> //https://github.com/matmunk/DS18B20
- #include <LoadCell.h> // Assuming LoadCell library is needed for LoadCell.update() and LoadCell.getData()
- #include <Arduino.h> // Required for Arduino functions like Serial
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void temp_density_me(void *pvParameters); // Prototype for the new function
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Assuming LoadCell and other necessary instances are defined here
- LoadCell LoadCell; // Uncomment and configure as necessary
- SemaphoreHandle_t mutex; // Uncomment if using FreeRTOS semaphores
- void setup(void)
- {
- // put your setup code here, to run once:
- Serial.begin(115200); // Initialize serial communication
- // Initialize LoadCell and other necessary components here
- if (!LoadCell.begin()) {
- Serial.println("Error: LoadCell initialization failed!");
- }
- // LoadCell.begin(); // Uncomment and configure as necessary
- // xSemaphoreCreateMutex(); // Uncomment if using FreeRTOS semaphores
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- // You might want to create a task for temperature and density measurement
- // xTaskCreate(temp_density_me, "TempDensityTask", 2048, NULL, 1, NULL); // Uncomment and configure as necessary
- }
- /****** TEMPERATURE AND DENSITY MEASUREMENT FUNCTION *****/
- void temp_density_me(void *pvParameters) {
- // temperature and density measurement
- static boolean newDataReady = 0;
- for (;;) {
- if (xSemaphoreTake(mutex, portMAX_DELAY) == pdTRUE) { // check for new data/start next conversion:
- if (LoadCell.update()) {
- newDataReady = true; // get smoothed value from the dataset:
- } else {
- Serial.println("Error: LoadCell update failed!");
- }
- if (newDataReady) {
- float i = LoadCell.getData();
- sensors.requestTemperatures();
- float temperature_Celsius = sensors.getTempCByIndex(0);
- if (temperature_Celsius == DEVICE_DISCONNECTED) {
- Serial.println("Error: Temperature sensor disconnected!");
- } else {
- float iSG = (i / (258.6 - ((i / 258.2) * 227.1))) + 1; // convert measured Plato to SG
- float iRSG = iSG / (1 + kt * (ti - temperature_Celsius)); // real density SG
- float iR = (((182.4601 * iRSG - 775.6821) * iRSG + 1262.7794) * iRSG - 669.5622); // real density Plato
- Serial.print("Плотность измеренная: ");
- Serial.print(i);
- Serial.print(" %");
- Serial.print(" ");
- Serial.print(iSG, 5);
- Serial.print(" ");
- Serial.println(iRSG, 5);
- Serial.print("Плотность скорректированная: ");
- Serial.print(iR, 2);
- Serial.println(" %");
- Serial.print("Температура: ");
- Serial.print(temperature_Celsius);
- Serial.println(" C");
- Serial.println();
- }
- newDataReady = 0;
- }
- xSemaphoreGive(mutex);
- } else {
- Serial.println("Error: Failed to take semaphore!");
- }
- vTaskDelay(5000);
- }
- vTaskDelete(NULL);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement