Growing stuff and doing things

dstroy0

Zeroes and Ones
Code to read/write anything to adafruits SPI or i2c fram:

C++:
#include <Arduino.h> //type definitions
#include <Wire.h> //dependent
#include <Adafruit_FRAM_I2C.h> //dependent

Adafruit_FRAM_I2C fram = Adafruit_FRAM_I2C(); //fram object

//FRAM_writeAnything
template <class T> int FRAM_writeAnything(int ee, const T& value)
{
    const byte* p = (const byte*)(const void*)&value;
    unsigned int i;
    for (i = 0; i < sizeof(value); i++)
          fram.write8(ee++, *p++);
    return i;
}

//FRAM_readAnything
template <class T> int FRAM_readAnything(int ee, T& value)
{
    byte* p = (byte*)(void*)&value;
    unsigned int i;
    for (i = 0; i < sizeof(value); i++)
          *p++ = fram.read8(ee++);
    return i;
}

//example structure to be written/read to/from fram
struct example
{
  float one = 0.0;
  float two = 0.0;
  float three = 0.0;
};
//struct objects
example struct_written_to_fram, struct_read_from_fram;

//number of cycles
int CYCLE_ADDRESS = 0;

//address to write/read to/from
int STRUCT_FRAM_ADDRESS = 2;

void setup() {
  // put your setup code here, to run once:
  //initialize serial output
  Serial.begin(500000);
  //initialize fram
  fram.begin();
 
  //set struct members to nonzero values
  struct_written_to_fram.one = 10.0;
  struct_written_to_fram.two = 100.0;
  struct_written_to_fram.three = 1000.0;

  //write zero to CYCLE_ADDRESS
  int zero_cycles = 0;
  FRAM_writeAnything(CYCLE_ADDRESS, zero_cycles);
}

void loop() {
  // put your main code here, to run repeatedly:

  //read cycle number from fram
  int cycle = 0; //variable to read into
  FRAM_readAnything(CYCLE_ADDRESS, cycle); //read cycle number from fram

  //print cycle number
  Serial.print(F("Cycle number: "));Serial.println(cycle);
 
  //print struct info
  Serial.print(F("Size of struct to be written: "));Serial.println(sizeof(struct_written_to_fram));
  Serial.println(F("Struct member values:"));
  Serial.println(struct_written_to_fram.one);
  Serial.println(struct_written_to_fram.two);
  Serial.println(struct_written_to_fram.three);
 
  //write struct to fram
  FRAM_writeAnything(STRUCT_FRAM_ADDRESS, struct_written_to_fram);
 
  //read from fram into different struct
  FRAM_readAnything(STRUCT_FRAM_ADDRESS, struct_read_from_fram);
 
  //print different struct info
  Serial.print(F("Size of struct read: "));Serial.println(sizeof(struct_read_from_fram));
  Serial.println(struct_read_from_fram.one);
  Serial.println(struct_read_from_fram.two);
  Serial.println(struct_read_from_fram.three);

  //increment cycle, write it to fram
  cycle++;
  FRAM_writeAnything(CYCLE_ADDRESS, cycle);
 
  //wait 5 seconds
  delay(5000);
}
 

dstroy0

Zeroes and Ones
I'm using this UPS for the RPI, it has an I2C interface to the battery gauge and charge ICs.
Needs the rpi_ws281x python library, if you follow their install instructions and check on the systemd unit, you'll find the unit fails because it didn't install this dependency.

1598448468331.png

Still has a couple issues but it charges/discharges and safe shutdown works.

1598448616156.png
 

dstroy0

Zeroes and Ones
I figured out how get rid of a bunch of lines of code and be pretty explicit with what's happening still so when I come back in however long I wont be borked

PHP:
    $_DATA = array();
    
    //put table_gen queries here
    $_SQL = array(0 => "SELECT `RES_pH`,`RES_EC`,`RES_temp`,`RES_ph_up_total`,`RES_ph_down_total`,`RES_total_in` FROM `myTable` WHERE TS_DT > (TS_DT - 5) AND `RES_pH` IS NOT NULL ORDER BY id DESC LIMIT 1;",
                  1 => "SELECT `ENV_A1_WL`,`ENV_A1_LP`,`ENV_A1_TDS`,`ENV_A1_RT`,`ENV_A1_RH`,`ENV_A1_RHE`,`ENV_A1_AT`,`ENV_A1_ATE`,`ENV_A1_CO2`,`ENV_A1_CO2E`,`ENV_A1_FAN`,`ENV_A1_L`,`ENV_A1_LI`,`ENV_A1_FS`,`ENV_A1_FD`,`ENV_A1_FT`,`ENV_A1_FI`,`ENV_A1_TTF`,`ENV_A1_HAM`,`ENV_A1_HAH`,`ENV_A1_HAD` FROM `myTable` WHERE TS_DT > (TS_DT - 5) AND `ENV_A1_AT` IS NOT NULL ORDER BY id DESC LIMIT 1;",
                  2 => "SELECT `ENV_A2_WL`,`ENV_A2_LP`,`ENV_A2_TDS`,`ENV_A2_RT`,`ENV_A2_RH`,`ENV_A2_RHE`,`ENV_A2_AT`,`ENV_A2_ATE`,`ENV_A2_CO2`,`ENV_A2_CO2E`,`ENV_A2_FAN`,`ENV_A2_L`,`ENV_A2_LI`,`ENV_A2_FS`,`ENV_A2_FD`,`ENV_A2_FT`,`ENV_A2_FI`,`ENV_A2_TTF`,`ENV_A2_HAM`,`ENV_A2_HAH`,`ENV_A2_HAD` FROM `myTable` WHERE TS_DT > (TS_DT - 5) AND `ENV_A2_AT` IS NOT NULL ORDER BY id DESC LIMIT 1;",
                  3 => "SELECT `VPD_A1_AIR`,`VPD_A1_L0`,`VPD_A1_L1`,`VPD_A1_L2`,`VPD_A1_L3`,`VPD_A1_LFT_0`,`VPD_A1_LFT_1`,`VPD_A1_LFT_2`,`VPD_A1_LFT_3`,`VPD_A2_AIR`,`VPD_A2_L0`,`VPD_A2_L1`,`VPD_A2_L2`,`VPD_A2_L3`,`VPD_A2_LFT_0`,`VPD_A2_LFT_1`,`VPD_A2_LFT_2`,`VPD_A2_LFT_3` FROM `myTable` WHERE TS_DT > (TS_DT - 5) AND `VPD_A1_AIR` IS NOT NULL ORDER BY id DESC LIMIT 1;",
                  4 => "SELECT `ACPWR_A0_RCW`,`ACPWR_A1_RCW`,`ACPWR_A2_RCW`,`ACPWR_A3_RCW`,`ACPWR_A4_RCW`,`ACPWR_A5_RCW` FROM myTable WHERE TS_DT > (TS_DT - 10) AND `ACPWR_A0_RCW` IS NOT NULL ORDER BY id DESC LIMIT 1;",
                  5 => "SELECT `DCPWR_5V_C`,`DCPWR_5V_BV`,`DCPWR_5V_P`,`DCPWR_12V_C`,`DCPWR_12V_BV`,`DCPWR_12V_P`,`DCPWR_24V_C`,`DCPWR_24V_BV`,`DCPWR_24V_P` FROM myTable WHERE TS_DT > (TS_DT - 10) AND `DCPWR_5V_C` IS NOT NULL ORDER BY id DESC LIMIT 1;"
                  );
    //combine query results into $_DATA             
    $_NUM_QUERIES = count($_SQL);
    for ($i=0; $i < $_NUM_QUERIES; $i++) {
        $result = $db_conn->query($_SQL[$i]);
        $temp = $result->fetch_assoc();
        $result->free_result();
        $_DATA += $temp;
    }
  
    $db_conn -> close();
 

dstroy0

Zeroes and Ones
Implemented a "cycle tracker", now I can easily keep track of when I start veg/end veg, start flower/end flower and it is saved to that fram i2c module.

It's just a class with a unix timestamp for each member (veg start, veg end, flower start, flower end), I use the fram read/write anything code above to write it to fram, the unix timestamp comes from my realtime clock.

This will give me a better estimate of final cost, excluding only mother maintenance and cloning.
 

dstroy0

Zeroes and Ones
I'm making more humidifiers when the parts I ordered arrive tomorrow, I'll put a step by step of what I'm doing up tomorrow, but for now here's a parts list

waterproof fan, ip67 12vdc
Amazon product

ultrasonic humidifier with power supply, 24vdc about 300-350ml per hr
Amazon product

waterproof low voltage relay 12vdc coil
Amazon product

water float valve
Amazon product

plastic bag for a splash guard

Other things I'll use:
handtools
wire
butt connectors
molex connectors
already existing 12v power distribution

operation:
The existing 12v will actuate the relay and power the fan, and the 24v supply will only be used to power the ultrasonic humidifier, the float valve keeps the water at the correct level

reliability:
Works the same way as the humidifier I have in my drying closet which has been in uninterrupted operation for two years. They need to be supplied with RO and cleaned out every so often, and they have to be connected to a controller that does not let them run continuously.
 

Buck5050

Underground Chucker
Nice! So the fan pushes the mist out through the unsealed slot at the edge. Does that layer of plastic act like a check valve when the fans not running? How often do you have to cycle the fan to maintain your set humidity in the area?
 

dstroy0

Zeroes and Ones
Works good at keeping the humidity right around the setpoint

1600010192428.png

Each one of the orange peaks is an activation, the larger ones are when both are running at the same time, they are about 5 minutes apart. They run for about 15-30 seconds each time. As the plants in the space grow, they will be used less and less because of transpiration.
1600010368317.png
 

Frimpong

🔥Freak Genetics🔥
Works good at keeping the humidity right around the setpoint

View attachment 26589

Each one of the orange peaks is an activation, the larger ones are when both are running at the same time, they are about 5 minutes apart. They run for about 15-30 seconds each time. As the plants in the space grow, they will be used less and less because of transpiration.
View attachment 26592
This is amazing
 
Top Bottom