Actually I found code that works better but I am still having trouble merging my code.
I have a second setup with an Arduino Uno and an rf24 and works ok sending the "hello worl" message from the code and I already have a VB6 program setup up to put the temp, humdity, and pressure values from the serial buffer and it works fine.
my problem is merging these codes and then changing the message transmitting the values recorded from the sensors
Working code for the rf24
/*
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>
const static uint8_t RADIO_ID = 1;
const static uint8_t DESTINATION_RADIO_ID = 0;
const static uint8_t PIN_RADIO_CE = 49;
const static uint8_t PIN_RADIO_CSN = 53;
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;
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;
}
void loop()
{
// 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);
}
And the working code for the BME280 sensor and the Photo Resistors
/*
BME280I2C Modes.ino
This code shows how to use predefined recommended settings from Bosch for
the BME280I2C environmental sensor.
GNU General Public License
Written: Dec 30 2015.
Last Updated: Sep 23 2017.
Connecting the BME280 Sensor:
Sensor -> Board
-----------------------------
Vin (Voltage In) -> 3.3V
Gnd (Ground) -> Gnd
SDA (Serial Data) -> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
*/
#include <BME280I2C.h>
#include <Wire.h> // Needed for legacy versions of Arduino.
#define SERIAL_BAUD 115200
/* Recommended Modes -
Based on Bosch BME280I2C environmental sensor data sheet.
Weather Monitoring :
forced mode, 1 sample/minute
pressure ×1, temperature ×1, humidity ×1, filter off
Current Consumption = 0.16 μA
RMS Noise = 3.3 Pa/30 cm, 0.07 %RH
Data Output Rate 1/60 Hz
Humidity Sensing :
forced mode, 1 sample/second
pressure ×0, temperature ×1, humidity ×1, filter off
Current Consumption = 2.9 μA
RMS Noise = 0.07 %RH
Data Output Rate = 1 Hz
Indoor Navigation :
normal mode, standby time = 0.5ms
pressure ×16, temperature ×2, humidity ×1, filter = x16
Current Consumption = 633 μA
RMS Noise = 0.2 Pa/1.7 cm
Data Output Rate = 25Hz
Filter Bandwidth = 0.53 Hz
Response Time (75%) = 0.9 s
Gaming :
normal mode, standby time = 0.5ms
pressure ×4, temperature ×1, humidity ×0, filter = x16
Current Consumption = 581 μA
RMS Noise = 0.3 Pa/2.5 cm
Data Output Rate = 83 Hz
Filter Bandwidth = 1.75 Hz
Response Time (75%) = 0.3 s
*/
BME280I2C::Settings settings(
BME280::OSR_X1,
BME280::OSR_X1,
BME280::OSR_X1,
BME280::Mode_Forced,
BME280::StandbyTime_1000ms,
BME280::Filter_Off,
BME280::SpiEnable_False,
0x76 // I2C address. I2C specific.
);
BME280I2C bme(settings);
//////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(SERIAL_BAUD);
while(!Serial) {} // Wait
Wire.begin();
while(!bme.begin())
{
Serial.println("Could not find BME280I2C sensor!");
delay(1000);
}
// bme.chipID(); // Deprecated. See chipModel().
switch(bme.chipModel())
{
case BME280::ChipModel_BME280:
Serial.println("Found BME280 sensor! Success.");
break;
case BME280::ChipModel_BMP280:
Serial.println("Found BMP280 sensor! No Humidity available.");
break;
default:
Serial.println("Found UNKNOWN sensor! Error!");
}
// Change some settings before using.
settings.tempOSR = BME280::OSR_X4;
bme.setSettings(settings);
}
//////////////////////////////////////////////////////////////////
void loop()
{
printBME280Data(&Serial);
delay(500);
}
//////////////////////////////////////////////////////////////////
void printBME280Data
(
Stream* client
)
{
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;
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);
float temp(NAN), hum(NAN), pres(NAN);
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_Pa);
bme.read(pres, temp, hum, tempUnit, presUnit);
client->print("Temp: ");
client->print(temp);
client->print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
client->print("\t\tHumidity: ");
client->print(hum);
client->print("% RH");
client->print("\t\tPressure: ");
client->print(pres);
client->print(" Pa");
client->print(" PR");
client->print("\t\tPR1A: ");
client->print(AnalogValue1);
client->print("\t\tPR2A: ");
client->print(AnalogValue2);
client->print("\t\tPR3A: ");
client->print(AnalogValue3);
client->print("\t\tPR4A: ");
client->print(AnalogValue4);
client->print("\t\tPR5A: ");
client->print(AnalogValue5);
client->print("\t\tPR1D: ");
client->print(DigitalValue1);
client->print("\t\tPR2D: ");
client->print(DigitalValue2);
client->print("\t\tPR3D: ");
client->print(DigitalValue3);
client->print("\t\tPR4D: ");
client->print(DigitalValue4);
client->print("\t\tPR5D: ");
client->print(DigitalValue5);
client->println(" ");
delay(1000);
}