Manchester library + Photon +DHT22 +433Mhz Tx/Rx module

Greetings and love from Berlin. I am am new to particle and tying to build this app. However, I cannot really figure it out how to get serial value on the receiver side. Please note that the sensor is working perfectly without the RF setup. Million thanks in advance. :smile:

Transmitter Code:

/**/ This #include statement was automatically added by the Particle IDE.**
**#include "Manchester/Manchester.h"**
**// This #include statement was automatically added by the Particle IDE.**
**#include "SparkIntervalTimer/SparkIntervalTimer.h"**
**// This #include statement was automatically added by the Particle IDE.**
**#include "Adafruit_DHT/Adafruit_DHT.h"**
**// This #include statement was automatically added by the Particle IDE.**
**#include "Adafruit_Sensor/Adafruit_Sensor.h"**

**#define TX_PIN D1  //pin where your transmitter is connected**
**#define DHTPIN D0     // what pin we're connected to**

**#define DHTTYPE DHT22		// DHT 22 (AM2302)**

DHT dht(DHTPIN, DHTTYPE);

void setup() {
	Serial.begin(9600); 
	Serial.println("DHTxx test!");

	dht.begin();
	
	man.setupTransmit(TX_PIN, MAN_1200);
}

void loop() {
// must be some code for manchester library ??

// Read humidity
	float h = dht.getHumidity();
// Read temperature as Celsius
	float t = dht.getTempCelcius();
// Read temperature as Farenheit
	float f = dht.getTempFarenheit();
  
// Check if any reads failed and exit early (to try again).
	if (isnan(h) || isnan(t) || isnan(f)) {
		Serial.println("Failed to read from DHT sensor!");
		return;
	}
// Compute heat index
// Must send in temp in Fahrenheit!
	float hi = dht.getHeatIndex();
	float dp = dht.getDewPoint();
	float k = dht.getTempKelvin();

	Serial.print("Humid: "); 
	Serial.print(h);
	Serial.print("% - ");
	Serial.print("Temp: "); 
	Serial.print(t);
	Serial.print("*C ");
	Serial.print(f);
	Serial.print("*F ");
	Serial.print(k);
	Serial.print("*K - ");
	Serial.print("DewP: ");
	Serial.print(dp);
	Serial.print("*C - ");
	Serial.print("HeatI: ");
	Serial.print(hi);
	Serial.println("*C");
	Serial.println(Time.timeStr());
}

Receiver Code :

**// This #include statement was automatically added by the Particle IDE.**
**#include <Manchester.h>**

**// This #include statement was automatically added by the Particle IDE.**
**#include <SparkIntervalTimer.h>**

**#define RX_PIN	D0	//pin where your receiver is connected**

void setup() {
    man.setupReceive(RX_PIN, MAN_1200);
    man.beginReceive();
}

void loop() {
    if (man.receiveComplete()) {
    uint16_t m = man.getMessage();
    man.beginReceive(); //start listening for next message right after you retrieve the message
    delay(200);
}

@kazi93, you need to try out the examples first. The send and receive functions are designed to send a 16bit number or an array of bytes. They are not written for “float” or other types. You will need to convert your 4 byte float into an array of bytes, send it and then on the receiver end, rebuild the float using the array of received bytes. Another way is to convert the values to text characters in an array (a string) and send the array. The receive end then takes that array of received characters and can print it out. :wink:

2 Likes

@kazi93 If your willing to use the RFM95 radio modules like these then I have code that allows you to communicate to a Photon or Electron over the Serial TX RX lines.

If you have the RFM69 modules I think there is a working library on the forum already.

1 Like

Are you aware of the function printlnf? You can replace all of the above with one line,

Serial.printlnf("Humid: %f%% - Temp: %f*C %f*F %f*K - DewP: %f*C - HeatI: %f*C", h,t,f,k,dp,hi);
3 Likes

Hi! Greetings again. I have tried with the Sparkfun library and flashed successfully by particle web IDE. However, on the receiver serial it shows Humid:0 ; Temp 0. Waiting for your valuable feedback. Million thanks in advance. :smile:

Transmitter code:

// This #include statement was automatically added by the Particle IDE.
#include <SparkFunRHT03.h>

// This #include statement was automatically added by the Particle IDE.
#include "Manchester.h"

// This #include statement was automatically added by the Particle IDE.
#include <SparkIntervalTimer.h>
/////////////////////
#define TX_PIN D1  //pin where transmitter is connected to particle photon**
#define DHT22_PIN D0     // DHT22 data pin is connected to particle photon**

//variables
RHT03 rht;
float h=0;
float t=0;
int transmit_t = 0;
int transmit_h = 0;
int transmit_data = 0;

void setup()
{
  Serial.begin(115200);
  man.setupTransmit(TX_PIN, MAN_1200);
	
}

void loop()
{
/*	// Call rht.update() to get new humidity and temperature values from the sensor.
	int updateRet = rht.update();
	
	// If successful, the update() function will return 1.
	// If update fails, it will return a value <0
	if (updateRet == 1)
	{
		// The humidity(), tempC(), and tempF() functions can be called -- after 
		// a successful update() -- to get the last humidity and temperature
		// value 
		float latestHumidity = rht.humidity();
		float latestTempC = rht.tempC();
		float latestTempF = rht.tempF();
		
		// Now print the values:
		Serial.println("Humidity: " + String(latestHumidity, 1) + " %");
		Serial.println("Temp (F): " + String(latestTempF, 1) + " deg F");
		Serial.println("Temp (C): " + String(latestTempC, 1) + " deg C");
		

	}
	else
	{
		// If the update failed, try delaying for RHT_READ_INTERVAL_MS ms before
		// trying again.
		delay(RHT_READ_INTERVAL_MS);
	}
*/
        transmit_h=100* (int) h;
        transmit_t=(int) t;
        transmit_data=transmit_h+transmit_t;
  
        man.transmit(transmit_data);
  
        delay(1000);
}

Receiver code:

// This #include statement was automatically added by the Particle IDE.
#include "Manchester.h"

// This #include statement was automatically added by the Particle IDE.
#include <SparkIntervalTimer.h>
#define RX_PIN D0 // where Rx antenna is connected to particle Photon

void setup() {
  //lcd.begin(16,2); 
  //lcd.home();
  man.setupReceive(RX_PIN, MAN_1200);
  man.beginReceive();
}

void loop() {
  if (man.receiveComplete()) {
    uint16_t m = man.getMessage();
    man.beginReceive(); 
    
    Serial.print("Humid: ");         
    Serial.println(m/100);           
  
    Serial.print("Temp ");
    Serial.println(m%100);

   }
}

Why do you have all the rht code commented out? Are you getting zeros when you uncomment that?

Try another RX pin.
I’m not sure if interrupts are used in the lib, but D0 & A5 are not supporting interrupts.

You failed to call rht.begin(D0) which you should have in setup. It looks like the library does not use interrupts, so D0 should be ok. The begin(int dataPin) function sets the device’s data pin, so you need to call that.

2 Likes

@Ric
@ScruffR
Thank you´for your prompt reply.
I have added below code in setup function and uncommented the codes too. The library does not use interrupts.
// Call rht.begin() to initialize the sensor and our data pin
rht.begin(DHT22_PIN);

Please note that I have below serial data on the Transmitter side :
Humidity: 20.7 %
Temp (F): 77.2 deg F
Temp ©: 25.1 deg C

Am I calling the float variable twice or it is OK as it would be decoded to the receiver side? I am trying with my little knowledge, hope to improve soon. :smile:

Million thanks and beers for all of you while in Berlin. Cheers! :beer:

You have a problem in your code. Inside the if statement, you set the return values of the rht functions to 3 local variables, but you’re transmitting values based on the global variables t and h which you set to 0 when you declare them. You probably also want to move the transmit code to inside the if clause, since you shouldn’t transmit if the update failed.

void loop()
{
    // Call rht.update() to get new humidity and temperature values from the sensor.
    int updateRet = rht.update();
	
    // If successful, the update() function will return 1.
    // If update fails, it will return a value <0
    if (updateRet == 1)
    {
        // The humidity(), tempC(), and tempF() functions can be called -- after 
        // a successful update() -- to get the last humidity and temperature
        // value 
        h = rht.humidity();
	t = rht.tempC();
	float latestTempF = rht.tempF();
		
	// Now print the values:
	Serial.println("Humidity: " + String(h, 1) + " %");
        Serial.println("Temp (F): " + String(latestTempF, 1) + " deg F");
        Serial.println("Temp (C): " + String(t, 1) + " deg C");
	transmit_h=100* (int) h;
        transmit_t=(int) t;
        transmit_data=transmit_h+transmit_t;
        man.transmit(transmit_data);
    }
    else
    {
        // If the update failed, try delaying for RHT_READ_INTERVAL_MS ms before
	// trying again.
	delay(RHT_READ_INTERVAL_MS);
    }
        delay(1000);
}
3 Likes