กลับไปหน้ารวมไฟล์
all-in-one-clock-20-e16d7a-en.md

All-In-One-Clock-2.0

This is the second version of my old project: All In One Clock 1.0 This project will have similar functions but have a touch screen and more information.

Project Goals:

  1. Display Time (current time and date)
  2. Alarm clock
  3. Temperature right now
  4. Full temperature info (pressure, humidity, etc..)
  5. Forecast 3 days (today, tomorrow, and the day after tomorrow)
  6. Current weather Icon
  7. Timer

To be able to do all of this, we will need a connection to the internet. I chose for this project to use the Arduino RP2040 Connect. To use the RP2040, I will be using the https://create.arduino.cc/iot This official Arduino tool is very easy to use, and it's great for using the internet across multiple devices.

we have an Arduino that is connected to the internet, but how will we get the information? Well, let's divide the information we need into two categories:

  • Time: To get the time, it's very simple because, while you are connected to the internet, you can get the Unix timestamp. The Unix timestamp is a way to count the time. How does it do it? It will count every second since January 1, 1970. For example, the time while writing it is "1682760531". To convert this time, I will use a library that will convert this time to a more readable time (hours, minutes, year, month, etc.).
    1. Temperature: To get the temperature, we will use something called an API. In short, an API is some kind of server that, when I "call it" I get JSON information back. For example, go to this link to use the NASA API that shows you the international space station location right now. http://api.open-notify.org/iss-now.json . For this project, I will use https://www.weatherapi.com . This API will have a lot of information for this project, but I will only use some of it because the Arduino cannot get so much information (we are talking about 20000 characters), so in the API settings, I changed it to only get some of the information. The API will also give me an image link, for example, cdn.weatherapi.com/weather/64x64/day/116.png . To get the image, I need to do a couple of things: get the image number, and determine if it's day or night.

    All of the information mentioned above will be sent through the ISP. The Arduino will get it and decode it.

    temperature = doc.containsKey("tw") ? doc["tw"] : temperature;

    In this example, the Arduino will read the incoming data, and if the data has the keyword "tw" (it will be encoded as JSON) then the data will be saved in the temperature variable.

    I also sent the image number and Day/Night but how will I show the image? Well, on the SD Card that is connected to the screen, there are two folders of all the images from day/night as bmp(bit map images). So I go to the SD Card and show the image by number or time.

    In this project, I show icons in two ways. The first is by using a .h script, which is faster, but I can't have a lot of images like that because it takes a lot of MB. The second way is by using the SD card.

    Dashboard:

    The Arduino IoT Cloud allows us to use a dashboard. What is a dashboard? is a way for me to see the data from anywhere and on any device.

    In the dashboard, there are a lot of widgets; we will use some to show the data. We will use the button widget to have a button that will update the temperature (usually for debugging) and a couple of other widgets to show the data (temperature, humidity, pressure, and time).

    Do note that if the Arduino will receive a data of a null reading(0) or will restart it can update the graph as you see(I will add in the future a way to stop that from happening).

    Fonts:

    I used a couple of extra fonts that I will include in the download files.

    The screen:

    I am using a 3.5-inch TFT screen; this is a touch screen. To use it, I am using the MCUFRIEND_kbv library.

    We have 5 different screens; let's go through them one by one:

    1. Main Screen: On this screen, we can find the current time and date, the temperature, and an icon that shows the weather. Also, we have the buttons for all of the other screens.
    2. Forecast Screen: In this screen, we can see the forecast for the current day, tomorrow, and the day after tomorrow. For each day, there is an icon and a minimum and maximum temperature.
    3. Temperature Screen: In this screen, we have a lot of information that includes: temperature, humidity, pressure, UV, wind speed, Feels like
    4. Alarm Screen: In this screen, we can set the alarm time by using two buttons.
    5. Timer Screen: On this screen, we have a timer display where you can set the desired time and start the countdown.

    Hardware Synchronization

    The **All In One Clock 2.0** is an aggregation of multiple smaller projects. It takes RTC timekeeping, climate sensing, and interactive menus, compiling them into one massive, highly functional block of code.

    1. The Brain: An Arduino Mega or ESP32 is required due to the massive code size and library requirements.
    2. The Timekeeper (DS3231 RTC): Unlike the basic `delay()` function, an RTC module has an internal battery. Even if you unplug the Arduino for a year, the RTC remembers the exact second and year.
    3. The Climate Monitor (DHT22 or BME280): Reads the room temperature.
    4. The User Interface: A 20x4 Text LCD or a 3.5" TFT touchscreen displaying all data beautifully formatted.
    5. The Inputs: 4 push buttons (Menu, Up, Down, Select) to navigate the settings menu and set alarms.

    Advanced Menu Structures

    To combine all these features, the code uses a complex State Machine.

    • State 0 (Home): Displays Time and Temp.
    • State 1 (Menu): Displays "1. Set Time, 2. Set Alarm, 3. Settings".
    • State 2 (Set Alarm): Blinks the cursor over the hour, waiting for the user to press 'Up' or 'Down'.

    Building the switch/case logic for a multi-tiered menu system is one of the most frustrating but rewarding software exercises in embedded systems programming!

    Connections:

    In this project we don't connect a lot of thing but we do connect some:

    1. Connect both Arduino's Using ISP. From the rp2040 A4-D21 and A5-D20.
    2. From the mega 5v to RP2040 VIN
    3. From the mega gnd to RP2040 GND
    4. From the mega 5v to vcc buzzer
      1. From the mega gnd to gnd buzzer
      2. From the mega D44 to buzzer

    Box:

    There is an extra 3d model for the box I used for the screen.

    GitHub:

    You can find all of the codes and files in my GitHub

    ข้อมูล Frontmatter ดั้งเดิม

    apps:
      - "1x Arduino IDE 2.0 (beta)"
      - "1x Arduino IoT Cloud"
    author: "dzh121"
    category: "Screens & Displays"
    components:
      - "1x Soldering iron (generic)"
      - "1x 3D Printer (generic)"
      - "1x Arduino Mega 2560 Rev3"
      - "1x Buzzer Module"
      - "1x 3.5 TFT Touch Screen with SD Card Socket for Arduino"
      - "1x 150 Pc. Jumper Wire Pack, 22AWG"
      - "1x Arduino Nano RP2040 Connect with headers"
      - "1x Cutter"
    description: "The ultimate bedside companion! Build a master clock featuring time, date, temperature, humidity, and customizable alarms on an LCD."
    difficulty: "Intermediate"
    documentationLinks: []
    downloadableFiles:
      - "https://github.com/dzh121/All-In-One-Clock-2.0/blob/main/code/arduinoMegaCode.ino"
      - "https://github.com/dzh121/All-In-One-Clock-2.0/blob/main/code/arduinoNanoCode.ino"
      - "https://github.com/dzh121/All-In-One-Clock-2.0/blob/main/code/icons.h"
    encryptedPayload: "U2FsdGVkX1/A0xGwVkj4rt5JWCwmggqpfBeVd34vwTiR/4svgDOcXYVElJ0u8tteSygKmQob7P7vB6ZQl7FwQ37y9wU7/ebalh7ScOWLVlFNh1GvBsjey5Vzz9UOs2kjQQ/vStMndY4I0AtvW8QIWA=="
    heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/all-in-one-clock-20-e16d7a_cover.jpg"
    lang: "en"
    likes: 2
    passwordHash: "4d616da6f673f5bb50b093f1acfb918c39392acd2817bb2140137ddcd7d59356"
    price: 2450
    seoDescription: "All In One Clock 2.0: Smart alarm clock with weather info, time, and timer. An all-in-one Arduino and ESP32 project."
    tags:
      - "Clocks"
      - "Internet Of Things"
      - "Entertainment System"
    title: "All In One Clock 2.0"
    tools: []
    videoLinks: []
    views: 6963