Yesterday some very nice people in the forum helped me with a code for displaying the temperature and pressure data at the same time using java. Thanks to them I managed to do that successfully with arduino uno. Today, my objective was displaying this data in a LCD monitor and for this, I am using arduino Mega 2560, the code is good because when I switch to arduino uno, it works and apparently the arduino Mega is also fine because when I put another code (for example, just for temperature using the thermistor), it displays the values in the serial monitor. Can someone help me? Why I cant display the data with this code on the serial monitor? The uploading is fine
Code:
#include <Wire.h>
#include "Seeed_BMP280.h"
BMP280 bmp280;
#define analogPin A0 //the thermistor attach to
#define beta 3950 //the beta of the thermistor
#define resistance 10 //the value of the pull-up resistor
void setup() {
Serial.begin(9600);
if(!bmp280.init())
Serial.println("Device error!");
}
void loop() {
long a =1023 - analogRead(analogPin);
int sensor1 = beta /(log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 273.0;
float c = (bmp280.getPressure());
unsigned long sensor2 = c;
char text [40];
sprintf (text, "%d, %lu\n", sensor1, sensor2);
Serial.println (text);
delay (500);
}
Adding more Serial.print() statements might give you a clue what is happening. I suspect that you simply are not getting to the Serial.print() statement, because the I2C device is not connected to the Mega correctly. The Mega uses different pins from the Uno, for I2C.
Adding more Serial.print() statements might give you a clue what is happening. I suspect that you simply are not getting to the Serial.print() statement, because the I2C device is not connected to the Mega correctly. The Mega uses different pins from the Uno, for I2C.
How to you suggest me to solve this problem then? Sorry I am really new in programming and stuff ahah. I started 4 days ago
Adding more Serial.print() statements might give you a clue what is happening. I suspect that you simply are not getting to the Serial.print() statement, because the I2C device is not connected to the Mega correctly. The Mega uses different pins from the Uno, for I2C.
Ok done!!! Thank you so much!! I searched the pins for arduino Mega and it were digital 21 and 20 instead of the A4 and A5 of the uno for the barometer. Thank you so much again!!!
thank you again guys!! Do you know where can I learn all this stuff? There are some books, or nice sites, or even youtube channels with all these subjects?
Arduino is programed with C++, so some time spent on a C++ tutorial would help with the basics, such as different variable types. No need to go too deeply into it though - it's unlikely that you'll be writing your own classes early on.
This site has a decent reference for Arduino specific stuff, not so much for C++ because there's plenty of other places to get that information.
wildbill:
Arduino is programed with C++, so some time spent on a C++ tutorial would help with the basics, such as different variable types. No need to go too deeply into it though - it's unlikely that you'll be writing your own classes early on.
This site has a decent reference for Arduino specific stuff, not so much for C++ because there's plenty of other places to get that information.