Hey folks. I fly rockets and dabble in arduino. Im trying to code the three items to my arduino nano and insert them into my rocket to collect data. I used the code from "bmg1234"(member), to join the SD card and the adxl345.
i need to add the code for the BMP280. individually I can read them on the computer, but combining them on the sd card is too hard for me to figure out.
In an ideal world i would also have the altimeter trigger my pyro charge to release my chute.
Any help would be great.
How are people supposed to help you when you don't share your code? Post your best effort at trying to incorporate your BMP280 into your current code along with any error messages you may be getting and people can help.
Good point, thx for the posting tip. I tried to upload and it gave errors: did not recognize Serial.begin(9600) there may be more but I did not gt past that one error.
I tried to fuse the BMP sketch with the already working sketch of the SD and adxl345.
#include <SD.h> //Load SD card library
#include<SPI.h> //Load SPI Library
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp; // use I2C interface
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
#include "Wire.h" // imports the wire library for talking over I2C
int ADXL345 = 0x53; // The ADXL345 sensor I2C address
float X_out, Y_out, Z_out; // Outputs
int chipSelect = 4; //chipSelect pin for the SD card Reader
File AngleData; //Data object you will write your sesnor data to
void setup() {
Serial.begin(9600);
Serial.println(F("BMP280 Sensor event test"));
if (!bmp.begin()) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1) delay(10);
}
/* Default settings from datasheet. /
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, / Operating Mode. /
Adafruit_BMP280::SAMPLING_X2, / Temp. oversampling /
Adafruit_BMP280::SAMPLING_X16, / Pressure oversampling /
Adafruit_BMP280::FILTER_X16, / Filtering. /
Adafruit_BMP280::STANDBY_MS_500); / Standby time. */
bmp_temp->printSensorDetails();
}
Serial.begin(9600);//turn on serial monitor
//mySensor.begin(); //initialize pressure sensor mySensor
Wire.begin(); // Initiate the Wire library
// Set ADXL345 in measuring mode
Wire.beginTransmission(ADXL345); // Start communicating with the device
Wire.write(0x2D); // Access/ talk to POWER_CTL Register - 0x2D
// Enable measurement
Wire.write(8); // (8dec -> 0000 1000 binary) Bit D3 High for measuring enable
Wire.endTransmission();
delay(10);
pinMode(10, OUTPUT); //Must declare 10 an output and reserve it
SD.begin(4); //Initialize the SD card reader
}
void loop() {
sensors_event_t temp_event, pressure_event;
bmp_temp->getEvent(&temp_event);
bmp_pressure->getEvent(&pressure_event);
Serial.print(F("Temperature = "));
Serial.print(temp_event.temperature);
Serial.println(" *C");
Serial.print(F("Pressure = "));
Serial.print(pressure_event.pressure);
Serial.println(" hPa");
Serial.println();
}
delay(2000);
Wire.beginTransmission(ADXL345);
Wire.write(0x32);
Wire.endTransmission(false);
Wire.requestFrom(ADXL345, 6, true); // Read 6 registers total, each axis value is stored in 2 registers
X_out = ( Wire.read() | Wire.read() << 8); // X-axis value
X_out = X_out; //For a range of +-2g, we need to divide the raw values by 256, according to the datasheet
Y_out = ( Wire.read() | Wire.read() << 8); // Y-axis value
Y_out = Y_out;
Z_out = ( Wire.read() | Wire.read() << 8); // Z-axis value
Z_out = Z_out / 256;
AngleData = SD.open("PTData.txt", FILE_WRITE);
if (AngleData) {
Serial.print("X= ");
Serial.print(X_out);
Serial.print(" Y= ");
Serial.print(Y_out);
Serial.print(" Z= ");
Serial.println(Z_out);
delay(250); //Pause between readings.
AngleData.print(X_out);
AngleData.print(",");
AngleData.println(Y_out);
AngleData.print(",");
AngleData.println(Z_out);
AngleData.close(); //close the
}
}
Posting tip #2 - read the sticky post at the top of this forum and learn how to properly post your code inside code tags
so it looks like this
Again, it helps people help you. Please edit your reply and insert the code tags
Lots of error codes showed up by simply adding the BMP sketch from Adafruit. I have the BMP on order but I am trying to pre program the code for it. I've spent hours battling with this. I am following your site directions and read the forum steps to post code. Hope this works. ps: How can i quickly find my post and responses without a long search through all the topics? thx for giving me your time. Mark
#include <SD.h> //Load SD card library
#include<SPI.h> //Load SPI Library
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp; // use I2C interface
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
#include "Wire.h" // imports the wire library for talking over I2C
int ADXL345 = 0x53; // The ADXL345 sensor I2C address
float X_out, Y_out, Z_out; // Outputs
int chipSelect = 4; //chipSelect pin for the SD card Reader
File AngleData; //Data object you will write your sesnor data to
void setup() {
Serial.begin(9600);
Serial.println(F("BMP280 Sensor event test"));
if (!bmp.begin()) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1) delay(10);
}
/* Default settings from datasheet. */
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
bmp_temp->printSensorDetails();
}
Serial.begin(9600);//turn on serial monitor
//mySensor.begin(); //initialize pressure sensor mySensor
Wire.begin(); // Initiate the Wire library
// Set ADXL345 in measuring mode
Wire.beginTransmission(ADXL345); // Start communicating with the device
Wire.write(0x2D); // Access/ talk to POWER_CTL Register - 0x2D
// Enable measurement
Wire.write(8); // (8dec -> 0000 1000 binary) Bit D3 High for measuring enable
Wire.endTransmission();
delay(10);
pinMode(10, OUTPUT); //Must declare 10 an output and reserve it
SD.begin(4); //Initialize the SD card reader
}
void loop() {
sensors_event_t temp_event, pressure_event;
bmp_temp->getEvent(&temp_event);
bmp_pressure->getEvent(&pressure_event);
Serial.print(F("Temperature = "));
Serial.print(temp_event.temperature);
Serial.println(" *C");
Serial.print(F("Pressure = "));
Serial.print(pressure_event.pressure);
Serial.println(" hPa");
Serial.println();
}
delay(2000);
Wire.beginTransmission(ADXL345);
Wire.write(0x32);
Wire.endTransmission(false);
Wire.requestFrom(ADXL345, 6, true); // Read 6 registers total, each axis value is stored in 2 registers
X_out = ( Wire.read() | Wire.read() << 8); // X-axis value
X_out = X_out; //For a range of +-2g, we need to divide the raw values by 256, according to the datasheet
Y_out = ( Wire.read() | Wire.read() << 8); // Y-axis value
Y_out = Y_out;
Z_out = ( Wire.read() | Wire.read() << 8); // Z-axis value
Z_out = Z_out / 256;
AngleData = SD.open("PTData.txt", FILE_WRITE);
if (AngleData) {
Serial.print("X= ");
Serial.print(X_out);
Serial.print(" Y= ");
Serial.print(Y_out);
Serial.print(" Z= ");
Serial.println(Z_out);
delay(250); //Pause between readings.
AngleData.print(X_out);
AngleData.print(",");
AngleData.println(Y_out);
AngleData.print(",");
AngleData.println(Z_out);
AngleData.close();
//close the
}
}
Arduino: 1.8.12 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"
adxl_sd_bmp_al_code_combined:38:2: error: 'Serial' does not name a type
Serial.begin(9600);//turn on serial monitor
^~~~~~
adxl_sd_bmp_al_code_combined:40:1: error: 'Wire' does not name a type
Wire.begin(); // Initiate the Wire library
^~~~
adxl_sd_bmp_al_code_combined:42:1: error: 'Wire' does not name a type
Wire.beginTransmission(ADXL345); // Start communicating with the device
^~~~
adxl_sd_bmp_al_code_combined:43:1: error: 'Wire' does not name a type
Wire.write(0x2D); // Access/ talk to POWER_CTL Register - 0x2D
^~~~
adxl_sd_bmp_al_code_combined:45:1: error: 'Wire' does not name a type
Wire.write(8); // (8dec -> 0000 1000 binary) Bit D3 High for measuring enable
^~~~
adxl_sd_bmp_al_code_combined:46:1: error: 'Wire' does not name a type
Wire.endTransmission();
^~~~
adxl_sd_bmp_al_code_combined:47:6: error: expected constructor, destructor, or type conversion before '(' token
delay(10);
^
adxl_sd_bmp_al_code_combined:48:8: error: expected constructor, destructor, or type conversion before '(' token
pinMode(10, OUTPUT); //Must declare 10 an output and reserve it
^
adxl_sd_bmp_al_code_combined:49:1: error: 'SD' does not name a type; did you mean 'SDA'?
SD.begin(4); //Initialize the SD card reader
^~
SDA
adxl_sd_bmp_al_code_combined:50:1: error: expected declaration before '}' token
}
^
Multiple libraries were found for "SD.h"
Used: C:\Program Files (x86)\Arduino\libraries\SD
Not used: C:\Users\mwatson\Documents\Arduino\libraries\SD-1.2.4
exit status 1
'Serial' does not name a type
Invalid library found in C:\Users\mwatson\Documents\Arduino\libraries\blink_9_on_1_off: no headers files (.h) found in C:\Users\mwatson\Documents\Arduino\libraries\blink_9_on_1_off
Invalid library found in C:\Users\mwatson\Documents\Arduino\libraries\blink_9_on_1_off: no headers files (.h) found in C:\Users\mwatson\Documents\Arduino\libraries\blink_9_on_1_off
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
You can't have code outside of a function. If you look at the indentation of your code you will see lots of function calls, etc. outside setup() and loop(). It needs to be inside those functions
#include <SD.h> //Load SD card library
#include<SPI.h> //Load SPI Library
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp; // use I2C interface
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
#include "Wire.h" // imports the wire library for talking over I2C
int ADXL345 = 0x53; // The ADXL345 sensor I2C address
float X_out, Y_out, Z_out; // Outputs
int chipSelect = 4; //chipSelect pin for the SD card Reader
File AngleData; //Data object you will write your sesnor data to
void setup() {
Serial.begin(9600);
Serial.println(F("BMP280 Sensor event test"));
if (!bmp.begin()) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1) delay(10);
}
/* Default settings from datasheet. */
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
bmp_temp->printSensorDetails();
//mySensor.begin(); //initialize pressure sensor mySensor
Wire.begin(); // Initiate the Wire library
// Set ADXL345 in measuring mode
Wire.beginTransmission(ADXL345); // Start communicating with the device
Wire.write(0x2D); // Access/ talk to POWER_CTL Register - 0x2D
// Enable measurement
Wire.write(8); // (8dec -> 0000 1000 binary) Bit D3 High for measuring enable
Wire.endTransmission();
delay(10);
pinMode(10, OUTPUT); //Must declare 10 an output and reserve it
SD.begin(4); //Initialize the SD card reader
}
void loop() {
sensors_event_t temp_event, pressure_event;
bmp_temp->getEvent(&temp_event);
bmp_pressure->getEvent(&pressure_event);
Serial.print(F("Temperature = "));
Serial.print(temp_event.temperature);
Serial.println(" *C");
Serial.print(F("Pressure = "));
Serial.print(pressure_event.pressure);
Serial.println(" hPa");
Serial.println();
delay(2000);
Wire.beginTransmission(ADXL345);
Wire.write(0x32);
Wire.endTransmission(false);
Wire.requestFrom(ADXL345, 6, true); // Read 6 registers total, each axis value is stored in 2 registers
X_out = ( Wire.read() | Wire.read() << 8); // X-axis value
X_out = X_out; //For a range of +-2g, we need to divide the raw values by 256, according to the datasheet
Y_out = ( Wire.read() | Wire.read() << 8); // Y-axis value
Y_out = Y_out;
Z_out = ( Wire.read() | Wire.read() << 8); // Z-axis value
Z_out = Z_out / 256;
AngleData = SD.open("PTData.txt", FILE_WRITE);
if (AngleData) {
Serial.print("X= ");
Serial.print(X_out);
Serial.print(" Y= ");
Serial.print(Y_out);
Serial.print(" Z= ");
Serial.println(Z_out);
delay(250); //Pause between readings.
AngleData.print(X_out);
AngleData.print(",");
AngleData.println(Y_out);
AngleData.print(",");
AngleData.println(Z_out);
AngleData.close();
}
}
Hi Karma. I tried to learn about the function calls but am unable to sort it out. is it a huge fix or a simple one for a knowledgeable Arduino person? Can you fix this for a fee or do you know a member who can do this for me? My battle continues. My rockets are grounded until I sort this out. Mark