Skip to content

Commit

Permalink
First commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdsuel committed Mar 5, 2024
0 parents commit aff36fc
Show file tree
Hide file tree
Showing 38 changed files with 21,072 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: PlatformIO CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache PlatformIO
uses: actions/cache@v2
with:
path: ~/.platformio
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: Set up Python
uses: actions/setup-python@v2
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Run PlatformIO
run: pio run -e Mella2.0
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.pio
.vscode
.DS_Store
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Mella
Mella is a mushroom growing chamber designed at FirstBuild. The chamber provides a humidity, light, and fresh air controlled environment that allows users to customize the conditions to promote growth of a multitude of mushroom species.

## Software Structure
The software is made up of a few main components/modules:

```mermaid
graph TD
UnitState[Unit State]
AirExchange[Air Exchange Controller]
Humidity[Humidity Controller]
Light[Light Controller]
Encoders[Encoders]
```

### Unit State
The primary purpose of this state machine is to maintain the system status.

Upon startup, the State Machine enters `State_Startup` for a parametrically-defined time. After startup, the unit enters `State_Normal`. While in this state, the humidity is periodically checked. If the humidity value falls outside the parametrically-defined range, the unit will enter `State_Abnormal` and remain in that state until the humidity returns to the normal range or a parametrically-defined timeout occurs. If the timeout occurs, the unit will enter `State_Fault`. While in this state, the lighting will be set to Error Mode. If the humidity re-enters the normal range, the unit will immediately return to `State_Normal`.

```mermaid
flowchart TD
State_StartUp -- Timeout --> State_Normal
State_Normal -- %RH Good --> State_Normal
State_Normal -- %RH Bad --> State_Abnormal
State_Abnormal -- %RH Good --> State_Normal
State_Abnormal -- %RH Bad --> State_Abnormal
State_Abnormal -- Timeout --> State_Fault
State_Fault -- %RH Good --> State_Normal
State_Fault -- %RH Bad --> State_Fault
```

### Air Exchange Controller
This controller simply controls the fresh air exchange fan in accordance with the knob setting. In a future update, the fan will be set to only run for a parametrically-defined period of time.

### Humidity Controller
Mella uses a SHT31 temperature/humidity sensor for closed loop control. Measurements from the sensor are fed back into a parametrically-defined PID loop whose output controls the humidity fan.

During operation, the humidity controller will periodically measure relative humidity and control the humidity fan in an attempt to maintain the humidity setpoint defined by the encoder knob position. The Humidity Controller is responsible for determining if the humidity falls within the parametrically-defined normal range.

### Light Controller
The light controller handles the lighting modes and animations. The state machine will request either Error Mode or Normal Mode. Based on this request, the light controller will adjust how it controls both the chamber light as well as the PCB heartbeat LED. In Normal Mode, the chamber lights will remain on and the intensity will be set based on the encoder position. The heartbeat LED will blink in 1 second intervals. In Error Mode, the chamber lights will slowly pulsate/bounce to notify the user of an issue. Additionally, the heartbeat LED will begin blinking ten times per second.

### Encoders
All three controllers (Air Exchange, Humidity, and Light) get their setpoint from the user via a set of three 16-position absolute encoders.
The knob being in the 6 o'clock position equates to off. The remaining 15 positions represent equally spaced values from the minimum to maximum values for the respective controllers.

## Logging
Mella provides periodic logging of data in CSV format. When logging occurs, the output of each module is printed to the output. This log can be accessed via the Mini USB port as a serial UART with a baud rate of 115200.

## Building
This project uses PlatformIO and can be built using the PlatformIO build function. For flashing, it is recommended that you use the shell scripts. For debugging/testing purposes, use the PlatformIO functions.
39 changes: 39 additions & 0 deletions include/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

This directory is intended for project header files.

A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.

```src/main.c

#include "header.h"

int main (void)
{
...
}
```

Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.

In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.

Read more about using header files in official GCC documentation:

* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes

https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
46 changes: 46 additions & 0 deletions lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.

The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").

For example, see a structure of the following two libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c

and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>

int main (void)
{
...
}

```

PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
56 changes: 56 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:Mella]
platform = atmelavr
framework = arduino
; board = leonardo
board = flora8
board_fuses.efuse = 0xCB
board_fuses.hfuse = 0xDE
; board_fuses.lfuse = 0xFF ; External 16 Mhz Crystal
board_fuses.lfuse = 0xE2 ; Internal RC Oscillator
; board_upload.offset = 0xFF
monitor_speed = 115200
upload_flags = -D
lib_deps =
ryanplusplus/tiny@^6.3.0
mike-matera/FastPID@^1.3.1
adafruit/Adafruit SHT31 Library@^2.0.0
ryanplusplus/arduino-tiny@^4.0.7

[env:AVRISP_mkII]
platform = atmelavr
framework = arduino
; board = leonardo ; External 16 Mhz Crystal Config
board = flora8 ; Internal RC Oscillator Config
board_fuses.efuse = 0xCB
board_fuses.hfuse = 0xDE
; board_fuses.lfuse = 0xFF ; External 16 Mhz Crystal Config
board_fuses.lfuse = 0xE2 ; Internal RC Oscillator Config
; board_upload.offset = 0xFF
upload_protocol = custom
upload_port = usb
upload_flags =
-C
${platformio.packages_dir}/tool-avrdude/avrdude.conf
-p
$BOARD_MCU
-P
$UPLOAD_PORT
-c
avrispmkII
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i
monitor_speed = 115200
lib_deps =
ryanplusplus/tiny@^6.3.0
mike-matera/FastPID@^1.3.1
adafruit/Adafruit SHT31 Library@^2.0.0
ryanplusplus/arduino-tiny@^4.0.7
Loading

0 comments on commit aff36fc

Please sign in to comment.