Notifications
Clear all

using an AM2315 sensor with the nRF24L01 and Arduino

8 Posts
2 Users
0 Likes
795 Views
(@rapido)
Member
Joined: 4 years ago
Posts: 10
Topic starter  

Has anyone a sketch that works with the above configuration?


   
Quote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 
Posted by: @rapido

Has anyone a sketch that works with the above configuration?

Can you describe the problem you're experiencing?

Does it compile without errors?
If not, what were they?

Are you able to post your code and describe exactly what it's not doing, vs what you expect it to be doing?


   
ReplyQuote
(@rapido)
Member
Joined: 4 years ago
Posts: 10
Topic starter  

Hi Frogandtoad. Thank you for replying. The problem is that on the serial monitor when in the transmit sketch I get a temperature reading but get "nan" for the humidity. The same applies to the receiver sketch on the display which is an I2C 20X04 line LCD. I am using code for BME280 which works fine and I adapted for the AM2315. I feel that the problem is with the reading of the sensor in the transmitter sketch and both sensors are I2C ,but is the coding for the AM2315 different from the BME280.


   
ReplyQuote
(@rapido)
Member
Joined: 4 years ago
Posts: 10
Topic starter  

Hi frogandtoad. Further to your response to my request for help with AM2315 coding the following is the transmitter sketch:

#include <SPI.h>

#include<Wire.h>

#include<Adafruit__Sensor.h>

#include<Adafruit_ AM2315.h>

#include<nRF24L01.h>

#include<RF24.h>

RF24 radio(9,10); //CE,CSN

const uint64_t address = 0xF0F0F0F0E1LL;

int counter = 0;

float temperature;

float humidity;

Adafruit_AM2315 am2315;

struct MyData {

int counter;

float temperature;

float humidity;

};

MyData data;

void setup() {

serial.begin(9600);

radio.begin();

radio.openWritingPipe(address);

etc.

I have looked at the " test sketch" for AM2315 which is in the Arduino IDE and it sets up the AM2315 differently. The sketch runs fine for me but I am unable to apply it to the above sketch to read the sensor properly and also to read the data at the receiver end. In the" am2315 test" sketch, in the "void loop" section

void loop() {

float temperature, humidity;

if (!am2315 readTemperatureAndHumidity(&temperature,&humidity)) {

Serial.println("Failed to read data from AM2315");

return;

}

serial.print("Temp *C: "); Serial.println(temperature);

Serial.print("Hum %: "); Serial.println(humidity);

delay(2000);

I have tried to use this in my sketch but without success. I am only learning by both reading and trying out what I think will work but obviously not enough knowledge of the subject.

 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@rapido

First things first... I don't know if that's an error in pasting, because you didn't provide the complete code, and I have to make guesses 🙂

1) C and C++ are case sensitive languages 'serial' is not the same as 'Serial'

2) The last three statements in your code are outside of the scope of the loop() function (after it)

3) Again, you've cut out the important bits, so I'll just have to guess that you first called "am2315.begin()"

Assuming everything else is correct, then you probably want to do something like the following:

void loop()
{
float temperature, humidity;
if (!am2315 readTemperatureAndHumidity(&temperature, &humidity)) {
Serial.println("Failed to read data from AM2315");
return;
}

// Somewhere after humidity and temperature have been obtained
data.humidity = humidity;
data.temperature = temperature;

// Now that the object data has been populated, send the object to the receiver
bool result radio.write(&datasizeof(data));
}
Cheers.

   
ReplyQuote
(@rapido)
Member
Joined: 4 years ago
Posts: 10
Topic starter  

Hi frogandtoad. Thank you for your help. I have succeeded in getting the remote transmitter working and the receiver also thanks to the information you supplied. To answer your points

1. the "serial" was a typing error on my part as I typed in the part of the first sketch, because I failed to successfully cut and paste the whole sketch.

2. Yes I now see the three lines are outside the loop function so I brought them inside the loop.

3 . Yes I have "am2315.begin()" in the sketch but left it out in excerpt I sent to you.

After adding the lines you sent me the system worked straight away. I will now tidy up the code as I have some lines in there that are not necessary.

Again thank you very much for your time and information that sorted the problem for me. I now plan to add a DS18B20 temperature as a ground temperature sensor, and after that wind direction and speed sensors. all on the outdoor remote system and add a BME280 indoors to give indoor temperature, humidity and pressure readings. I don't know how long that will take but I have the next few months to try and progress the system.

Happy new year.


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@rapido

Posted by: @rapido

After adding the lines you sent me the system worked straight away. I will now tidy up the code as I have some lines in there that are not necessary.

Again thank you very much for your time and information that sorted the problem for me.

Glad to have been able to help, and thanks for letting me know.

Cheers.


   
ReplyQuote
(@rapido)
Member
Joined: 4 years ago
Posts: 10
Topic starter  

Hi All. I now want to add a ds18b20 to the AM2315 with the nrf24l01 and arduino. I have now an ATmega 328p with the AM2315 attached and the sketch running and would like to add a ds18b20 as a ground temperature sensor. I think it can be done using a single pipe but how to code both sensors  so that the data will be sent by the nrf24l01 and how to decode it at the receiver.

any help would be appreciated.

rapido.


   
ReplyQuote