Notifications
Clear all

how to code an I2C sensor and a "One Wire" sensor using an NRF24L01 and an arduino uno. the sensors are an AM2320 and DS18B20 to be transmitted to an other arduino uno , a NRF24L01 and a 4x20 LCD.

3 Posts
2 Users
0 Likes
1,500 Views
(@rapido)
Member
Joined: 4 years ago
Posts: 10
Topic starter  

I have a sketch for the AM2320 running on both the transmitter and the receiver. I have tried using separate "pipes" for each sensor because of the two different systems used eg. I2C and "One Wire", without success. 

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_AM2320.h>


Adafruit_AM2320 am2320;
RF24 radio(9,10);
const uint64_t address = 0xF0F0F0F0E1LL;
int counter = 0;
const int led_pin = 13;
struct MyData
{
int counter;
float temperature;
float humidity;
};
MyData data;

void setup()
{
Serial.begin(9600);
pinMode(led_pin,OUTPUT);
radio.begin();
radio.openWritingPipe(address);
radio.setChannel(105);
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_250KBPS);
radio.stopListening();


if (!am2320.begin())
{
Serial.println("Could not find a valid AM2315, check wiring!");
while (1);
}
}

void loop()
{
digitalWrite(led_pin,HIGH);
data.counter = counter;
data.temperature = am2320.readTemperature();
data.humidity = am2320.readHumidity();


Serial.print("Packet No. = ");
Serial.println(data.counter);

Serial.print("Temperature = ");
Serial.print(data.temperature);
Serial.println("*C");

Serial.print("Humidity = ");
Serial.print(data.humidity);
Serial.println("%");
Serial.println();

radio.write(&data,sizeof(MyData));

Serial.println("Data Packet Sent");
Serial.println("");
digitalWrite(led_pin, LOW);

counter++;
delay(3000);
}

What code do I need to add to the above to include the DS18B20 ?? I will also need to add to the receiver code which I will look at later.



 

   
Quote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2037
 

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

Hi robotBuilder. Thank you for coming back to me. I know I have been into both those sites and tried amalgamating the two sketches without success. Maybe I should have shown also the  "include and Define" parts of the sketch for the addition of the DS18B20. After that I do not know how to apply the code to the sketch for the AM2320. Also you may have noticed  there a mention of a AM2315 in code above. I found that I could use either sensor in the code as they are both I2C sensors with the same address, are interchangeable but not used together. The circuits I built are on  breadboards and get them working on the bench first. I feed the AM2320  to A4 and A5 for I2C with 2 10K resistors and D2 for the one wire circuit with a 4.7K resistor between Vcc and signal.

I tried to load the above code as per instructions of this site but it turned out as shown. Sorry for that but I am not great at all the ins and outs of modern computing facilities. Will I combine the two sketches as best I can and come back maybe you can indicate where I am going wrong. I am learning as I go and try to understand what is needed by reading the relevant section but a lot of the time I do not understand it. Please let me know what I need to do.


   
ReplyQuote