Tuesday, June 10, 2025

Driving a WS2812B with a PIC

One of my projects needed a small footprint μC. For a while, PIC chips had disappeared from the market post COVID and I opted for the ESP8266. But now, they are not only back but newer chips are available. I was using the PIC 12F1840 but I had outgrown the program memory of 7K. The PIC 16F18115 has twice the program memory of 14K. Besides some enhanced features that are not of interest, it is actually cheaper. While it has an internal oscillator of 32 MHz, it is a lot slower than the ESP8266. This will make driving the WS2812B a bit of a challenge.

There may be many ways to drive a WS2812B from a PIC using some peripherals imaginatively. This is yet another way. This drives a single WS2812B using a bit-banging approach.

The SK6812 is a good substitute for the WS2812B. The datasheet timings are a bit different from the WS2812B, though in practice, they may still interoperate. I have tried to generate timings that are valid for both chips as per their datasheets.

Friday, August 16, 2024

Inside a Linear Actuator

Linear actuators are getting easy to obtain and relatively cheap. The same cannot be said of linear servos. The two have a lot in common except for the ability to control the position precisely. The usual way the commercial servos do it is using a multi-turn potentiometer. I decided to take a different tack. And the best way to implement it is to take one apart and see how they can be engineered to provide servo operation.

The full sized linear actuators (500+ mm travel) I intend to use are expensive and I need six of them. A good approach would be to try it with smaller actuators (200m travel) and get some experience using them. The ones I opted for are shown below in retracted and extended state.


Sunday, October 1, 2023

Chakravyuh - A Labyrinth

Decades ago, back in school, we used to doodle a labyrinth. I thought it would make a cool painting. A bit stark and monochromatic but intriguing, nevertheless. All I needed to do was to figure out a way to draw a geometrically defined version of it.

After a bit of analysis, I figured out the various arcs to be drawn. This was done in a CAD program (TurboCAD) and saved as SVG. Then I used GIMP to rasterise it. This allows me to scale it to any resolution. I chose a 3200 x 3200 pixel image. This was reproduced on an 88 cm acrylic on glass print from the Canvas Art Factory.

Monday, July 10, 2023

A New Workbench

I am in a new house and as I was debugging my circuit on this small, cramped table, I looked around me. Oodles of space. Why not build set up a decent workstation? This is how and what I ended up with.


Everyone has their own way of setting up their work table. This depends on what they do there along with space and cost constraints. This is how I set up mine. It may not work for everyone, may be not even for me! But there may be a few ideas worth borrowing.

Monday, December 12, 2022

SMD Hot Air Soldering

Once I started using SMD components, it widened my horizons but it also started me down the slippery slope. I started with careful soldering and decided to move to hot air soldering. And I could really do with a microscope to lend a helping hand.


Hot Air Setup - HDMI Microscope, Atten 858D+ Hot Air Station

The whole thing was triggered when I had to solder ESP modules on to a PCB. Most chips like SOIC were OK. I did not have to deal with TSSOP or TQFP. I stick to 1206 passive components, going down to 0805 only if necessary. I did try soldering the ESP modules by hand but the results were abysmal. Time to go down the hot air route...

Monday, August 29, 2022

YA$1µC - Yet Another $1 Microcontroller

I designed my servo controller around the PIC 16F18326. Then on the Element14 site, I see the dreaded words – Available for back order, Awaiting Delivery by 7/08/23! It is not often that calculating the wait involve the year. On the other hand, ESP based modules are an ebay/aliexpress click away. So I decided to redesign my circuit around the ESP chipset. Which brings me to the well known The Amazing $1 Microcontroller article. So how do the ESP chips stack up as an Amazing $1 µC?

ESP8285 bare chips, ESP-01F modules and breakout boards for it

Most ESP chips need an external flash chip. The exception is the ESP8285 that requires just an external crystal. So this is the chip that participates in this competition. To start with, is it really a $1 uC? Not really. It is basically a wifi chip, so it does need an external crystal. In quantities of 10, the ESP8285 bare chip is available on Aliexpress for under US$0.80. An external crystal adds about 12 cents – this is just under the $1 limit. So let us persevere and take a quick look at how it rates.

Monday, July 25, 2022

Is your robot a jerk?

How many times have you seen a video of a robot that moves in a jerky motion? This is probably due to an on/off approach to speed control. This is an easy trap when controlling a servo. You have to move from A to B. One second you are setting it to position A and the next you set it to position B. The servo responds with a jack-rabbit start and gets to the new position as quickly as possible.

A better approach is to accelerate slowly till you reach full speed and then decelerate to stop. The need for this was first illustrated when a motor being controlled jumped and fell off my table. Since then, the speed profile has been tested by keeping the motor on its own on a flat surface. If it falls over, it has failed the test.

Monday, July 18, 2022

Serial Multi-drop on an ESP8266

My servo controller is being moved from a PIC to an ESP module. Each servo motor has its own controller connected to a bus. The bus is a TTL serial line. In order to connect multiple controllers on the same bus, the transmit line of each slave controller has to be floated. They are pulled up at the host and a slave controller enables it only when it is ready to respond to a host request. This ensures that only one slave is transmitting at any given time.

I am, for now, using the Arduino framework. This puts a couple of layers between my code and the hardware. This blog looks at how to implement a floating transmit line on an ESP. To test the prototype I have the line set to half the power supply voltage of 3.3V using a couple of resistors. This helps me check if the output is floating or not. In the trace below, you can see a floating line starting to transmit a response.

Tuesday, July 12, 2022

Driving a WS2812B with an ESP8266 (Arduino)

With most PIC chips disappearing from the market as part of the semiconductor shortage, I looked around for options for my smart servo controller. I finally settled on the ESP8266 module - specifically ESP-01F. One of the features I had in mind was to use a WS2812B RGB LED to indicate the various states. I already have a servo control loop that is executed once every 20ms. It made sense to squirt out the data for the RGB LED as part of this service routine.

There are many ways to drive a WS2812B from an ESP8266 in an Arduino environment. This is yet another way. This drives a single WS2812B using a bit-banging approach.

Friday, March 6, 2020

Oxeye - A daisy chain servo controller

I finally decided to try out a robot arm. I have been looking at getting one (either that or one of those biped robots) for a while. I was also looking forward to building a controller for it from scratch.

One interesting problem is how to control several servos. Most solutions end up with this octopus like controller where wires from all the servo motors snake to a single controller board. This board has multiple servo outputs. But never enough. A much better way would be to use a bus structure.

Each servo will have its own little controller. Each controller will have an input and output port. Or the other way around – it is just a bus. Each controller is connected to the next one in a daisy chain. The first one is connected to the controller and the last one has one port unused. Depending on ease of wiring, in some cases a Y cable can connect multiple controllers to a single one. This should make the wiring a lot simpler – no tangle of connections to a single controller. It also simplifies the controller - there is only one port. This is roughly how smart servos work as well.

Tuesday, April 23, 2019

Enphase Production/Consumption Metering

In the last blog, we looked at Panel Level Monitoring based on the thecomputerperson blog. Further down in the comments, is another useful URL.

The URL is http://[ip address]/stream/meter. Like Panel Level Monitoring, it prompts you for the user id and password. But the usual envoy/serial no. does not work this time. The user id is installer and the password is not obvious. Fortunately, thecomputerperson has a blog describing an app to derive this password. Once you enter the credentials, you get a continuous stream of data with more arriving every 1 second. Each batch of data looks like this.

data: {
  "production":{
    "ph-a":{"p":2412.766,"q":195.631,"s":2419.61,"v":243.321,"i":9.95,"pf":1.0,"f":50.12},
    "ph-b":{"p":2216.147,"q":171.409,"s":2220.896,"v":245.239,"i":9.068,"pf":1.0,"f":50.12},
    "ph-c":{"p":2176.172,"q":178.79,"s":2178.513,"v":239.326,"i":9.112,"pf":1.0,"f":50.12}
  },
  "net-consumption":{
    "ph-a":{"p":-2275.016,"q":-312.015,"s":2293.029,"v":243.378,"i":9.421,"pf":-0.99,"f":50.12},
    "ph-b":{"p":-2014.286,"q":-212.405,"s":2023.73,"v":245.4,"i":8.257,"pf":-1.0,"f":50.12},
    "ph-c":{"p":-2151.988,"q":-342.735,"s":2171.025,"v":239.412,"i":9.078,"pf":-0.99,"f":50.12}
  },
  "total-consumption":{
    "ph-a":{"p":137.75,"q":-507.647,"s":128.826,"v":243.349,"i":0.529,"pf":1.0,"f":50.12},
    "ph-b":{"p":201.861,"q":-383.814,"s":199.012,"v":245.319,"i":0.811,"pf":1.0,"f":50.12},
    "ph-c":{"p":24.184,"q":-521.524,"s":7.95,"v":239.369,"i":0.033,"pf":1.0,"f":50.12}
  }
}

Sunday, April 21, 2019

Enphase Panel Level Monitoring

No sooner had the Enphase Envoy been installed, I started exploring the web server installed on it. The Enphase Envoy uses your home wireless to send its data back to the cloud. You should be able to see the device on your router and find out its IP address. Connect to it using a browser to see the web pages that it serves up.

The normal pages have some basic info but the interesting stuff has been described in thecomputerperson blog. Have a look and do go past the blog into the comments. That is where some of the most interesting information lies.

One gold nugget was the call to get panel level information. The URL is http://[ip address]/api/v1/production/inverters. If you try that on a browser, you are prompted for a user id and password. The user id is envoy and the password is the last 6 digits of the serial number for the Enphase Envoy. The response is a JSON document listing each panel and their outputs. The values are the serial number of the panel (serialNumber), the timestamp this information was last updated (lastReportDate), the device type (devType) which is always 1, the power last reported (lastReportWatts) and maximum power ever reported (maxReportWatts) - not sure how far back it goes - since last power up?

[
  {
    "serialNumber": "121XXXXXXXXX",
    "lastReportDate": 1555658860,
    "devType": 1,
    "lastReportWatts": 1,
    "maxReportWatts": 297
  },
  {
    "serialNumber": "121XXXXXXXXX",
    "lastReportDate": 1555658777,
    "devType": 1,
    "lastReportWatts": 0,
    "maxReportWatts": 297
  },
  ...
]

Friday, April 19, 2019

Going Solar - Post-installation

Part VI - Post-installation

My service provider was and is AGL. I had trouble getting them to do anything before the installation. But after, getting on to the account portal, I got a pleasant surprise. Plenty of details on my usage!

Friday, April 12, 2019

Going Solar - Installation

Part IV - Installation day arrives!

After a few delays over the Christmas period and waiting for the panels to be back in stock, installation day finally arrived. The solar company (Space Solar) has its own installers. A van and a pickup truck (piled high with solar panels) pulled up that morning. The crew placed ladders and clambered onto the roof and inspected it for an hour or so. The chief technician then gave me the news. It was going to be hard to place all the cells. He did not see any value in putting cells on the south facing roof (as was in the original design). Instead, he suggested squeezing it into a spot which is under the eaves and be in shadow till about 1 PM. He reckoned it was better than putting it on the south facing roof. He also offered to install fewer panels than the original layout and save a bit of cost but I was not for it. On the whole, I think it was an improvement on the original design.

Thursday, March 28, 2019

Going Solar - Enphase Envoy

Part V - Enphase Envoy - the brains of the outfit

The Enphase Envoy, in my case, the Envoy-S Metered, keeps an eye on the IQ7+ micro-inverters. It also communicates back to base somewhere on the cloud. In addition, it can also measure the amount of power your solar array produces and the amount of power you consume. All in all, this is a piece of equipment that deserves its own blog post.

Tuesday, February 5, 2019

Going Solar - The Financials and comparing Tariff Plans

Part III - The installation is taking for ever! May be a good time to publish the financials behind the whole thing and look at and compare some tariff plans.

I already have my hourly consumption as mentioned in previous blogs. To keep it relatively simple I am looking at it across seasons. The analysis looks like this.

I am comparing my current plan with no solar array, with a 5KW solar array optimally placed and a 10.72KW array in a less than optimum aspect. The last is, of course, the one I am getting installed.

Wednesday, January 9, 2019

Going Solar - Solar Panel Configuration

Part II - As quotes come in, the design of the Solar Array emerges.

Monday, January 7, 2019

Going Solar - Analysing my energy usage

Part I - Planning to add solar panels to my roof, I started with an initial analysis of my electricity consumption pattern.

Tuesday, April 24, 2018

Building the ESP8266 IR Learner

The project outlined in the previous blogs seemed to work well. It was time to make a PCB and put some finishing touches on the software. The PCB is roughly the same size as the Doit ESP8266 board. To keep the size down, I have almost exclusively used SMD components. Over time, I have been slowly trying to switch over from through hole to SMD.

Wednesday, April 11, 2018

Long press on IR Remotes

We have looked at IR signals sent out by IR remote controls in a previous blog. So what happens when you keep the button pressed for a longer time? It depends on the remote control. Each one is slightly different but they fall into a few broad categories. I have access to a handful of remote controls and I used the IR Receive program mentioned before to analyse the repeat patterns. They fell into to two main categories - except for the damn Foxtel remote.