Skip to content

Commit

Permalink
[wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
maizy committed Dec 18, 2018
1 parent 1a894dd commit 83c7bf0
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ambient7-arduino/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Ambient7 with Arduino compatible MCU

## Hardware

* MCU - Wemos D1 R1
* Temperature/Humidity sensor – Asair (aka Aosong) AM2302 (DHT22)
* CO2 Sensor – Winsen MH-Z19B

All components may be replaced with analogues.

## Implementations

* [Arduino IDE based]()
* [micropython](micropython-version/) – abandoned. lack of
software serial (UART) support.

## Extra apps

* [hello-world-led](hello-world-led/) – test arduino sketch

## Wemos D1 R1 setup

### ArduinoIDE
Expand Down
30 changes: 30 additions & 0 deletions ambient7-arduino/arduino-ide-version/ambient7-mcu/ambient7-mcu.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <SoftwareSerial.h>

unsigned long startTime = millis();

void setup() {
Serial.begin(9600);
pinMode(D3, INPUT);
}

void loop() {
Serial.println("------------------------------");
Serial.print("Time from start: ");
Serial.print((millis() - startTime) / 1000);
Serial.println(" s");
int ppm_pwm = readCO2PWM();
delay(5000);
}

int readCO2PWM() {
unsigned long th, tl, ppm_pwm = 0;
do {
th = pulseIn(D3, HIGH, 1004000) / 1000;
Serial.println("Step");
tl = 1004 - th;
ppm_pwm = 5000 * (th-2)/(th+tl-4);
} while (th == 0);
Serial.print("PPM PWM: ");
Serial.println(ppm_pwm);
return ppm_pwm;
}
30 changes: 30 additions & 0 deletions ambient7-arduino/arduino-ide-version/t1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <SoftwareSerial.h>

unsigned long startTime = millis();

void setup() {
Serial.begin(9600);
co2Serial.begin(9600);
pinMode(D3, INPUT);
}

void loop() {
Serial.println("------------------------------");
Serial.print("Time from start: ");
Serial.print((millis() - startTime) / 1000);
Serial.println(" s");
int ppm_pwm = readCO2PWM();
delay(5000);
}

int readCO2PWM() {
unsigned long th, tl, ppm_pwm = 0;
do {
th = pulseIn(D3, HIGH, 1004000) / 1000;
tl = 1004 - th;
ppm_pwm = 5000 * (th-2)/(th+tl-4);
} while (th == 0);
Serial.print("PPM PWM: ");
Serial.println(ppm_pwm);
return ppm_pwm;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 83c7bf0

Please sign in to comment.