Hello everyone,
this is my first question on this forum. I'm currently participating in a contest named Cansat. We have to make a satellite with the size of a soda can. I'm now working on the programming of our satellite, but I'm experiencing a problem.
I have two programs: one for a BMP200 sensor, which measures the air temperature and the air pressure and the other program is for a TCS230 color sensor, which measures the RGB values. Both sensors have to send their data wireless back to our ground station. If I use each program separate from each other, they work perfect, but when I combine them, the data only comes through to our ground station when I turn the satellite off, not every second as it is supposed to do.
This is my code:
#include <SoftwareSerial.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP2800.h>
#define S0 5
#define S1 4
#define S2 1
#define S3 6
#define sensorOut 7
#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 9
#define BMP_CS 8
// Stores frequency read by the photodiodes
int redFrequency = 0;
int greenFrequency = 0;
int blueFrequency = 0;
SoftwareSerial mySerial(10,11);//RX, TX
int number = 0;
//Adafruit_BMP280 bmp; // I2C
//Adafruit_BMP280 bmp(BMP_CS); // hardware SPI
Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
void setup() {
// Setting the outputs
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
// Setting the sensorOut as an input
pinMode(sensorOut, INPUT);
// Setting frequency scaling to 20%
digitalWrite(S0,HIGH);
digitalWrite(S1,LOW);
mySerial.begin(9600);
mySerial.begin(9600);
mySerial.println(F("BMP280 test"));
if (!bmp.begin()) {
mySerial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1);
}
}
void loop() {
{
// Setting RED (R) filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
// Reading the output frequency
redFrequency = pulseIn(sensorOut, LOW);
// Printing the RED (R) value
mySerial.print("R = ");
mySerial.print(redFrequency);
delay(100);
// Setting GREEN (G) filtered photodiodes to be read
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
// Reading the output frequency
greenFrequency = pulseIn(sensorOut, LOW);
// Printing the GREEN (G) value
mySerial.print(" G = ");
mySerial.print(greenFrequency);
delay(100);
// Setting BLUE (B) filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
// Reading the output frequency
blueFrequency = pulseIn(sensorOut, LOW);
// Printing the BLUE (B) value
mySerial.print(" B = ");
mySerial.println(blueFrequency);
delay(100);
}
{
mySerial.print(F("Temperature = ")); //Woordje 'temperature' doorgeven
mySerial.print(bmp.readTemperature()); //gemeten temperatuur doorgeven
mySerial.println(" *C"); //graden celsius teken erachter zetten
mySerial.print(F("Pressure = ")); //Woordje 'pressure' doorgeven
mySerial.print(bmp.readPressure()); //gemeten luchtdruk doorgeven
mySerial.println(" Pa"); //Pascal erachter zetten
mySerial.print(F("Approx altitude = ")); //Woordje 'Approx altitude' doorgeven
mySerial.print(bmp.readAltitude(1023.75)); // this should be adjusted to your local forcase
mySerial.println(" m");
mySerial.println();
delay(500); //1 second delay
}
}
I hope somebody can help me with this question (ps. sorry if my English is bad :b)