1. Hello!

    First of all, welcome to MapleLegends! You are currently viewing the forums as a guest, so you can only view the first post of every topic. We highly recommend registering so you can be part of our community.

    By registering to our forums you can introduce yourself and make your first friends, talk in the shoutbox, contribute, and much more!

    This process only takes a few minutes and you can always decide to lurk even after!

    - MapleLegends Administration-
  2. Experiencing disconnecting after inserting your login info? Make sure you are on the latest MapleLegends version. The current latest version is found by clicking here.
    Dismiss Notice

Milky's DIY Electronics Project: Plant Care Automation Tool

Discussion in 'Programming' started by AssamMilkTea, Jul 25, 2021.

  1. AssamMilkTea
    Offline

    AssamMilkTea King Slime

    29
    42
    36
    Nov 28, 2020
    Vereinigte Staaten
    6:34 AM
    Milkerino
    Heyo Milky here~
    I recently decided to work on an electronics project that takes care of your plants for you.
    Big brain AinzAinz suggested sharing my progress here in the forums so why not =3=

    I will be providing updates when I am free from work and have achieved something of visual significance, typically once every 3 days.

    A.L.P.H.A.
    Automated and Lightweight Plant Habitation Assistant


    Functionalities
    Water plants with configurable time periods and water quantity depending on temperature and humidity
    Log plant growth, temperature and humidity onto an external storage and display on OLED
    Detect light levels throughout the day and use LED to supplement plant growth
    Display soil pH, temperature, humidity and any relevant stats onto the OLED module
    Use motors to carry sensor and watering tool from pot to pot to monitor multiple plants

    Project Duration:
    2021-07-24 → present

    Prepared by

    Milky

    Electrical Components
    STM32 microcontroller, SD card and reader, 4x4 Keypad, Photoresistor,
    Humidity sensor, Thermometer, Water level sensor, Red and Blue LED,
    OLED Module, Active buzzer, Stepper- and servo-motors
    (ELEGOO 37 SENSOR KIT TUTORIAL FOR UNO V2.0)
    [​IMG]

    Software Components

    STM32 System Workbench (IDE)
    CubeMX (Hardware Abstraction Layer)
    [​IMG]

    Miscellaneous Components

    water storage
    water flow switch (connected to servomotor)
    plant of choice
    flower pot of choice

    Code Repository

    https://github.com/BobbaMilkTea/alpha

    Timeline

    https://docs.google.com/spreadsheets/d/1D-ZyrKnIMRHGlNYRvxcjqJI7CP4GUzHoVvOjKRtuSOY/edit?usp=sharing

    System Design for Function I

    [​IMG]

    Algorithmic Design for Function I
    - release water when temperature is low to prevent evaporation
    - release greater quantities of water when humidity is low
    - alert user when water level in tank is low
    [​IMG]

    System Design for Function II
    [​IMG]

    Algorithmic Design for Function II
    - use polling subroutine to display info onto OLED
    - log information on SD card via SPI
    - set up external interrupt to receive user display requests
    [​IMG]

    Schematic Layout
    [TBA]

    PCB Design
    [TBA]

    Budget
    ComponentDescriptionUnit PriceQuantityPrice
    STM32F051R8T6 IC MCU 32BIT 64KB FLASH 64LQFP $4.21 1 $4.21
    Sensor Kit ELEGOO Upgraded 37 in 1 Sensor Modules Kit $34.99 1 $34.99
    Digital Multimeter AstroAI Multimeter 2000 Counts Digital Multimeter $12.99 1 $12.99
    Portable Oscilloscope AUKUYEE Updated 2.4" TFT Digital Oscilloscope Kit $46.99 1$46.99
    - - - - $99.18
    Test Plan
    - unit testing
    - integration testing
    - behaviourial testing

    [TBA]

    References / Citation

    [1] G. Spano, M. D’Este, V. Giannico, et al., Are Community Gardening and Horticultural Interventions Beneficial for Psychosocial Well-Being? A Meta-Analysis , 20-May-2020. [Online]. Available: link
    [2] “ELEGOO 37 SENSOR KIT TUTORIAL FOR UNO V2.0.” Elegoo, Shenzhen. Available: https://www.elegoo.com/pages/arduino-kits-support-files. [Accessed July 24, 2021].
    [3] H. Silva, S. Sagardia, et al., “Relationships between leaf anatomy, morphology, and water use efficiency in Aloe vera as a function of water availability,” Revista Chilena de Historia Natural, 24-Jul-2014. [Online]. Available: link
    [4] “STM32F051x4 STM32F051x6 STM32F051x8 Datasheet.” STMicroelectronics.
    [5] “RM0091 Reference manual.” STMicroelectronics.
    [6] "SPECIFICATIONS OF LCD MODULE NO: LCM1602A-FSYG-GBW DOC REVISION: 00" Longtech Optics.
    [7] “DHT11 Humidity & Temperature Sensor.” Mouser Electronics.
     
    • Great Work Great Work x 6
    • Like Like x 4
    • Informative Informative x 1
  2. CleverCookie
    Offline

    CleverCookie King Slime

    29
    9
    41
    May 28, 2017
    6:34 AM
    CleverCookie
    Night Lord
    Nerd
     
    • Informative Informative x 1
    • Friendly Friendly x 1
  3. Ainz
    Offline

    Ainz Zakum

    1,669
    1,081
    490
    May 2, 2015
    Male
    Netherlands
    11:34 AM
    So many I keep forgetting
    0
    This is so fkn cool I'm so happy you decided to journal it!
     
    • Friendly Friendly x 1
  4. geospiza
    Offline

    geospiza Web Developer Staff Member Web Developer

    212
    449
    215
    Apr 16, 2020
    3:34 AM
    geospiza
    Dark Knight
    146
    Funk
    Over-engineered many times over. Looking forward to progress!
     
    • Friendly Friendly x 1
  5. OP
    OP
    AssamMilkTea
    Offline

    AssamMilkTea King Slime

    29
    42
    36
    Nov 28, 2020
    Vereinigte Staaten
    6:34 AM
    Milkerino
    A couple of days ago, I decided to start with an achievable piece - connecting the micro-controller with an LCD 1602 display (16 characters per row, 2 rows).
    Initially I wanted to use the CFAL1602-Y module, which allows for interfacing in SPI mode.

    SPI (serial peripheral interface) allows for communication by using 4 wires (1 for clock signal, 1 for device selection and 2 for data transmission in each direction).

    Unfortunately, my CFAL1602-Y module broke, and I had to rewrite my code to use the LCM1602-A instead, which can only be interfaced using parallel bits.
    I decided to use 4-bit mode instead of 8-bit mode for communication, which saves up some GPIO pins at the cost of doubling the time taken to transmit data.

    The STM32 reference manual contains registers for us to look up. In this case, the ODR (output data register) was used to determine the voltage level (3.3V for logic '1', 0V for logic '0') to be sent to the LCD module.
    The code snippet as shown was used.
    Code:
    static void _send_parallel_four_bit(char b, int mode) {
       GPIOA->ODR &= ~(DISP_RS);
       GPIOA->ODR = (mode << 1) | ((b & 0x0f) << 4);
       GPIOA->ODR |= DISP_EN;
       _micro_wait(1000);
       GPIOA->ODR &= ~DISP_EN;
    }
    References:
    https://web.sonoma.edu/users/f/farahman/sonoma/courses/es310/310_arm/resources/LCD_V1_setup.pdf

    Result:
    [​IMG]

    What's next?
    Connecting the hygrometer-thermometer (blue component at the back) to display humidity and temperature!
     
    • Like Like x 2
  6. OP
    OP
    AssamMilkTea
    Offline

    AssamMilkTea King Slime

    29
    42
    36
    Nov 28, 2020
    Vereinigte Staaten
    6:34 AM
    Milkerino
    The DHT11 uses a single line to transmit bidirectional data, one bit at a time, with the time period between falling edges defining a '0' or '1' bit.

    The algorithm was supposed to be:
    initialise connection to DHT 11-> send a read request -> DHT11 responds with read request acknowledged -> DHT11 sends 40 consecutive bits representing humidity and temp.
    However, it seems that the STM32 has only detected the request acknowledgement from the DHT11 without any data bits coming after it =3=
    [​IMG]

    This is difficult to debug at a software level and requires some hardware probing tools, which I really should have purchased at the very beginning ;-;
    [​IMG]
    An oscilloscope for signal variation over time and a DMM for simple voltage/current/resistance measurement should come in handy.
    Thankfully they are not too pricey. I'm adding this to the budget section in the first post.
     
    • Great Work Great Work x 1
  7. Ainz
    Offline

    Ainz Zakum

    1,669
    1,081
    490
    May 2, 2015
    Male
    Netherlands
    11:34 AM
    So many I keep forgetting
    0
  8. OP
    OP
    AssamMilkTea
    Offline

    AssamMilkTea King Slime

    29
    42
    36
    Nov 28, 2020
    Vereinigte Staaten
    6:34 AM
    Milkerino
    I know you are big brain Ainz
    stop pretending and tell me what's wrong with my code
     
    • Friendly Friendly x 1
  9. OP
    OP
    AssamMilkTea
    Offline

    AssamMilkTea King Slime

    29
    42
    36
    Nov 28, 2020
    Vereinigte Staaten
    6:34 AM
    Milkerino
    Bad news I think the humidity sensor is bork
    Edit: Turns out the sensor was not broken =3=
    As you can see, although the request signal was sent, no response was ever received from the DHT11...
    [​IMG]
    It may have been the STM32 supplying a voltage level below the input range of the DHT11 (3-5.5V),
    [​IMG]
    After switching to a 5V open-drain output setup, the DHT11 started returning a response.
    [​IMG]
    Started receiving signals from the DHT11 hooray! (thinner means '0', fatter means '1')
    [​IMG]
    And now to take a look at the values received
    ...
    [​IMG]
    [​IMG]
     
    • Like Like x 2

Share This Page