Currently I’m trying to set up a multi-node thermostat system to try and better conserve energy and more importantly lower utility bill and add some other useful sensors and fancy electronics, which I’ll explain later but right now I’m at a bit of a hang up on the basic and initial part.
I have an RHT03 and I’m trying to get it to read out correctly using a FreeSoC mini board, so far I have gotten EVERYTHING to work correctly with the exception of 2 things, the 1st is the negative values, I don’t have a way on hand to make the sensor try to read negative tempuratures, the second is the main issue even though my RH and TMP readings are good my checksums do NOT match up, and I’m not sure what I have done wrong.
/* ========================================
*
* Copyright YOUR COMPANY, THE YEAR
* All Rights Reserved
* UNPUBLISHED, LICENSED SOFTWARE.
*
* CONFIDENTIAL AND PROPRIETARY INFORMATION
* WHICH IS THE PROPERTY OF your company.
*
* ========================================
*/
#include <project.h>
#include <BitCheck.h>
uint8 URh, LRh,UTmp, LTmp;
int Cs;
int16 Rh8, TmpC8, TmpF8, Rh16, TmpC16, TmpF16, CCS, RH, TMP;
int main()
{
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
Clock_1_Enable(); //Enable Comm_poll clock set for 10KHz
Comm_Poll_Start(); //Start PWM Comm_Poll to hold high for 2sec and low for 1ms
Display_Start(); //Start UART with only TX (since thats all I care about ATM)
BitClock_Enable(); //Enable Block at 1MHz to be used with LowBitTimer/DataBits/CommStart
//to filter sort the different pulse lengths
LowBitTimer_Start(); //Detects pulses under 30ms
DataBits_Start(); //Detects all pulses
CommStart_Start(); //Detects on a very brief pulse at start of RHT03 signal
UpperRh_Start(); //Start Relative humiditys upeer 8-bit shift register
LowerRh_Start(); //RH lower 8-bit shift register
UpperTmp_Start(); //Start Tempurature upper 8-bit shift register
LowerTmp_Start(); //TMP lower 8-bit shift register
CheckSum_Start(); //Start Checksum 8-bit shift register
RH_Start(); //Start Relative humiditys 16-bit shift register
TMP_Start(); //Start Temperature 16-bit shift register
//CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */
for(;;)
{
URh=UpperRh_ReadRegValue(); //read RH upper 8-bit
LRh=LowerRh_ReadRegValue(); //read RH lower 8-bit
UTmp=UpperTmp_ReadRegValue(); //read TMP upper 8-bit
LTmp=LowerTmp_ReadRegValue(); //read TMP lower 8-bit
Cs=CheckSum_ReadRegValue(); //read checksum 8-bit
RH=RH_ReadRegValue(); //read RH 16-bit
TMP=TMP_ReadRegValue(); //read TMP 16-bit
Rh8=URh+LRh; //8-bit RH = upper + lower
TmpC8=UTmp+LTmp; //8-bit TMP(celsius) = upper + lower
TmpF8=((TmpC8/10)*9/5+32)*10; //8-bit TMP(farheniet) = conversion equation
Rh16=RH; //16-bit RH = its register
TmpC16=TMP; //16-bit TMP = its register
TmpF16=((TmpC16/10)*9/5+32)*10; //same conversion equation just for 16bit
CCS=(URh+LRh+UTmp+LTmp); //Checksum validation each 8-bit value added together
Display_PutChar((URh/100)+48); //just my way of getting character
//output from an integer
Display_PutChar(((URh/10)-(URh/100)*10)+48);
Display_PutChar(((URh/1)-(URh/10)*10)+48);
Display_PutString(","); //delimiters
Display_PutChar((LRh/100)+48);
Display_PutChar(((LRh/10)-(LRh/100)*10)+48);
Display_PutChar(((LRh/1)-(LRh/10)*10)+48);
Display_PutString(",");
Display_PutChar((UTmp/100)+48);
Display_PutChar(((UTmp/10)-(UTmp/100)*10)+48);
Display_PutChar(((UTmp/1)-(UTmp/10)*10)+48);
Display_PutString(",");
Display_PutChar((LTmp/100)+48);
Display_PutChar(((LTmp/10)-(LTmp/100)*10)+48);
Display_PutChar(((LTmp/1)-(LTmp/10)*10)+48);
Display_PutString(",");
Display_PutChar((Cs/100)+48);
Display_PutChar(((Cs/10)-(Cs/100)*10)+48);
Display_PutChar(((Cs/1)-(Cs/10)*10)+48);
Display_PutCRLF(0);
Display_PutString(" "); //makes the calculated checksum
//appear below captured
Display_PutChar((CCS/100)+48);
Display_PutChar(((CCS/10)-(CCS/100)*10)+48);
Display_PutChar(((CCS/1)-(CCS/10)*10)+48);
Display_PutCRLF(0);
Display_PutString("Rh "); // display RH as a precision value
Display_PutChar((Rh16/100)+48);
Display_PutChar(((Rh16/10)-(Rh16/100)*10)+48);
Display_PutString(".");
Display_PutChar(((Rh16/1)-(Rh16/10)*10)+48);
Display_PutString("%");
Display_PutCRLF(0);
Display_PutChar((TmpC16/100)+48);
Display_PutChar(((TmpC16/10)-(TmpC16/100)*10)+48);
Display_PutString(".");
Display_PutChar(((TmpC16/1)-(TmpC16/10)*10)+48);
Display_PutString("C/");
Display_PutChar((TmpF16/100)+48);
Display_PutChar(((TmpF16/10)-(TmpF16/100)*10)+48);
Display_PutString(".");
Display_PutChar(((TmpF16/1)-(TmpF16/10)*10)+48);
Display_PutString("F");
Display_PutCRLF(0);
Display_PutString("Rh ");
Display_PutChar((Rh8/100)+48);
Display_PutChar(((Rh8/10)-(Rh8/100)*10)+48);
Display_PutString(".");
Display_PutChar(((Rh8/1)-(Rh8/10)*10)+48);
Display_PutString("%");
Display_PutCRLF(0);
Display_PutChar((TmpC8/100)+48);
Display_PutChar(((TmpC8/10)-(TmpC8/100)*10)+48);
Display_PutString(".");
Display_PutChar(((TmpC8/1)-(TmpC8/10)*10)+48);
Display_PutString("C/");
Display_PutChar((TmpF8/100)+48);
Display_PutChar(((TmpF8/10)-(TmpF8/100)*10)+48);
Display_PutString(".");
Display_PutChar(((TmpF8/1)-(TmpF8/10)*10)+48);
Display_PutString("F");
Display_PutCRLF(0);
CyDelay(2000); //software pause for 2 seconds
}
}
/* [] END OF FILE */
I realize very few people would have experience with the setup I am using but so far its just the same as asny other 8-32bit micro using C, with the exception of the IDE allowing for schematic customization inside the chip it self, and being able to creat a PDF with all the info about my project, which if I knew a way to link it here in the forums, I’d link my project PDF to give further insight into how its set up.