Showing posts from October, 2022

Arduino RTC: Calculate if daylight saving time adjustment applies

 When I revisited some code making use of the real time clock (RTC) on an Arduino MKR 1010 board I found that I had left a "kludge" to adjust for time zone and daylight savings. If you are using an Internet time server to set your real time clock then you are probably going to get a response of GMT (well since 1972, more officially, UTC). Your base line adjustment for your time zone (if any) is going to be fixed but you might want to allow for any seasonal daylight savings adjustment. It would be nice if we could add some code to make a daylight savings adjustment automatically. Your local rules may vary from mine but the UK rules, applied here, would serve for EU countries. Other locations might need a tweak or two. Daylight savings adjustments occur in the early hours of a Sunday. So, we need to know what the current day of the week it is when setting our RTC if we want to decide if we should apply any adjustment to UTC/GMT plus or minus our time zone difference. Code to ge

Arduino: How to calculate day of week from date

 I wanted to add some code to a program that could detect if a clock was running during daylight saving and making an appropriate adjustment. To do this I needed to be able to test if a day was a Sunday (as that is the day when clocks are usually moved back and forth depending upon season). Some real-time clock libraries have this function built in but the one I was targeting <RTCZero> was going to need some help. I developed a function to calculate a day of the week from a supplied date and tested it with an interactive program (using the Serial Monitor of the IDE) that will run just fine on an Arduino UNO. The serial speed is set at only 9600 so that the code works with the IDE2 Serial Monitor (still broken I note) but if you are using the earlier version of the IDE then you can set a higher rate. To test the function, just type a date in dd/mm/yyyy format (so a UK format) into the outbound message box of the Serial Monitor and hit the <Return> key. You do not need to set

Arduino: How to scroll long text on OLED screen

 While exploring a new and tiny SSD 1306 OLED screen as a useful user interface I hit on the need to scroll some longish text across the screen. This did not seem to be a feature of the Adafruit library I was using to run the device. So I am introducing this working demo of my solution to the problem. The solution is to position the start point of the text in steps towards the left and beyond the left hand edge of the screen. The screen "clips" the text and displays all it can across the width of the screen. The demo includes some fixed text at the top of the screen and scrolls the long text below. #include <SPI.h> #include <Wire.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 32 // OLED display height, in pixels #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 Adafr

Arduino: How to get IP Address for a URL

 I was revisiting an Arduino program that was setting the real-time clock on an Arduino MKR 1010 using the services of an NTP timeserver. The problem was that the IP address I had been using to lookup the time was not (currently) valid. I soon found an alternative but wondered if I could use a time server URL to lookup a currently valid IP address to pass to a WiFiUDP object instance. I took a look in the WiFi.cpp file that defines the WiFi class and found a handy function that looked like just the thing. int WiFiClass::hostByName(const char* aHostname, IPAddress& aResult) { return WiFiDrv::getHostByName(aHostname, aResult); } The following short Arduino program shows how to retrieve the IP address of a URL and store it in an arduino::IPAddress object. [ Arduino documentation for IPAddress object .] #include <WiFiNINA.h> const char* mySSID = SECRET_SSID; // your WiFi SSID const char* myPass = SECRET_PASSWORD; // Your WiFi password template inline Print &operator<

Raspberry Pi Pico compared to Arduino Maker 1010

  Starting with a feature and price breakdown .   MKR WiFi 1010 Pi Pico W Processor Cortex-M0+ 32bit ARM running at 48MHz 2 ARM Cortex-M0+ 32 bit cores clocked at 133MHz Memory 256Kb Flash plus 32Kb RAM 256Kbyte RAM WiFi 2.4GHz 802.11 b/g/n 2.4GHz 802.11 b/g/n Bluetooth BLE 5.2 GPIO Pins (excl. power etc.) 22 1xSPI, 1xI2C, 1xUART, 7x12-bit ADC, 1x10-bit DAC , 13xPMW 10x External interrupts 26 2×SPI, 2×I2C, 2×UART, 3×12-bit ADC, 16× PWM All GPIO pins support external interrupts Real time clock yes yes Other Encryption Chip Temperature sensor Floating Point library on chip 8×Programmable IO state machines SoftAP Price £29.90 £7.00 Looks like an easy price/perfo