Posts

Showing posts from 2022

Arduino OLED display

Image
One obvious Arduino UI option that I had previously overlooked was a small OLED display device. While they have a small screen size these are inexpensive devices and easy to communicate with using the I2C 2 wire interface. Installing libraries I used the IDE library manager to look for suitable software to run an SSD1306 OLED display. I chose the Adafruit option as that included provision for a 128 x 32 device and the I2C interface. The installation prompted me to include a GFX and BusIO library as they were dependencies. I knew I wanted a GFX library to manage some basic graphics. Testing Then connected a good old basic Arduino Uno to the board using 4 jumper wires - 2 for power and the 2 for the I2C interface. Then I loaded the appropriate Adafruit supplied example program and watched it happily run through a great demonstration of the display's capabilities. The library supports a wide range of graphics drawing options alongside simple text. Next steps The next step for this lit...

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...

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

Image
  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 pr...

Arduino User Interfaces

Image
 Back when the Arduino project was getting under way and indeed when most of us started to get to grips with controlling a brilliant low-cost microprocessor like an Arduino Uno the concept of a program user interface (UI) would have been something of a joke. The final chapter of my book on Arduino C programming built upon the capability of an Arduino MKR WiFi 1010 board to serve a UI to any device on a local network with a Web browser – all to control the project’s skylight closer. The intention was to show that any suitable Arduino project could be extended to include an effective user interface over WiFi. The User Interface was clearly a key component of the project and I though a good demonstration of the concept. One can imagine w lot of microprocessor projects that could be enhanced with an effective UI. A popular Arduino project is to set up an automated plant or seedling watering system as that makes use of sensors and activators. If the plants are outdoors you could concei...

The Arduino IDE

Image
 The upcoming version 2 IDE for Arduino C development had me writing some notes on this new desktop tool for my Arduino C book support web pages. I made the effort as it was always possible that there would be a key change that might have made life difficult for new users working through the book. In fact, the changes are largely improvements to the user interface including a nice “intellisense” addition when entering code. The most significant addition seemed to relate to debugging running code on an Arduino board. A little investigation revealed that the new “debug” facility only applied to a limited range of recent boards and that almost all of those would require the inclusion of some additional third-party test hardware. Only the new Arduino Zero has the capacity to natively support interactive debugging from the IDE. That capacity is probably a sign of things to come but while the Zero has that “Uno” format and thus heritage appeal the overall package leaves me wondering abo...