Category Archives: electronics

Not bad at all for under $15

The vertical lines in the screen, while present, aren’t as obvious as they are in the photo. The time is off because it’s not on my home network right now and can’t retrieve the correct time.

I’ve been playing around a bit with ESPHome and Home Assistant lately…started with a couple of Sonoff smart outlets, one to replace a Kill-A-Watt monitoring my mining rig and another to switch a light on at sunset.

What’s up above is part of this weather station kit. The metal can on the small board in the center is a BME280 environmental sensor that picks up temperature, humidity, and barometric pressure and makes that information available over I2C. The NodeMCU on the right reads the sensor, publishes its readings over WiFi to a Home Assistant server, and displays the readings (and current time) on the I2C-connected OLED on the left. You could probably use an ESP-01S with a 4-MB flash upgrade since I2C only needs two pins to work, but the kit came with a NodeMCU, so that’s how I brought it up initially.

Wiring is simple: connect ground together on all three boards, connect the power inputs on the OLED and sensor to a 3.3V pin on the NodeMCU, connect the data pins (SDA) to pin D2, and connect the clock pins (SCK) to pin D1.

The ESPHome config file (not really a program as such) looks something like this:

esphome:
  name: bme280
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "your_wifi_ssid"
  password: "your_wifi_password"

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

i2c:

sensor:
  - platform: bme280
    address: 0x76
    temperature:
      name: "BME280 Temperature"
      id: temp
      oversampling: 16x
    pressure:
      name: "BME280 Pressure"
      id: baro
    humidity:
      name: "BME280 Humidity"
      id: humid
    update_interval: 60s

display:
  - platform: ssd1306_i2c
    model: "SH1106 128x64"
    lambda: |-
      it.strftime(127, 60, id(arial14), TextAlign::BASELINE_RIGHT, "%H:%M", id(esptime).now());      
      it.printf(0, 0, id(arial14), TextAlign::TOP_LEFT, "%.1f°", id(temp).state*1.8+32.0);
      it.printf(0, 20, id(arial14), TextAlign::TOP_LEFT, "%.1f%%", id(humid).state);
      it.printf(0, 40, id(arial14), TextAlign::TOP_LEFT, "%.2f\" Hg", id(baro).state*0.0295);
      
time:
  - platform: homeassistant
    id: esptime
    
font:
  - file: "/usr/share/fonts/corefonts/arial.ttf"
    id: arial14
    size: 14
    

The sensor returns temperature in °C and barometric pressure in hPa; the code above converts those to more sensible units for display. Also, you’ll probably need to update the font file location to whatever is correct for your system. (I have ESPHome installed on Gentoo Linux and have the corefonts package installed.)

Something like this would be useful to have indoors. For an outdoors weather sensor, leave off the screen and the related sections (display, time, and font) from the config file. Next task is to fab up an enclosure of some sort.

A password manager in your pocket

It doesn’t do everything that KeePass does, but it keeps the four passwords you use most on your keychain (or will, once it’s in the 3D-printed case I’ve planned for it). It plugs into a USB port and shows up as a keyboard. It also shows up as a serial interface, through which you can set the text to be sent by each key.

In the past, I’ve ordered boards from companies that make them and stuffed them with parts myself. This time, the boards were handed off to an assembly service that put on everything except the button domes. (They’re not supposed to be soldered; a piece of tape is sufficient to keep them in place.)

Total cost for PCB fabrication and assembly? $52 for 10 pieces of bespoke electronics. The button domes add about another $2 per board, and 3D-printed cases should be about a quarter each.

It’s amazing times we live in that such things are possible. :)

(Source for everything is at https://gitlab.com/salfter/key_dongle.)

Hooray for old firmware in shipping hardware :-P

A while back, I picked up a cheap Chinese knockoff of a usbASP programmer from Amazon…originally, it was to replace the crummy factory-installed firmware on the Anet A8 motherboard with Marlin. The programmer did its job at the time and was forgotten about for a while. (The A8’s motherboard, meanwhile, crapped the bed after I had only had the printer up and running for maybe a month. It’s long since been rebuilt into an AM8 and the electronics have likewise been through several upgrades, most recently to an SKR 1.4 Turbo with TMC5160 drivers just this past weekend…but that’s getting offtopic.)

I pulled the programmer out again to try configuring some ATMEGA328s for a project. They’re empty chips ordered from DigiKey a while back, and I figured I’d try throwing Optiboot onto them. This should be a simple matter of popping the ATMEGA328 off of an Arduino Uno, plugging in one of the empty chips, plugging the usbASP into the Arduino’s ICSP header, and invoking avrdude with the right options…right?

The programmer wasn’t having any of that. With the preprogrammed chip in the Arduino, avrdude identified the chip, read out the fuses, etc. With an empty chip, it wouldn’t read out the chip ID properly. It said something about not being able to set the clock speed and that an upgrade might fix it.

The homepage for the usbASP had some firmware images, so I grabbed the newest and flashed it according to these instructions. The clock-speed error was gone, but it still wouldn’t work. I tried swapping in other Arduinos and still had no luck.

A bit of poking around led me to this fork of the usbASP firmware, last updated just nine days ago. (By comparison, the “update” I had previously applied was already ten years old!) I burned that to the usbASP, popped an empty chip back into the Arduino Uno, and fired up avrdude. Success! I burned Optiboot, set the fuses, and switched cabling on the Arduino so it was connected with just a USB cable (as usual) instead of the usbASP. The Arduino IDE saw it; I was able to send the “blinky” example to it and get the onboard LED blinking.

I was also able to diddle the fuse settings to change speeds from 16 MHz down to as low as 1 MHz and to run off the internal oscillator instead of an external crystal. I have a stepper-motor tester I started building a while back that was stalled when I think I misprogrammed the fuses and switched it to crystal operation in a circuit with no crystal. Now that the programmer is properly sorted out, I think it’s time to dig up the parts and finish this project.

How to rotate KiCad footprints

I did some reading recently on design for manufacture (in particular, https://rheingoldheavy.com/design-assembly-kicad/), and one of the things that came up was that you should have your component footprints oriented the same way as they’re loaded into the tape that gets loaded into the pick-and-place machine. Many KiCad footprints (including those that ship with KiCad) aren’t oriented this way, and even in the new KiCad 5, I don’t see an easy way to rotate an entire footprint. You can rotate a footprint inside a PCB design, but unless I’m missing something, there’s no option within the footprint editor to take all the elements within and rotate them (let alone an option to rotate an individual element, as far as I can see).

I’ve come up with this:

https://gitlab.com/salfter/kicad-footprint-rotator/

This sed script takes a KiCad footprint and rotates it 90° counterclockwise by transforming coordinates, dimensions, and rotation angles within. If you need to rotate 180°, run your footprint through the script twice. To rotate 90° clockwise, run it through three times.

Here’s what KiCad’s SOD-323 footprint looks like as it’s rotated through 360°:

the original footprint

rotated 90°

rotated 180°

rotated 270°…this is probably how it’s loaded into the tape

rotated 360°…back where we started

I’ve tested it on a few footprints that use different types of elements, and I think it’s working properly. That said, it’d be prudent to verify that the rotated footprint is correct before you whack it into your next project. If you run across a footprint that it screws up, I would be interested in seeing it.

Parts for the reflow controller are on the way

Here’s my next project:

It’s basically a mashup of the Rocket Scream reflow oven controller shield with an Arduino Leonardo, crammed into as small a board as possible (only 2″x2.5″) so it can be installed inside nearly any toaster oven. I fired off a parts order just a few minutes ago. While the board design is ready, I like to have the parts in hand so I can verify against a printout of the board design that they’ll fit. I’ve ordered boards made before, only to find out that the parts intended to go on them wouldn’t fit.

Beyond the board and parts, the only other components I’ll still need to get are a solid-state relay (and heatsink) and a thermocouple. I think I’ll stash an iPhone charger inside to power the controller board, as I have several of them kicking around here. I already have the toaster oven…picked up one of these, as others have had success with it in their builds. It’s cheap and heats up quickly.