FAQ
TL;DR: DS1307 RTCs ship with 56 bytes of battery-backed user RAM, and “Both classes inherit the print() method” [Elektroda, khoam, post #17961199] Append "\r\n" to ESP8266 UDP packets so smartphone apps display them properly. Use sprintf() or Arduino String to merge numbers with text. [Maxim, DS1307 Datasheet]
Why it matters: Correct line endings, string handling, and timekeeping stop silent data losses and hard-to-trace bugs in IoT builds.
Quick Facts
• DS1307 address: 0x68; user RAM: 56 bytes; runs at 32 kHz [Maxim, DS1307 Datasheet]
• NodeMCU I²C default pins: D1 (SCL) & D2 (SDA) [RoboIndia I2C Scanner]
• lcd/Serial.print(x, d) prints x with d decimal places; d=0 gives integers [Arduino Reference]
• ESP8266 UDP max payload: 1472 bytes on typical Wi-Fi MTU 1500 [Espressif SDK]
• attachInterrupt() works on GPIO0,2,4,5,12–15; level or edge triggered [ElectronicWings NodeMCU Interrupts]
How do I make ESP8266 UDP responses visible in a smartphone controller app?
Most apps expect CR-LF line endings. Add "\r\n" at the end of every reply: Udp.write("W1_ON\r\n");. Test on a PC to confirm the app now shows the response [Elektroda, kaczakat, post #17955379]
What’s the shortest way to join text and numbers on Arduino?
Use sprintf with a fixed char buffer: char buf[30]; sprintf(buf,"napiecie,%d,natezenie,%d",napiecie,natezenie); [Elektroda, khoam, post #17958530] Or concatenate String objects: String msg = "napiecie,"+String(napiecie)+",natezenie,"+String(natezenie); [Elektroda, kaczakat, post #17957189]
Can I send an Arduino String directly with Udp.write()?
Yes. Convert with myString.c_str() and pass the length: Udp.write(myString.c_str(), myString.length());. The method needs a byte array plus size [Arduino WiFiUdp Reference].
How do I print only whole numbers from BME280 readings?
Specify the precision: lcd.print(bme.readHumidity(), 0); prints no decimals, while 1 keeps a single digit [Elektroda, khoam, post #17960944]
How can I switch the Adafruit BMP280 library from SPI to I²C on NodeMCU?
- Comment out the SPI constructor and enable Adafruit_BMP280 bme; 2. Call Wire.begin(); in setup. 3. Ensure SCL on D1 and SDA on D2. The sensor then initializes over I²C [Elektroda, heyka, post #17960677]
What is the safest way to scan I²C devices on NodeMCU?
Upload an I²C-scanner sketch (example: RoboIndia tutorial). It lists active 7-bit addresses; reverse D1/D2 labels in some board silkscreens [Elektroda, heyka, post #17959267]
Does NodeMCU support external interrupts like AVR INT pins?
Yes. Use attachInterrupt(digitalPinToInterrupt(pin), ISR, mode). Valid pins: 0,2,4,5,12–15. Modes: RISING, FALLING, CHANGE, LOW, HIGH [ElectronicWings NodeMCU Interrupts].
How do I set an arbitrary time on a DS1307 module?
Call clock.setDateTime(YYYY,MM,DD,HH,MM,SS); outside any if(condition). Example: clock.setDateTime(2023,5,25,14,30,00); [Elektroda, Slawek K., #17966869].
What does the offset parameter in DS1307::readByte() do?
Offset selects which of the 56 RAM bytes (addresses 0x08–0x3F) you access. readByte(0) returns the first RAM byte, readByte(10) the eleventh, and so on [Elektroda, khoam, post #17974395]
Why does the library test #if ARDUINO >= 100 in its headers?
IDE 1.0 introduced Wire.write()/read(). Older 0.x cores used Wire.send()/receive(). The check includes the proper API for both toolchain eras [Elektroda, Slawek K., #17973439].
Could using Arduino String crash my ESP8266?
Yes. Frequent concatenations fragment the heap; devices with <40 kB free RAM may reboot after hours of uptime [Espressif “Managing Heap Fragmentation”, 2016]. Experts advise fixed char buffers for long-running IoT tasks [Elektroda, kaczakat, post #17957189]
Quick 3-step: reset DS1307 time to build time
- Include and create DS1307 clock;. 2. In setup(), call clock.begin(); then clock.setDateTime(DATE,TIME);. 3. Upload once; the battery backs the time afterward. This matches the MCU compile timestamp [Elektroda, heyka, post #17966506]