circuitpython 8.0 rc 1

A new version of CircuitPython is near final release. Version 8 RC 1 was released today (yesterday, actually, but it wasn’t officially documented until today). I’m interested because now there’s an official CircuitPython released specifically for the Raspberry Pi Pico W ( https://circuitpython.org/board/raspberry_pi_pico_w/ ). I’m starting with one of my Pico W boards, and then moving around to all the devices that currently run 7.3.3. So far nothing has leaped out as a problem, but these are very early days. I know that WiFi works, but I don’t know if Bluetooth is working or not.

One application I’ve been tweaking along the way is an automatic quote displayer that queries the Adafruit quote server and prints it out. The response comes back in JSON. The original code, written for CP 7, only printed the response out in a raw format. This version parses the JSON and line wraps long quotes to less than 80 columns. Here’s a typical output.

...   Injustice anywhere is a threat to justice everywhere. - Martin Luther King, Jr.   I never am really satisfied that I understand anything; because, understandit well as I may, my comprehension can only be an infinitesimal fractionof all I want to understand. - Ada Lovelace   Adversity is revealing of character. - Unknown   The most exciting phrase to hear in science, the one that heralds new discoveries,is not 'Eureka!' but 'That's funny...'. - Isaac Asimov   The whole point of getting things done is knowing what to leave undone. - Oswald Chambers...

And here’s the code.

# Copyright (c) 2023 William H. Beebe, Jr.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.## Derived/modified from"# 2022 Liz Clark for Adafruit Industriesimport osimport timeimport sslimport wifiimport socketpoolimport microcontrollerimport adafruit_requestsimport jsonimport gc# Adafruit quotes URL#quotes_url = "https://www.adafruit.com/api/quotes.php"# Connect to a local access point.# WIFI_SSID and WIFI_PASSWORD should be defined in your settings.toml file.#wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD'))pool = socketpool.SocketPool(wifi.radio)session = adafruit_requests.Session(pool, ssl.create_default_context())print("\n\nFetching quotes from {}\n".format(quotes_url))wrap_limit = 72while True:try:time.sleep(5)gc.collect()# Get a quote. Parse the JSON response.#response = session.get(quotes_url)dic = dict(json.loads(response.text)[0])qstr = dic['text'] + "."# Primitive line wrapping for long text lines.#while len(qstr) > wrap_limit:cut = qstr.find(" ", wrap_limit, len(qstr)) + 1if cut > 0:print("   {}".format(qstr[:cut]))qstr = qstr[cut:]else:breakif len(qstr) > 0:print("   {}".format(qstr))print(" - {}\n".format(dic['author']))response.close()gc.collect()# pylint: disable=broad-exceptexcept ValueError as e:print("Error: bad JSON")response.close()except Exception as e:print("Error:\n", str(e))print("Resetting microcontroller in 10 seconds")time.sleep(10)microcontroller.reset()

As they say, more to come.

switching back to visual studio code

I have a strong like/dislike relationship with Emacs. When I like it, I like it immensely. When I dislike it, the dislike is intense.

There’s a lot to like about Emacs. There’s the easy keyboard control, the ability to pick a productive theme, and the way it highlights code as I write it. It’s not an IDE, and I don’t want it to be an IDE. But I do want more than just a simple text editor, especially when I’m working with C++, Go, or Rust.

Unfortunately, I’m set in my ways when it comes to how my code should look as I type it in. The greatest irritant to me is tab spacing in code. I expect tab spacing to work like this: four spaces, no tab characters, only spaces for tabs. Most of the time Emacs does this with aplomb. Wonderful formatting, especially in Rust and Go. Unfortunately it doesn’t always want to do this with C or especially C++. In spite of reading every document dump, every dedicated wiki, ever sub Reddit, every Medium article, every Stack Overflow post, Emacs has decided to set tab stops to two spaces, no matter how I configure those settings via init.el. I even tried to drop back to an earlier Emacs release, only to find that whatever Emacs Lisp configuration scripts had been picked up by my current Emacs release wouldn’t execute properly with an earlier release.

Since I couldn’t satisfy my frustration by actually fixing the tab space issue within Emacs, I opened up Visual Studio Code and went looking to see why it was constantly consuming processor overhead. I found the guilty plugin by turning off one plugin after another and restarting VSCode. I found the guilty plugin, a plugin I seldom use, disabled it, and I’m now back to happily writing code in VSCode again.