// BMP 280 config
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#define BMP_SCK 13 //SCK/SCL port
#define BMP_MISO 12 //SDO port
#define BMP_MOSI 9 //SDA/SDI port
#define BMP_CS 8 //CSB port
Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
// Mics-6814 config
#include <Wire.h>
#include "MutichannelGasSensor.h"
#include <NMEAGPS.h>
#include <NeoSWSerial.h>
static const int RXPin = 4, TXPin = 3;
NeoSWSerial gpsPort(RXPin, TXPin);
static const uint32_t GPSBaud = 9600;
NMEAGPS gps;
gps_fix fix;
uint8_t fixCount = 0;
// APC 220 config
NeoSWSerial mySerial(10,11);
int number = 0;
void setup(){
Serial.begin(9600);
mySerial.begin(9600);
Serial.println(F("--*C-------Pa------m-----NH3---NO2------lat-----long----kph")); // waarde worden aangegeven in volgorde van (temperatuur,luchtdruk,hoogte)
mySerial.println(F("--*C-------Pa--------m-----NH3---NO2----lat----long"));
gpsPort.begin(GPSBaud);
gas.begin(0x04);//the default I2C address of the slave is 0x04
gas.powerOn();
bmp.begin();
}
void loop(){
while (gps.available( gpsPort )) {
fix = gps.read();
// Once every 5 seconds...
if (++fixCount >= 1) {
BMP280();
Mics6814();
displayInfo();
fixCount = 0;
}
}
}
void BMP280(){
if (bmp.begin()){
Serial.print(bmp.readTemperature() - 5); // Leest temperatuur in graden af
Serial.print(", ");
Serial.print(bmp.readPressure()); // Leest luchtdruk in Pa af 1 hPa = 100 pa
Serial.print(", ");
Serial.print(bmp.readAltitude(1006.9)); // Luchtdruk aangepast op jouw gebied in hPa (http://luchtdruk.com/luchtdruk-in-nederland.html)
}
else {
Serial.print("invalid"); // Leest temperatuur in graden af
Serial.print(", ");
Serial.print("invalid"); // Leest luchtdruk in Pa af 1 hPa = 100 pa
Serial.print(", ");
Serial.print("invalid"); // Luchtdruk aangepast op jouw gebied in hPa (http://luchtdruk.com/luchtdruk-in-nederland.html)
}
}
void Mics6814(){
float c;
Serial.print(", ");
c = gas.measure_NH3(); // NH3 measure
if(c>=0) Serial.print(c); // NH3 measure
else Serial.print("invalid"); // NH3 measure
Serial.print(", ");
c = gas.measure_NO2(); // NO2 measure
if(c>=0) Serial.print(c); // NO2 measure
else Serial.print("invalid"); // NO2 measure
Serial.print(", ");
}
void displayInfo(){
if (fix.valid.location) {
Serial.print( fix.latitude(), 5 );
Serial.print(", ");
Serial.print( fix.longitude(), 5 );
} else {
Serial.print(F("INVALID"));
Serial.print(", ");
Serial.print(F("INVALID"));
}
if (fix.valid.speed) {
Serial.print(", ");
Serial.print(fix.speed_kph());
} else {
Serial.print(", ");
Serial.print(F("INVALID"));
}
Serial.println();
}
Ok so this is my code. Everything works fine and I am receiving the data on my computer. The only problem I had today is once I change all Serial.print lines to mySerial.print in the void loop, it does not work anymore. mySerial is a line that I made for the antenna to receive the data. The code under this description is an older one that works with the antenna and it has mySerial in it too. If someone can tell me what I did wrong please help me out with it.
/*
APC 220:
[Met deze code kun je de APC220 module als transmitter testen.]
[De APC220 sluit je als volgt aan op een uno:
APC220 > UNO
gnd > gnd
VCC > 5V
en > niet aansluiten
RXD > D11
TXD > D10
AUX > niet aansluiten
SET > niet aansluiten]
-------------------------------------------------------------------------------------
Mics-6814:
[Download https://github.com/Seeed-Studio/Mutichannel_Gas_Sensor/archive/master.zip and install it to Arduino Library.]
[Open the code directly by the path:File -> Example -> Mutichannel_Gas_Sensor-> ReadSensorValue_Grove.]
[Connect:
GND Connect to ground
VCC Power supply: 3.3V - 5V (5V)
SDA I2C data (Pin A4 or One next to AREF pin
SCL I2C clock (Pin A5 or Two next to AREF pin]
-------------------------------------------------------------------------------------
[SD card module:
Connect:
GND GND
VCC 5V
SCK pin 13
MOSI pin 11
MISO pin 12
CS pin 10]
*/
// SD Card config
/*
#include <SPI.h>
#include <SD.h>
File myFile;
int pinCS = 10;
*/
// APC 220 config
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10,11);
int number = 0;
// BMP 280 config
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#define BMP_SCK 13 //SCK/SCL port
#define BMP_MISO 12 //SDO port
#define BMP_MOSI 9 //SDA/SDI port
#define BMP_CS 8 //CSB port
Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
// Mics-6814 config
#include <Wire.h>
#include "MutichannelGasSensor.h"
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
Serial.println(F("--*C-------Pa------m-----NH3---NO2")); // waarde worden aangegeven in volgorde van (temperatuur,luchtdruk,hoogte)
mySerial.println(F("--*C-------Pa--------m-----NH3---NO2"));
gas.begin(0x04);//the default I2C address of the slave is 0x04
gas.powerOn();
(bmp.begin());
/*pinMode(pinCS, OUTPUT); // output van Chipset voor sd module*/
}
void loop() {
float c;
//Code for printing with antenna
if (bmp.begin()){
mySerial.print(bmp.readTemperature()); // Leest temperatuur in graden af
mySerial.print(", ");
mySerial.print(bmp.readPressure()); // Leest luchtdruk in Pa af 1 hPa = 100 pa
mySerial.print(", ");
mySerial.print(bmp.readAltitude(1022.0)); // Luchtdruk aangepast op jouw gebied in hPa (http://luchtdruk.com/luchtdruk-in-nederland.html)
}
else {
mySerial.print("invalid"); // Leest temperatuur in graden af
mySerial.print(", ");
mySerial.print("invalid"); // Leest luchtdruk in Pa af 1 hPa = 100 pa
mySerial.print(", ");
mySerial.print("invalid"); // Luchtdruk aangepast op jouw gebied in hPa (http://luchtdruk.com/luchtdruk-in-nederland.html)
}
mySerial.print(", ");
c = gas.measure_NH3(); // NH3 measure
if(c>=0) mySerial.print(c); // NH3 measure
else mySerial.print("invalid"); // NH3 measure
mySerial.print(", ");
c = gas.measure_NO2(); // NO2 measure
if(c>=0) mySerial.println(c); // NO2 measure
else mySerial.println("invalid"); // NO2 measure
delay(1000); // Geeft aan hoe snel de sensor weer nieuwe info moet geven
}