Posts

The book: Practical Arduino C - complete text now free online

 My book on C for Arduinos has an audience and that is reflected in the sporadic (and partly seasonal) sales. Sometimes selling well but with some months figures making grim reading. I wrote the book to make the C (and C++) language a full partner with electronic skills for Arduino hobbyists and professionals. C skills complement hardware design skills and can potentially enable or enhance projects that might otherwise have failed to meet their design objectives. I wrote the book to be read and to act as an ongoing resource for its readers. To that end I am going to make the complete book available on line - and free to read.  The process of moving the book content to HTML is a little time consuming as I wanted the presentation to match the printed page as closely as possible (along with some web style page navigation). That task may take a while to complete. I have completed the first three full chapters and they are available now if you follow this link . Chapter three is a ...

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