element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Achievement Levels
    • Benefits of Membership
    • Feedback and Support
    • Members Area
    • Personal Blogs
    • What's New on element14
  • Learn
    Learn
    • eBooks
    • Learning Center
    • Learning Groups
    • STEM Academy
    • Webinars, Training and Events
  • Technologies
    Technologies
    • 3D Printing
    • Experts & Guidance
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Arduino Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Project Groups
    • Raspberry Pi Projects
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Or 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
1 Meter of Pi
  • Challenges & Projects
  • Design Challenges
  • 1 Meter of Pi
  • More
  • Cancel
1 Meter of Pi
Blog Aquaponics Box: #2 - Hacking the HATs (both HATs from the challenger kit on single RPi)
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: dules
  • Date Created: 16 Nov 2020 10:46 PM Date Created
  • Views 1762 views
  • Likes 8 likes
  • Comments 23 comments
  • 1meterofpi
  • pico hat hacker
  • enviro hat
  • raspberry pi 4 2gb
  • pimoroni
  • 1 meter of pi
  • 1 meter of pi - design challenge
  • raspberrypi
  • pim487
  • automation hat mini
  • pim486
  • pim300
Related
Recommended

Aquaponics Box: #2 - Hacking the HATs (both HATs from the challenger kit on single RPi)

dules
dules
16 Nov 2020

Hacking the HATs

1) Intro

Got the challenger kit in the mail: RPi4 2GB, Enviro HAT (PIM486), Automation HAT mini (PIM487), Pico HAT Hacker (PIM300)

Raspberry Pi 4 2GB

Installed "Raspberry Pi OS" on an empty SD card

Luckily I had a micro HDMI adapter to connect the monitor

Hooked up USB keyboard and touchpad

2A USB-C cell phone charger (will be getting the recommended 3A power source).

Comparing it to RPi Zero I have worked with before it booted up lighting fast, and using it is a breeze.

Next up was testing of the HATs

Enviro (PIM486)

image

Followed instructions from https://github.com/pimoroni/enviroplus-python (same repository is for "Enviro+" and "Enviro", we got the Enviro)

On our board we have:

  • ST7735 - 0.96" colour LCD (160x80) (SPI)
  • BME280 - temperature, pressure, humidity sensor (I2C)
  • LTR-559 - light and proximity sensor (I2C)
  • MEMS microphone (I2S/PCM)

Main difference is that Enviro does not have these sensors included in Enviro+:

  • Breakout for PM sensor (PMS5003 particulate matter sensor)
  • MICS6814 -Gas sensor
  • ADS1015 - Analog to Digital Converter (used to read Analog values from Gas sensor)

At first it did not worked great, temperature and humidity values where way off and very variable.

I found out it was like that because of the HAT placement and RPi radiating heat over Temperature sensor, and temperature is used for adjusting humidity reading.

In examples there is cpu temp compensation code, but from my experience it was not reliable enough.

The solution was to get the HAT away from the RPi (using wires or ribbon cable) and remove the cpu temp compensation code. Now its working great.

weather-and-light.py example is my favorite and will probably reuse most of its code for my project (without cpu temp compensation).

Automation HAT mini (PIM487)

image

Followed instructions from https://github.com/pimoroni/automation-hat (same repository is for "Automation HAT", "Automation pHat" and our "Automation HAT mini")

CURL command did everything except the copy of examples, so I did that manually (downloaded the gitHub repository zip)

On our board we have:

  • ST7735 - 0.96" colour LCD (160x80) (SPI)
  • ADS1015 - Analog to Digital Converter (used to control analog channels) (I2C)
  • 3 Analog (ADC) channels - range inputs that measure supplied voltage from 0-24V (test: wire +5V to any of the ADC channels)
  • 3 Inputs - dual state input: low (<1V) and high (>3V) (test: wire +5 to any of the 3 Inputs
  • 3 Outputs - up to 24V sinking output (sinking means you connect +5/12/24 to load and from load to Output screw terminal as Ground)
  • 1 Relay - mechanical switch (max25V2A, can be used as normally open or normally closed (test: make an electrical circuit and loop it through the relay)

Github provide 3 separate examples with nice display graphics:

  • analog.py - analog range inputs
  • input.py - digital inputs
  • output.py - digital outputs
  • no relay example - can be utilized using: automationhat.relay.one.toggle()/on()/off()/is_on()/is_off()/write(boolean)

 

Pico HAT Hacker (PIM300)

image

Nothing special about this board at the first glance other than pin naming, and can do few things with it

- solder two rpi headers (female/male) and use it for offsetting some other HAT

- solder other side directly on the rpi header leaving enough space to put another hat on it so you can end up with two hats (if you can fit them)

- use as a hat and on the place off the second header solder in wires that go to the rest of your boards

 

2) Problem

When I found out that two HATs that we got in the challenger kit did not stack I was quite disappointed. Mostly because RPi4 2GB has more than enough computing power (and pins) for much more sensors and controls than those two HATs.

If we go to https://pinout.xyz/phatstack and select Automation Hat Mini and Enviro Plus (there is no option for basic Enviro HAT), we can see the clashing pins

image

From what we can see here there are 6 pins clashing so there should be no way to use them on single RPi.

But I can't accept it image

automationhat.relay.one

 

3) Research

If you are not in interested in details just skip to chapter 4) Solution

RPI Interfaces

To solve the problem we need to understand few different interfaces that you can use on RPi.

The one that we are interested in are:

  • I2C
  • SPI
  • I2S/PWM

 

I2C - Inter Integrated Circuit

This is a two-wire communication interface, on these two wires you can connect multiple devices, and each of them has an unique address (usually set by the manufacturer).

image

These two pins are used for I2C on RPI (source: https://pinout.xyz/pinout/i2c)

  • GPIO 2 (data)
  • GPIO 3 (clock)

We have multiple I2C devices on our HATs:

  • Enviro > BME280 (address - 0x76 or 0x77)
  • Enviro > LTR-559 (address - 0x23)
  • Automation mini > ADS1015 (address - 0x48)

So all of these devices have different addresses and are safe to connect all together (both use GPIO 2 and 3)

 

SPI - Serial Peripheral Interface

This is a 4 wire serial bus used to connect multiple devices, 3 wires are common and 1 wire (CS-Chip Select) is separate for each device.

On RPi there are 2 SPI busses:

  • SPI0: GPIO 7, 8 as CS pins and 9, 10, 11 as common pins
  • SPI1: GPIO 16, 17, 18 as CS pins and 19, 20, 21 as common pins

image

Our two HATs use SPI0 bus for ST7735 LCD display. They use common GPIO 9, 10,11 (marked black) and these are safe to share between both displays

But they also both use same CS pin GPIO 7, and we have two CS pins available on SPI0 (GPIO 7 and 8) so one of them should be switched to GPIO 8.

 

I2S/PCM - Pulse-code Modulation

Used for digital audio input or output, uses 4 GPIO pins

  • GPIO 18 - Serial Clock
  • GPIO 19 - Word select
  • GPIO 20 - Serial Data In
  • GPIO 21 - Serial Data Out

image

Enviro HAT uses pins GPIO 18, 19, 20 (marked with blue dot) for MEMS microphone

 

Enviro

This is the pinout of Enviro Hat:

image

Pins marked with red dot are not connected on Enviro, and are only used on Enviro+ so we don't have to take them into consideration

  • ST7735 (display) - GPIO 7, 8, 9, 10, 11, 12
  • BME280 - I2C: GPIO 2, 3
  • LTR-559 - I2C: GPIO 2, 3
  • MEMS microphone - I2S: GPIO 18, 19, 20

 

Automation HAT Mini

This is the pinout of Automation HAT Mini:

image

Thing to note here is that this HAT takes the 3V3 Power from pin 17

  • ST7735 (display) - GPIO 7, 8, 9, 10, 11, 25
  • ADS1015 (Analog channels)- I2C: GPIO 2, 3, 4 (not sure what is GPIO 4 about, still trying to get answers)
  • 3 Inputs - GPIO 26, 20, 21
  • 3 Outputs - GPIO 5, 12, 3
  • 1 Relay - GPIO 16

 

 

Clashing pins

As a result of research these are the only clashing pins:

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

 

 

4) Solution

 

I would like to keep the Automation HAT Mini unchanged so official automationhat library can be used, so only changes are going to be made to enviro pinout

 

Enviro GPIO 7

This is one of a SPI0 bus CS pins (we have two available), so we will move it on Enviro to other available CS pin GPIO 8. On Automation HAT Mini it will stay the same.

Important thing here is to change that pin in the Enviro example code (ST7735 initalization).

 

Enviro GPIO 12

This one is used on Automation HAT mini as an Output 2 pin, and on the Enviro for display backlight.

On Enviro I will switch that pin to GPIO 25, it's the same pin Automation HAT Mini is using for backlight (it can be shared)

I am going to use both displays together, so if you want to change backlight individually I suggest you put it on some other empty pin (eg pin GPIO 13)

Also don't forget to change backlight pin in the example code (ST7735 initalization).

 

ST7735 Initialization

Sample code for display initialization with modified Enviro HAT pins

#Enviro LCD
dispEnviro = ST7735.ST7735(
     port = 0,
     cs = 0, #GPIO 8
     dc = 9,
     backlight=25,
     rotation=270,
     spi_speed_hz=10000000
)
#Automation HAT Mini LCD
dispAutomation = ST7735.ST7735(
     port = 0,
     cs = 1, #GPIO 7
     dc = 9,
     backlight=25,
     rotation=270,
     spi_speed_hz=10000000
)

 

Enviro GPIO 20

This one is used on Automation HAT mini as an Input 2 pin, and on the Enviro for microphone data.

As I don't see any use for a microphone in my project I will disconnect all microphone pins on Enviro: GPIO 18, 19, 20

If you need the microphone you would need to move the Output 2 on Automation HAT to some other empty pin.

Rewiring of any Automation HAT Mini outputs or inputs will require the change in the official automationhat library (not recommended) or using the HAT without official library so you can define the pins by yourself.

 

Proof of concept

Here is a video of the working example. It's not pretty but it works image

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

5) Auto-Enviro HAT

So this new "Auto Enviro HAT" will be the combination of Enviro, Automation HAT Mini and Pico HAT Hacker.

Requirement is to be able to quickly connect/disconnect modules for replacement or inspection.

Idea is to use Pico HAT Hacker with one 40pin female header to plug into RPi, and two other 40 pin male headers, one connected to Enviro and the second to Automation HAT Mini.

male headers would be connected with wires to Pico HAT Hacker so they can be positioned away from RPi heat (messes with temperature readings)

image

Wiring schematics

I will upload pictures of finished Auto-Enviro HAT once I put it all together.

 

6) Conclusion

For me this was an educational journey about RPi pins and communication protocols.

Learned a lot by reverse engineering these two hats and trying to put them together.

Took some time to do so I hope it will help someone else to learn and implement.

 

 

Aquaponics Box: #1 - Intro

Aquaponics Box: #3 - Contest final notes

  • Sign in to reply

Top Comments

  • feiticeir0
    feiticeir0 over 3 years ago in reply to embeddedguy +4
    Yes, you can use them ! i'm using them with a temperature/humidity sensor using 3.3v, GND, SDA and SCL pins. Everything working well !
  • embeddedguy
    embeddedguy over 2 years ago in reply to ilvyanyatka +4
    Hi, You must ground all the pins on the Enviro hat with pins on RPi. I had an issue to get data from light sensor which is resolved by that! Best, Ujjval
  • feiticeir0
    feiticeir0 over 3 years ago in reply to dules +3
    I'm going to speak for myself here - I really did enjoy programming a Client-Server python (let's called application but it's more of a script ) . It was an opportunity to research RPCXML Client Server…
  • dules
    dules over 2 years ago in reply to embeddedguy

    Hey, I see that the backlight pins in your code is different then in my example...

    so check your backlight wiring for disp1. It's set to pin 12, and in my example its 25 (same as disp)

    Most likely that is the problem.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • embeddedguy
    embeddedguy over 2 years ago

    Hi Davor,

     

    I tried to start both the LCD's together but the second LCD on Enviro is not starting!

    My disp object looks like the following. The only thing I changed is the backlight and the cs pins as in the wiring diagram.

    Could it be that the power is not enough? I am suppying 2.1 amps!

     

    disp = ST7735.ST7735(
        port=0,
        cs=1,
        dc=9,
        backlight=25,
        rotation=270,
        spi_speed_hz=4000000
    )
    disp1 = ST7735.ST7735(
        port=0,
        cs=0,
        dc=9,
        backlight=12,
        rotation=270,
        spi_speed_hz=4000000
    )

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dules
    dules over 2 years ago in reply to ilvyanyatka

    Hi,

    for connecting the Enviro I used pin 1 for 3.3V, pin 2 for 5V and pin 6 for Ground.

    Ujjval might be right for grounding all the gnd pins from Enviro to RPi, I did not have any problems with the light sensor, but I did not do detailed testing so I might have not encountered it yet.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • embeddedguy
    embeddedguy over 2 years ago in reply to ilvyanyatka

    Hi,

     

    You must ground all the pins on the Enviro hat with pins on RPi. I had an issue to get data from light sensor which is resolved by that!

     

    Best,

    Ujjval

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ilvyanyatka
    ilvyanyatka over 2 years ago

    Hi, I have a question,

    What pins do you use to connect Enviro to Ground and 5V? They are not on the pinout chart and I cannot find this information online.

    Thanks

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
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 © 2023 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