element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
1 Meter of Pi
  • Challenges & Projects
  • Design Challenges
  • 1 Meter of Pi
  • More
  • Cancel
1 Meter of Pi
Blog The Space Salad System Blog 9 - Wearing Two HATs At Once
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: rockcacti
  • Date Created: 6 Jan 2021 2:03 AM Date Created
  • Views 467 views
  • Likes 4 likes
  • Comments 0 comments
  • 1 meter of pi
  • the space salad system
Related
Recommended

The Space Salad System Blog 9 - Wearing Two HATs At Once

rockcacti
rockcacti
6 Jan 2021

Previous Blog Posts

Blog 1 - Challenge Overview + Plant Growth Factors

Blog 2 - Plant Growth Chamber Design

Blog 3 - The Project Plan + Prototype Materials

Blog 4 - Automation Using The Challenger Kit

Blog 5 - Enclosure Prototype + Light/Air/Temperature

Blog 6 - Plant Pot System + Assembly

Blog 7 - Enviro HAT Data Collection and Plotting

Blog 8 - Automation HAT Irrigation System

 

Wearing Two HATs At Once

 

This time I decided to have a playful pun as the blog title, as it aptly describes the content of this blog and the journey thus far. I believe the 1 Meter of Pi design challenge is not only a challenge to design a system to grow plants in space, but also a challenge of wearing two hats, one of botany and one of engineering. Coming into this challenge with zero Raspberry Pi experience, I'm so surprised by how much I've done and learned in the past month. Blog 7 and 8 hold a very special place in my heart as it documents the growth I've had as an engineer. I'm getting more comfortable with the engineering hat, but I've got so much more to learn. So this blog, I challenge myself with getting the Raspberry Pi to wear two HATs at once and adding a harvest notification feature to the Enviro HAT.

 

Fellow challenger dules solved the challenge of getting two HATs on a single Raspberry Pi. I follow along with his explanation, but also check for my own understanding:

 

Pinout of the Automation HAT

image

 

Pinout of the Enviro HAT

image

 

Clashing Pins

As dules observed, the following pins clash:

 

GPIO

Enviro HAT

Automation HAT Mini

7SPI CSSPI CS
12Display BacklightOutput 2
20I2S Serial Data In (microphone)Input 2

 

Following his recommendations, I switch SPI CS to GPIO 8, the only other available SPI CS pin, and switch Display Backlight to GPIO 25, which can be shared with Automation HAT Mini because it is a display backlight. I unplug 12S Serial Data In, because my project does not use a microphone. By changing only the Enviro HAT pins, I can keep Automation HAT pins unchanged and I am able to keep using the official library without changing the code.

 

GPIO

Enviro HAT

8SPI CS
25Display Backlight
NoneI2S Serial Data In (microphone)

 

Enviro HAT Pinout Initialization

I must modify ST7735 Initialization in the Enviro HAT weather-and-light.py example code so that it reflects the new pinout:

 

#Initialize the LCD
dispEnviro = ST7735.ST7735(
     port = 0,
     cs = 0, #GPIO 8
     dc = 9,
     backlight = 25,
     rotation = 270,
     spi_speed_hz = 10000000
)

 

Hooking up both HATs to the Raspberry Pi

This setup requires so many jumper wires that the number of failure points increases tremendously. Having experienced a faulty jumper wire situation with the Automation HAT, I decide to use a methodical approach of testing first before hooking things up. I test each jumper wire individually with an LED and breadboard then I proceed to hooking up the HATs. I choose to use bright colored jumper wires for the Enviro HAT and dark colored ones for the Automation HAT. None of the jumper wires were faulty, but it was a good practice nonetheless.

 

Enviro HAT Harvest Notifications

I only need 3 of the 4 environmental readings on the Enviro HAT display: temperature, humidity, and light. So that leaves extra space on the display to tinker with. I decided that the most useful feature would be harvest notifications. For this iteration of the project, I decided that the most useful harvest notification would be for lettuce, which takes four weeks to mature from seed to harvest. (Future iterations could have a harvest notification for each plant, but for this iteration, I only have space for one notification.)

 

In the 'weather-and-light.py' file, I first commented out all parts related to pressure since I am replacing pressure with harvest. I then created a 'describe_harvest' function that returns either "YES" or "NO". 'time_elapsed' is a variable defined in the latter part of the file. It represents the number of seconds since the file first ran (i.e. how long the Enviro HAT has been collecting environmental readings).

 

There's 2419200 seconds in a week. We convert time_elapsed to weeks_elapsed. The if-statement checks if 4 weeks have passed since planting. If so, we are ready to harvest!

 

def describe_harvest(time_elapsed):
    """Tells user whether harvest is ready or not"""
    harvest_is_ready = "NO"
    weeks_elapsed = time_elapsed // 2419200
    if weeks_elapsed > 0 and weeks_elapsed % 4 == 0:
        harvest_is_ready = "YES"
    return harvest_is_ready

 

I then insert some code for harvest display within the 'while True:' loop, just right before '# Display image'.

 

    # Harvest
    harvest_string = "Harvest?"
    img = overlay_text(img, (WIDTH - margin, 48), harvest_string, font_lg, align_right=True)
    harvest_desc = describe_harvest(time_elapsed)
    spacing = font_lg.getsize(harvest_string.replace(",", ""))[1] + 1
    img = overlay_text(img, (WIDTH - margin - 1, 48 + spacing), harvest_desc, font_sm, align_right=True, rectangle=True)
    
    # Display image 
    disp.display(img)

 

Video Demo

Success! Although this setup looks quite busy with all the jumper wires, it does provided an added benefit. With the Enviro HAT positioned far away from the Raspberry Pi, the heat radiated from the Raspberry Pi CPU no longer affects Enviro HAT environmental readings. The measurements are now different, but are not yet accurate it seems. (I also learned that BAD humidity stands for any humidity that is not between 40-60%)

 

Environmental ReadingEnviro HAT on Pi

Enviro HAT away from Pi

Temperature25°C15°C
Humidity64% BAD93% BAD
Light328 Lux621 Lux

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

In the next blog, I'll summarize my project, show a full video demo, and express many thanks to those who helped me during this awesome journey! Until then, keep learning and have fun! Click the arrow to navigate to the next blog.

image

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube