Skip to content

Commit

Permalink
Merge pull request #3 from GLWine/Rev.-hardware-1.1.0
Browse files Browse the repository at this point in the history
Rev. hardware 1.1.0
  • Loading branch information
GLWine authored May 17, 2020
2 parents 999b37d + 338a6d4 commit ef8d1ef
Showing 7 changed files with 773 additions and 217 deletions.
Binary file modified ECU design on Fritzing/ECU-Bombyx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Libraries/DHT_sensor_library.zip
Binary file not shown.
27 changes: 0 additions & 27 deletions README.it_IT.md

This file was deleted.

58 changes: 53 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,12 +4,11 @@
![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/GLWine/ECU-Bombyx?include_prereleases&style=social)
![GitHub All Releases](https://img.shields.io/github/downloads/GLWine/ECU-Bombyx/total?style=social)

Thesis on the design and use of the environmental control unit for Bombyx mori.
Purpose: to measure changes in temperature and humidity to correlate any effects on the yarn obtained.
The project consists of an Arduino, a humidity and temperature sensor, a clock and an SD card.
Readings are taken every 15 minutes on the other moon.
Thesis project on the effects of climate and gases in companies that produce silk. Use of an Arduino system called ECU-Bombyx (Environmental control unit - Bombyx Mori).

[*Leggimi*](https://github.com/GLWine/ECU-Bombyx/blob/master/README.it_IT.md)
Purpose: to measure changes in temperature, humidity, eCO2 and total volatile organic compounds (TVOC) to correlate any effects on the yarn obtained.
The project consists of an Arduino, a humidity and temperature sensor, a clock module, an SD card shield and an SGP30 sensor for air quality.
Every 15 minutes The ECU-BM performs a reading that it saves in the SD.

<table cellspacing=”0″ cellpadding=”0″ width=”560″ border="0">
<tbody>
@@ -18,6 +17,55 @@ Readings are taken every 15 minutes on the other moon.
<td valign=”top” width=”250”><img border="0" src="https://github.com/GLWine/ECU-Bombyx/blob/master/Prototipo%203D/ECU-B.png"></td>
</tr></tbody></table>

# Installation guide

## Phase 1: *wiring*
Before installing and starting make sure of the presence of these modules:
- DHT 22 sensor (temperature and humidity);
- Micro-SD module;
- RTC DS1302 module (clock);
- SGP30 air quality sensor;
- Arduino module one turn. 3;
Strictly carry out the wiring as indicated in the ECU-Bombyx image.

## Phase 2: *software installation*
Step 0: install the necessary libraries.

Step 1: install the ECU-Bombyx-Setter file from the Arduino IDE. In the "Serial monitor" view, make sure all modules respond.

--- Skip if the previous one is successful ---

Step 2: carefully check the wiring and that the modules are actually working.

Step 3: install the ECU-Bombyx-Base-Line file from the Arduino IDE. This is to find the baseline for the SGP30 sensor. Based on the [manufacturer's information](https://github.com/adafruit/DHT-sensor-library/pull/138 "Baseline Set & Get"), I created the code. This passage is of fundamental importance. The procedure lasts 12, it must be done for each SGP30 you have.

Step 4: install the ECU-Bombyx-Main file from the Arduino IDE. In the "Serial monitor" view, make sure that all modules respond and complete operations.

Final notes:
1. will start reading every 15 minutes writing in the micro-SD. The save format is .cvs with the company name.
2. If the DHT 22 module does not mount a 4K7 Ohm resistor, it is essential to solder one between DAT and VDD.
3. (optional) Add a 100nF capacitor between VDD and GND for filtering the waves.
3. There is a voluntary error in the ECU-BOMBYX-Main code. The reason is to remind those who use the code to set the variable that gives the name the file with the readings.

# Libraries

I made some changes to it based on this libbrerie of DHT [Pull requests #138](https://github.com/adafruit/DHT-sensor-library/pull/138 "Fixed signed/unsigned and unused parameter warnings")

The library to be imported with the correction is in the zip, it is sufficient to decompress it in the folder ..\Documents\Arduino\libraries\.

## Libraries List

Here are the lepers used for the code:

- Adafruit SGP30 Air Quality Sensor Breakout
- Adafruit SGP30 Sensor by Adafruit V.1.2.0
- DS1302: Trickle-Charge Timekeeping Chip
- RTC by Makuna V.2.3.4
- DHT22 temperature-humidity sensor + extras
- DHT sensor librery by Adafruit V.1.3.9 **_modified_**

I recommend installing all the dependencies that arduino IDE offers

# License [![GitHub license](https://img.shields.io/github/license/GLWine/ECU-Bombyx)](https://github.com/GLWine/ECU-Bombyx/blob/master/LICENSE.md)

This program is free software: you can redistribute it and/or modify
235 changes: 235 additions & 0 deletions Sketch ECU/ECU-Bombyx-Base-Line/ECU-Bombyx-Base-Line.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
/* The following code is used to set the starting baseline for the SGP30 module.
* The calibration process lasts 12 hours, every 30 minutes from a partial response.
* At the end he writes in the SD the two found values of the eCO2 and of the TVOC.
*
* modified 17 May 2020 by Giampiero Leserri
*/

#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <Adafruit_SGP30.h>
#include <DHT.h>

// set up variables using the DHT 22:
#define DHTPIN 2 //Pin select DHT
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE); // Declare the DHT data pin and model to the DHT library

// set up variables using the SGP30:
Adafruit_SGP30 sgp;
uint16_t TVOC_base, eCO2_base;
/* return absolute humidity [mg/m^3] with approximation formula
* @param temperature [°C]
* @param humidity [%RH]
*/
uint32_t getAbsoluteHumidity(float temperature, float humidity)
{
// approximation formula from Sensirion SGP30 Driver Integration chapter 3.15
const float absoluteHumidity = 216.7f * ((humidity / 100.0f) * 6.112f * exp((17.62f * temperature) / (243.12f + temperature)) / (273.15f + temperature)); // [g/m^3]
const uint32_t absoluteHumidityScaled = static_cast<uint32_t>(1000.0f * absoluteHumidity); // [mg/m^3]
return absoluteHumidityScaled;
}

// set up variables using the SD utility library functions:
#define chipSelect 4 // declare the pin that is connected to the chip select
// the myFile object is created for the SD
File myFilex;
File myFiley;

//
const unsigned long timeL = 44100000; //12 hour
static unsigned long timeS1 = 60000; // 1 minute
static unsigned long timeS2 = 1800000; //30 minute

//const unsigned long timeL = 600000; //10 minute
//static unsigned long timeS1 = 60000; // 1 minute
//static unsigned long timeS2 = 300000; //5 minute

void setup()
{
Serial.begin(9600);

Serial.print(F("Initializing SD card..."));

if (!SD.begin(4))
{
Serial.println(F("initialization failed!"));
while (1)
;
}

dht.begin();

Serial.println(F("initialization done."));

Serial.println(F("SGP30 test"));

if (!sgp.begin())
{
Serial.println(F("Sensor not found :("));
while (1)
;
}
Serial.print(F("Found SGP30 serial #"));
Serial.print(sgp.serialnumber[0], HEX);
Serial.print(sgp.serialnumber[1], HEX);
Serial.println(sgp.serialnumber[2], HEX);
Serial.println(F("Calibration start... (duration 12h)\n******************************"));

// If you have a baseline measurement from before you can assign it to start, to 'self-calibrate'
//sgp.setIAQBaseline(0x8E68, 0x8F41); // Will vary for each sensor!
myFilex = SD.open("Cali.csv", FILE_WRITE);

// if the file is available, write to it:
if (myFilex)
{
myFilex.println(F("eCO2;TVOC"));
myFilex.close();
}
else
{
// if the file didn't open, print an error:
Serial.println(F("error opening Cali.csv"));
}
}
// creo una varibile per far andare l'if in basso alla riga 138
int i = 0;

void loop()
{
// make a string for assembling the data to log:
String dataString = "";

if (millis() < timeL)
{
// If you have a temperature / humidity sensor, you can set the absolute humidity to enable the humditiy compensation for the air quality signals
float temperature = dht.readTemperature(); // [°C]
float humidity = dht.readHumidity(); // [%RH]
sgp.setHumidity(getAbsoluteHumidity(temperature, humidity));

if (!sgp.IAQmeasure())
{
Serial.println(F("Measurement failed"));
}
//Serial.print("TVOC "); Serial.print(sgp.TVOC); Serial.print(" ppb\t");
//Serial.print("eCO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm");

if (!sgp.IAQmeasureRaw())
{
Serial.println(F("Raw Measurement failed"));
}
//Serial.print("Raw H2 "); Serial.print(sgp.rawH2); Serial.print(" \t");
//Serial.print("Raw Ethanol "); Serial.print(sgp.rawEthanol); Serial.println("");

delay(2000);

if (millis() > timeS1)
{
Serial.print(F("."));
timeS1 += 60000;
}

if (millis() >= timeS2)
{
timeS2 += 1800000; //30 minute
//timeS2 += 300000; // 5 minute

if (!sgp.getIAQBaseline(&eCO2_base, &TVOC_base))
{
Serial.println(F("Failed to get baseline readings"));
}
Serial.println(F("\n30 minutes have passed!"));
dataString = (F("0x"));
dataString += String(eCO2_base, HEX);
dataString += (F(";"));
dataString += (F("0x"));
dataString += String(TVOC_base, HEX);

// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFilex = SD.open("Cali.csv", FILE_WRITE);

// if the file is available, write to it:
if (myFilex)
{
myFilex.println(dataString);
myFilex.close();
// print to the serial port too:
Serial.println(dataString);
}
else
{
// if the file didn't open, print an error:
Serial.println(F("error opening BLP1"));
}
}
}
else
{
if (i < 1)
{

if (!sgp.getIAQBaseline(&eCO2_base, &TVOC_base))
{
Serial.println(F("Failed to get baseline readings"));
}
Serial.println(F("\n\n\nProcess terminated!!!"));
Serial.print(F("****Baseline values: eCO2: 0x"));
Serial.print(eCO2_base, HEX);
Serial.print(F(" & TVOC: 0x"));
Serial.println(TVOC_base, HEX);

// delete the file:
Serial.println(F("Removing old ECO2 and TVOC..."));
SD.remove("ECO2.TXT");
SD.remove("TVOC.TXT");

dataString = (F("0x"));
dataString += String(eCO2_base, HEX);
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFilex = SD.open("ECO2.TXT", FILE_WRITE);

// if the file is available, write to it:
if (myFilex)
{
myFilex.println(dataString);
myFilex.close();
// print to the serial port too:
Serial.println(dataString);
}
else
{
// if the file didn't open, print an error:
Serial.println(F("error opening eCO2"));
}

dataString = (F("0x"));
dataString += String(TVOC_base, HEX);
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFiley = SD.open("TVOC.TXT", FILE_WRITE);

// if the file is available, write to it:
if (myFiley)
{
myFiley.println(dataString);
myFiley.close();
// print to the serial port too:
Serial.println(dataString);
Serial.println();
}
else
{
// if the file didn't open, print an error:
Serial.println(F("error opening TVOC"));
}
i = 2;
}
}
}
/* Sketch uses 20316 bytes (62%) of program storage space. Maximum is 32256 bytes.
* Global variables use 1171 bytes (57%) of dynamic memory,
* leaving 877 bytes for local variables. Maximum is 2048 bytes.
*/
Loading

0 comments on commit ef8d1ef

Please sign in to comment.