Hi everyone
I am newbie here .
I have a project of connecting sensor to arduino from a distance of about 100 mtr.
I am using BME280
and MHZ16
I am using NANO and MAX485 at Sensors with following code
#include <RS485.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include "SparkFunBME280.h"
BME280 mySensor;
char Message[maxMsgLen+1] ;
int pin = 5;
void setup() {
Serial.begin(9600);
pinMode(pin, INPUT);
if (mySensor.beginSPI(10) == false) //Begin communication over SPI. Use pin 10 as CS.
{
Serial.println("The sensor did not respond. Please check wiring.");
while(1); //Freeze
}
}
void loop() {
double duration = pulseIn(pin, HIGH);
double y = duration / 1000;
float z = y * 48;
const char resulth[8];
float h =mySensor.readFloatHumidity();
dtostrf(h, 6,2, resulth);
const char resultt[8];
float t = mySensor.readTempC();
dtostrf(t, 6,2,resultt);
const char resultc[8];
dtostrf(z, 6,2, resultc);
char buffer[strlen(resultc) + strlen(resultt) + strlen(resulth) +1];
sprintf(buffer, "%s,%s,%s", resultc, resultt, resulth);
Serial.println(buffer);
strcpy(Message,buffer);
if(RS485_SendMessage(Message,fWrite,ENABLE_PIN))
{
Serial.print("Sending:");
Serial.println(Message);
}
delay(1000);
}
At the other end I am using UNO r3 with this code
// Receive
#include <RS485.h>
#include <SoftwareSerial.h>
char message[maxMsgLen+3+1];
void setup()
{
Serial.begin(9600);
Serial.println("System Startup - Receiver");
RS485_Begin(28800);
}
void loop()
{
//if(RS485_ReadPlainMessage(fAvailable,fRead,message))
if(RS485_ReadMessage(fAvailable,fRead, message))
{
Serial.print("Receiving:");
Serial.println(message);
}
}
Nano is showing that it is sending data to RS485 and also on Serial Monitor
But UNO is not responding
If i use example code for sender then UNO start receiving data with Same wiring
I am using following Libraries
Sparkfun BME280
RS485-Arduino-Library-master
SparkFun_BME280_Arduino_Library-master
SPI
SOFTWARESERIAL
I have used following wiring at nano
//BME280 -> Arduino
// GND -> GND
// 3.3 -> 3.3
// CS -> 10
// SDI -> 11
// SDO -> 12
// SCK -> 13
// MAX485 NANO
// DI D2
// RO D3
// RE D4
// MHZ16 NANO
// PWM D5
and at the other end i have used this
//MAX485 ARDUINO
//DI D10
//RO D8
//RE D9
Thanks In Advance