Please forgive what I'm sure will be a stupid question. I'm an Arduino newbie working on my first project. I have some VB6 programming experience but no C+ experience at all so the syntax and formatting throws me off.
I'm trying to merge the BME280test and the NRFLITE Dynamic TX library examples to make a temp sensor I can put outside to radio the info inside.
I merged the code in what made the best sense to me but when I try to upload it to the Mega i get a message that reads " 'printValues' was not declared in this scope" and I don't know why.
(I also want to add Photoresistors for Sun Tracking - that is addressed after the problem code. That code works and I can merge it with the BME280 code so if I can merge the BME280 and MRFLITE codes I'll be able to merge that code without problem)
Someone please enlighten my to my ignorance. Code follows:
/*
Demonstrates sending data packets of different length. The receiver will check to see what size of
packet was received and act accordingly.
Radio Arduino
CE -> 9
CSN -> 10 (Hardware SPI SS)
MOSI -> 11 (Hardware SPI MOSI)
MISO -> 12 (Hardware SPI MISO)
SCK -> 13 (Hardware SPI SCK)
IRQ -> No connection
VCC -> No more than 3.6 volts
GND -> GND
*/
#include <SPI.h>
#include <NRFLite.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)
const static uint8_t RADIO_ID = 1;
const static uint8_t DESTINATION_RADIO_ID = 0;
const static uint8_t PIN_RADIO_CE = 9;
const static uint8_t PIN_RADIO_CSN = 10;
struct RadioPacket1
{
uint8_t FromRadioId;
uint8_t Counter;
};
struct RadioPacket2
{
uint8_t FromRadioId;
char Message[31]; // Note the max packet size is 32, so 31 is all we can use here.
};
NRFLite _radio;
RadioPacket1 _radioData1;
RadioPacket2 _radioData2;
Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
unsigned long delayTime;
void setup()
{
Serial.begin(115200);
if (!_radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN))
{
Serial.println("Cannot communicate with radio");
while (1); // Wait here forever.
}
_radioData1.FromRadioId = RADIO_ID;
_radioData2.FromRadioId = RADIO_ID;
Serial.println(F("BME280 test"));
bool status;
// default settings
// (you can also pass in a Wire library object like &Wire2)
status = bme.begin();
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
Serial.println("-- Default Test --");
delayTime = 1000;
Serial.println();
}
void loop()
{
printValues();
delay(delayTime);
void printValues() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.println();
// Pick a number from 10,000 - 60,000.
uint16_t randomNumber = random(10000, 60001);
if (randomNumber > 30000)
{
// Send RadioPacket1.
_radioData1.Counter++;
Serial.print("Sending ");
Serial.print(_radioData1.Counter);
if (_radio.send(DESTINATION_RADIO_ID, &_radioData1, sizeof(_radioData1)))
{
Serial.println("...Success");
}
else
{
Serial.println("...Failed");
}
}
else
{
// Send RadioPacket2.
// Create a message and assign it to the packet.
// Strings need to be converted to a char array and note they cannot be longer
// than 31 characters since that is the size of _radioData2.Message.
String msg = "Hello " + String(randomNumber);
msg.toCharArray(_radioData2.Message, msg.length() + 1);
Serial.print("Sending '");
Serial.print(msg);
Serial.print("'");
if (_radio.send(DESTINATION_RADIO_ID, &_radioData2, sizeof(_radioData2)))
{
Serial.println("...Success");
}
else
{
Serial.println("...Failed");
}
}
delay(1000);
}
this is the Photoresistor set code that I will want to merge with the code above. I can merge it with the BME280 code (below) and it works so if I can merge the BME280 and radio code (above) if I can get them to work
/***************************************************************************
This is a library for the BME280 humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BME280 Breakout
----> http://www.adafruit.com/products/2650
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface. The device's I2C address is either 0x76 or 0x77.
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
***************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
unsigned long delayTime;
void setup() {
Serial.begin(9600);
Serial.println(F("BME280 test"));
bool status;
// default settings
// (you can also pass in a Wire library object like &Wire2)
status = bme.begin();
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
Serial.println("-- Default Test --");
delayTime = 1000;
Serial.println();
}
void loop() {
printValues();
delay(delayTime);
}
unsigned int AnalogValue1;
unsigned int AnalogValue2;
unsigned int AnalogValue3;
unsigned int AnalogValue4;
unsigned int AnalogValue5;
unsigned int DigitalValue1;
unsigned int DigitalValue2;
unsigned int DigitalValue3;
unsigned int DigitalValue4;
unsigned int DigitalValue5;
void printValues() {
AnalogValue1 = analogRead(A0);
AnalogValue2 = analogRead(A1);
AnalogValue3 = analogRead(A2);
AnalogValue4 = analogRead(A3);
AnalogValue5 = analogRead(A4);
DigitalValue1 = analogRead(2);
DigitalValue2 = analogRead(3);
DigitalValue3 = analogRead(4);
DigitalValue4 = analogRead(5);
DigitalValue5 = analogRead(6);
Serial.println(AnalogValue1);
Serial.println(AnalogValue2);
Serial.println(AnalogValue3);
Serial.println(AnalogValue4);
Serial.println(AnalogValue5);
Serial.print("PRsA");
Serial.println(DigitalValue1);
Serial.println(DigitalValue2);
Serial.println(DigitalValue3);
Serial.println(DigitalValue4);
Serial.println(DigitalValue5);
Serial.print("PRsD");
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.println();
}