Go Down

Topic: Clock Radio with Temp and Humidity Display (Read 160 times) previous topic - next topic



I am working through my first major project and i am running into some issues with my code. For now I am working on building a radio but i do not have all of the parts yet. So i am doing one thing at a time while learning the nuances. Right now I am using a 16x2 LCD screen, an Arduino Uno, a push button, and a DHT11. I will be adding a couple of rotary encoders (Volume and Freq), a RTC module, a class D amp module, the TEA5767, and of course a couple speakers with an antenna later on.

My end goal is to have an FM radio with one 16x2 LCD screen using one button (Not a switch) to swap the display from Freq/Date to Temp/Humidity. A nice to have would be to add in a code so the display switches again while the rotary encoder for volume is being adjusted to display current volume. But i will get to that later on.

The problem i am running into now pertains to the screen swap upon button push. I have 3 programs written right now for testing and combining purposes. ClockRadio_With_Temp_TEST is the current version of temp and humidity display that works to display current temp and current humidity to the LCD screen. Button_Push_Screen_Switch2_TEST is the current screen swapping sketch that works 100% when swapping between "Hello World" and "Goodbye World". ClockRadio_With_Temp_TEST_2 is my attempt at combining them. The program will compile without issues but the LCD will only display the startup message. Pressing the button does not display anything different anymore. One thing of note is that the serial monitor is still processing data and displaying it. I posted only the combined code below due to character limits of this post. I added all 3 as attachments with a few pictures

The only thing i can think of is that both codes use serial data and therefore it cannot keep track of both logic circuits?? Any advice would be greatly appreciated even if it is get a second display because it is not possible.

Code: [Select]


// include the library code:
#include <Bounce2.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define DHT11_PIN 0 // pin A0

const int buttonPin = 7; // Pin 7
Bounce button; //Debounced Button
bool textDisplay; //Which text to display

//Initialize DHT11
byte read_dht11_dat()
      byte i = 0;
      byte result=0;
      for(i=0; i< 8; i++)
           while(!(PINC & _BV(DHT11_PIN))); // wait for 50us
           if(PINC & _BV(DHT11_PIN))
              result |=(1<<(7-i));
           while((PINC & _BV(DHT11_PIN))); // wait '1' finish
    return result;

//Temp and Humidity Module
byte dht11_dat[5];
byte dht11_in;
byte i;


void setup()
  // Bootup Display
  // initialize the serial communications:
  DDRC |= _BV(DHT11_PIN);
  PORTC |= _BV(DHT11_PIN);

  button.attach(buttonPin, INPUT);
void loop()
    // start condition
    // 1. pull-down i/o pin from 18ms
     PORTC &= ~_BV(DHT11_PIN);
    PORTC |= _BV(DHT11_PIN);
    DDRC &= ~_BV(DHT11_PIN);
    dht11_in= PINC & _BV(DHT11_PIN);
        Serial.println("dht11 start condition 1 not met");
    dht11_in = PINC & _BV(DHT11_PIN);
        Serial.println("dht11 start condition 2 not met");
    // now ready for data reception
    for (i=0; i<5; i++)
    dht11_dat[i] = read_dht11_dat();
    DDRC |= _BV(DHT11_PIN);
    PORTC |= _BV(DHT11_PIN);
    byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];
    // check check_sum
    if(dht11_dat[4]!= dht11_check_sum)
        Serial.println("DHT11 checksum error");

    //Print into Serial Monitor 
    Serial.print("Current Humdity = ");
    Serial.print(dht11_dat[0], DEC);
    Serial.print(dht11_dat[1], DEC);
    Serial.print("% ");
    Serial.print("Temperature = ");
    Serial.print((dht11_dat[2]*1.8)+32, BIN);
    Serial.println("F ");

    // Update the state of the debounced button.

    // Toggle display on rising edges of the button.
    if (button.rose())
        if (textDisplay)
            //Show Temp and Humidity on LCD Display
            lcd.print("Temp: ");   
            lcd.print((dht11_dat[2]*1.8)+32, BIN);
            lcd.print("Humidity: ");
            lcd.print(dht11_dat[0], DEC);
            textDisplay = false;
                lcd.print("Freq Here");
                lcd.print("Date Here");
                textDisplay = true;

Thank You,



My end goal is to have an FM radio with one 16x2 LCD screen using one button (Not a switch)
Sew the button back on the shirt. Use a switch! It's OK to use a push-button SWITCH.

Code: [Select]
    // Toggle display on rising edges of the button.
    if (button.rose())

If that function never returns true, what do you do? Nothing. What are you seeing on the LCD? Nothing. Coincidence? I doubt it.
The art of getting good answers lies in asking good questions.


From the Bounce spec it is not clear if you have to set the debounce  "interval".
Perhaps the edge detector should be in while loop, but that would contradict the note that "update"  must be done continuously  - as  you did,
It just makes me curious how "they" manage to make the "rose" edge to be just single shot.
What resets it and prevents repeated access to the if(_) construct.


Thunder is good, thunder is impressive; but it is lightning that does the work.

Go Up