2021-11-20

ESP8266 vs ESP32

When I started using the Espressif processors I started with the ESP8266 and Arduino development platform. It is all C++ based (which is not really my favourite). But it is a really good starting point for anyone wanting to play around with microcontrollers.

One of the key things here is the available hardware. A "programming" lead is just a USB serial which is available for a few pounds, The Arduino development platform is free to download. But most importantly there are thousands of very cheap ESP8266 based devices on the market, easy to use, and many easy to access programming pins. The ESP8266 is possibly the most popular basis for IoT (Internet of Things) devices like smart light switches and the like.

However, having managed to make some PCBs (milled from copper boards) for ESP8266 based modules, I eventually decided to move on to using the ESP32. It had a number of advantages as a processor itself, but also the ESP IDF which works on linux and MacOS making it easy for me to code in C, which I prefer. The ESP IDF and various libraries are still a work in progress and far from perfect, but generally work well. I have made a load of projects based on ESP32.

But being ESP32 means I lack the thousands of ready made modules that I can use. I have designed and made loads of circuit boards myself, including a complete access control and alarm system.

What is now nice to see if that there are finally some ESP32 IoT devices coming out. Manufacturers are moving to ESP32 based boards. One of the most useful I have found is the Shelly 1. What is especially nice is it has direct pins for programming access - without even taking apart. It is simple, just a switch input and a relay output, but runs of mains, or 12V DC (do not use the GPIO pins when running on mains as they are live).

Shelly have just launched the Shelly plus 1, which is basically the same as the ESP8266 based Shelly 1 device, but ESP32 based. It also has programming pins easily accessible (though smaller), a relay and switch input. In this case the 12V is a screw terminal rather than a link you have to change.

The good news though is I can load my own code, ESP IDF based, on to this. It means I can use these modules directly on, say, my access control and alarm system. I had found I needed various simple 12V single input modules for the likes of a door contact or fire alarm input and previous used boards I made. But at this low price the Shelly plus 1 is a no brainer, as they say. Using my code I can set secure boot, and encrypted communications as part of the alarm system. Even something simple like an alarm bell could use one (single output for bell and single input for tamper).

My first actual project with one of these is for a servant bell system. I have an actual bell, which I want to "ding". I am using 12V DC, but the bell really only "rings" using AC. Using DC you need a small pulse to do a clean "ding". Too short and the clanger does not hit the bell. Too long and it hits it and holds, making more of a "clunk" than a "ding. Get it right and you get a nice clean "ding".

I was using tasmota32 code for this, but that is designed to do pulses of 200ms at least and not that consistent - perfect for blinking lights and the like, but no good for what I need.

So, back to my own code, ESP IDF based, using my existing libraries, and I am now starting something a bit like my own tasmota in a way - programmable inputs and outputs. Expect the outputs (which is all I have coded so far) are configurable to the millisecond.

I have found 15ms seems to be the sweet spot to make the bell ding...

2021-11-18

No, we don't have servants

But if we did, we'd need one of these beauties.

Well, the plan is to make this work for a friend of mine.

Believe it or not, it is "electric". With bare wires nailed to a board, and coils! With a bit of cleaning up and soldering, I have all the coils working.

With a bit of experimentation I could see how to drive this. I think I can even use what remains of the original wires which go round the back where they were just cut off. Basically the coils pull the swinging indicator, and on release it is left swinging back and forth. Oddly there is no sort of sounder, so I wonder how it worked to get people's attention. I'm planning an additional bell.

So, how to drive it - well it looks like a suitable resistor will allow it to work quite easily on a 12V supply, with a back EMF diode.

Relay board

One simple solution is an off the shelf relay board. Like I used for my DEFCON lights. One small snag is that they come with 8 relays and this needs 9 (10 if you include the bell).

Definitely a possibility though.

Custom board

Another simple enough idea is I make a relay board with 10 outputs. PCBTrain can turn these around in a day, and it may be a nice useful board design. I'm in two minds whether to use a relay, a solid state relay, or a driver (that drives 0V/12V). All could handle the approx 1A needed, especially as it would be a short pulse. I need to think about the other uses of these as part of the design, obviously.

The drivers are nice in that they take a lot less space, but are not as flexible as they drive the output rather than simply being an effective relay contact.

I also have to think how I make one of these - as almost all the chips I would use are on something like a year lead time! Thankfully I have several solid state relays and several driver chips in stock, and enough power supplies.

I could, of course, take the opportunity to consider using the newer ESP32-S2 modules, which seem to be available. This would all make this more of an R&D project, which is not a bad idea.

It would all take time though, and I am quite keen to have this ready for Christmas.

Shelly

There is, of course, a simple answer, and ironically likely to be the cheapest, and that is just use a Shelly1 relay module. Even needing 10 of them is not expensive, and there is space on the back of this thing. They are available and in stock for next day.

This does feel like cheating somewhat but may be the best option. Certainly worth prototyping with one of them to start with.

Then what?

One way or another I'll end up with WiFi connected indicators. So we need a way for that to work from places around the house. Buttons, or a pull cord, etc.

For this, by far the simplest is the Shelly option, as a light switch, sending an MQTT message when pressed.

P.S. Blogger is broken again, even with clearing caches, and so I cannot actually reply to comments!

P.P.S. I went with Shelly Plus 1, but my own code...

2021-11-14

Carbon cycle

I am pretty sure I did cover this in school, but I did not quite appreciate how significant it is.

One if the things that always gets me is the EXACT amount of CO₂ pulled from the atmosphere by a plant for it to grow, that I then eat, is the exact amount of CO₂ I then breath out from burning it (unless I use some of that carbon to get fatter, then that is released when one day I am cremated or eaten by bacteria). And the O₂ that is made by the plant growing is also the EXACT amount I need to use to breath to burn that plant and consume it. OK some of that goes in to poop that is used (O₂) and released (CO₂) when that is digested by bacteria. But the CO₂ is the same. It goes around in circles. The circle is complete. It works.

The carbon cycle is all about how carbon moves around in the world. Wikipedia has this the cool image.

So how to stop climate change? - it is so so simple - stop burning old carbon (i.e. fossil fuels).

It is fine to grow trees, make wood, and burn that, the carbon goes round and round.

It is fine to grow food, eat it, and breath out, the carbon goes round and round.

AFAIK cows farting is an issue, as that carbon ends up as methane with has a bigger impact, but AFAIK for less time, and apparently the answer there is feeding the cows seaweed! But generally using carbon to grow food to feed and animal that we then eat and breath out is again OK, carbon goes round and round.

Don't get me wrong, loads of other issues, too many cars and not enough walking and cycling, all sorts, but just looking at climate change, it is all down to the carbon. We'll improve a lot of other stuff by fixing the climate change issues as a side effect!

Almost anything we do with "recently" captured carbon then going to the atmosphere matters not a jot. Pull carbon from atmosphere and release it a year later - not problem. What matters is all that old carbon in fossil fuels being burned. Unless we want an atmosphere that was around a few million years ago, we need to stop.

Even all the "indirect" stuff, like carbon cost of manufacturing and transport, only matter when those processes use fossil fuels directly or indirectly. Make those processes use electricity or hydrogen from green supplies (not from fossil fuels) and they all end up carbon neutral.

The one thing, and this really is the one thing, that matters, is burning old carbon. Stuff pulled from the atmosphere millions of years ago and stuffed in the ground. Burning fossil fuels. That is what matters. That is what needs to stop. It really is as simple as that!

Heck, even making fossil fuels in to plastic which we don't burn, is not an issue! What matters is old carbon going to the atmosphere - STOP IT!

Blockchain is not the answer

Often people come up with some idea and think "blockchain" is the way to do it.

In pretty much all cases the answer is "NO!", or more often "Hell, NO", seriously. In a lot of cases the thing people are doing is something which can be, or already is, done by a central authority registry. Don't get me wrong, even a central registry may "sign" things digitally, and have signatures or signatures in a block chain style, but that is not what people mean when they talk of putting things on "blockchain".

Blockchain, as most people mean it, has some serious disadvantages too - and I mean using blockchain like the way crypto currencies are used - it means explicitly removing any central "authority". It means if you lose keys to your wallet you have lost what you "own" and no way to recover that ever. E.g. people have somehow suggested this should work for domain ownership, which is batshit insane IMHO - far better as a central authority (per top level domain), and allows the authority to resolve disputes even, and recover "lost" creds, and so on.

But hear my out - I have an idea - a sort of "ownership" which could maybe benefit from not having a central authority.

Buying a movie!

One of the things one can "buy" which is a tad on the intangible side is "a single copy of some copyright work". E.g. if I buy a movie. Once upon a time that meant I buy a physical media copy of it. You can still do this even. And you can give or sell that copy to someone else even. That instance of a copy of the movie is something that can be moved between owners as the physical object that it is.

The whole of copyright law is around the notion of "copying" a thing, so the physical copy is the key aspect here. That is all rather outdated now as copying is so basic and simple and free for data. The right more rightly exists for something like a movie in a right for me to watch that movie, not any sort of "copy" process.

However, we now live in a world where I "buy" a movie on something like Apple TV. Now this is a lot less tangible, and is more of a "licence" to "play out that movie" from "Apple TV" data storage via any of my many Apple devices.

That does not feel as useful as holding a DVD in my hand which I own. If Apple TV stopped, I could lose tens of thousands of pounds worth of video library that, in theory, I "own".

Obviously there could be some digitally signed licence of ownership of a copy, signed by the copyright holder's published public key, and identifying me. But identifying me is tricky in itself - email address? name? what? What if that ID changes?

I'm thinking this is where blockchain comes in. If a licence to own and instance of a copyright work can be created on the blockchain as owned by my digital wallet, and signed by copyright holder, then I can present that as proof to AppleTV or someone else, that has streaming services. That would provide proof that they are allowed to stream that copyright media to me. I'd have to use my wallet to sign in somehow to prove it is me, which adds to the complexity, but it identifies "me" in this context.

But it would also allow me to sell my copy to someone else if I wanted to.

It would allow for a provider that sold me the copies in the first place to go bust and I would still hold my digital wallet proving these copies are mine and I could take that to some other streamer service, even if for a nominal fee to load them on to their system.

Any such system would have to be wrapped in consumer friendly UI. It could even be a bit "behind the scenes", in that Apple could effectively manage my wallet of things purchased via them - as long as I can always obtain, and take over that wallet and legally I own it - maybe it could "live" in my apple devices that I own as a fallback, locked with my AppleID passphrase. But it could work

It would almost certainly be impossible as it would require co-operation of copyright holders, and streaming services, and the like, and possibly even legal backing. It may mean streaming services separately "sell" copyright works, and provide streaming of them for some ongoing subscription so if you come to them with your "owned" works they are not losing out.

But I think as a commercial and legal model it could, in theory, work.

I also think there is no chance of it happening :-)

2021-10-31

DEFCON Lights

A bit of fun for a change... 

Firstly, seeing as even some of my geeky mates did not know this, the US has a DEFCON level (defence condition). See wikipedia for more. There are images of DEFCON lights in a variety of films/shows (including War games, and Stargate). DEFCON 1 is most severe.

I saw RS did some rather nice 12V LED indicators, which I was using for a different projects, and realised they would make quite nice DEFCON lights.

So the shopping list:-

  • RS 791-8579 White
  • RS 791-8573 Red
  • RS 791-8589 Yellow
  • RS 791-8582 Green
  • RS 791-8585 Blue
  • RS 877-1836 Sounder
  • Amazon relay board
  • Amazon box
  • Some wire and Wagos, and I have a 12V supply in the house.

The relay board is simple, ESP12-F based (ESP8266), so flashed with Tasmota and configured the relays 1 to 8. Note these are not ideal boards as they have ground plane around the antenna. I may have to make a relay board some time for a different project that needs 9 relays, but this was fine for this fun project.

The LED modules are simple enough to wire up. As is the sounder.

The result all connects to an MQTT server over WiFi. The relays are set up on tasmota, but relay 8 (the sounder) has a pulse time set (1 second) so I can simply turn it on to make a beep. I did consider a flashing strobe light as well, but meh...

The next challenge was to work out how to drive it sensibly. Setting a light was simple, I did a cmnd/DEFCON/Backlog Power0 0;Power3 1;Power8 1 for example. This turns all lights off, turns on light 3, and makes the sounder beep for a second.

I use a FireBrick as the MQTT server, so I created some profiles for DEFCON 1 to 5. Each is testing if DHCP is active for some IPs on the WiFi, and if the higher levels are all off so only one at a time. They then have that backlog command as the "on" MQTT command with retain.

This means that I get a DEFCON depending on who is in the house. DEFCON 1 for presence of the those who shall not be named (anti-vax). Cool or what?

P.S. I am sure Letraset used to be a thing - finding transfer numbers was not easy...

2021-10-26

The COVID experience (vaccinated)

Sorry to say that COVID has managed to finally hit many of our family, in spite of (almost) all of us being very careful in lots of ways, and (almost) all of us having vaccines.

My wife has also been unwell, but we are both starting to get over it now.

I have spent the last 10 days or so feeling like shit - started like a nasty cold, and LFTs every day negative, but finally on day 4 it was +ve LFT, and then +ve PCR.

It was not until around day 8 that I lost my sense of smell, which is just weird - my nose is clear now, but I simply cannot smell, not even my ground coffee. I can still taste but it is a bit off.

Someone else described this, and I am inclined to agree - it felt like it was trying to get on my chest, but thankfully did not manage it. Even so, my blood oxygen levels dipped quite a lot. I can only imagine how bad it would have been if I had not been vaccinated.

It has been ups and downs a bit - on day 7 I really thought things were getting a lot better, I felt mostly fine with a bit of a blocked nose. I then spent days 8 and 9 in bed!

Sadly, at least one person that has now got it was unable to have a vaccine, and it looks like a newborn has it too. These are worrying times for all of us. We can only hope they recover quickly.

And those that have not got it have had to run around shopping and getting medicines for those that have - and we really do all appreciate that.

Remember, you are only as strong as the weakest link - make sure you all have your vaccines please! Don't be put off nagging people to get their vaccine, as I was. Personal choices are important, and make good sense right up until those choices impact others around you - then they are no longer just personal choices. Vaccines don't just help reduce the risk to yourself, and your family, but help reduce the spread and mutations. Getting a vaccine is being part of a community.

I do now have some IgG and IgM antibodies though. These did not show after the vaccines, which I believe is to be expected as they are different.

But everyone, stay safe.

P.S. Whilst the isolation is over, there are some symptoms lingering - a simple walk to the shops made me tired and out of breath, and I still have an annoying cough, even if no longer infectious. It will be interesting to see how long this lasts. Day 12 - can just about smell the coffee again.

P.P.S. The lingering cough is not fun - just spending an hour on a phone call really kicked it off and felt grotty for rest of the day. No idea how long this will go on for. ... Weeks later and still up and down with this.

P.P.P.S. It has lasted over a month, on and off, but finally feeling at lot more normal now.

2021-10-17

Tasmota thermostat

The tasmota code has a proper thermostat mode, but it is not in the pre-built code, so I wanted to work out a way to do this with simple rules.

There are examples, yay... But I was struggling to make sense of these.

A simple example, say I want on at 25C and off at 29C...

The obvious rules are something like this :-

ON DS18B20-1#temperature>29 DO Power 0 ENDON

ON DS18B20-1#temperature<25 DO Power 1 ENDON

This works, but every second or so it is doing Power 1 or Power 0 constantly, and reporting that on MQTT, which is a tad annoying. It is worse if you have triggers on power setting to send publish commands to other things, etc.

The other examples I have seen seem to have a similar problem, I think. Some seem to have a timer that reduces the chatter but still, I just wanted something simple that only actually logged something and only actually changed power setting, when the temperature threshold is crossed.

What I came up with is not complicated, and seems to work:-

ON DS18B20-1#temperature>%var1% do backlog var1 999;var2 25;power 0 ENDON

ON DS18B20-1#temperature<%var2% do backlog var2 -999;var1 29;power 1 ENDON

The trick is the this sets the var1/var2 meaning that the temperature is no longer triggering an event all the time once it has changed.

Bingo, it works, and is a pretty simple pair of rules. Probably worth using mem1/mem2 as the 25/29 values here to be tidier, but still. Not complicated, and reacts immediately when the temperature passes the relevant threshold.

It also means the sensor can be a separate Shelly from the relay easily, only sending the publish to change the relay on change, which is also a big improvement.

P.S. For those that do not know, a Shelly 1 is a small ESP8266 based relay/switch that can switch mains power (16A) and typically about £8 (the blue round box). It has good firmware anyway, but Tasmota is an alternative firmware (open source) which can run on most ESP8266 and ESP32 based smart devices, so can run on a Shelly 1. DS18B20 is a common temperature sensor, and more than one can be connected in parallel even (the black wire and metal tube). Shelly do an adaptor (needed for DS18B20 as they would otherwise be mains voltage) to connect to temperature sensors (the black round thing on the Shelly 1).

2021-10-15

Mitsubishi Lossnay+GUG aircon (not actually working)

We have a bit of a mystery here - the brand new, expensive, ducted air-con in the house does not work!

So what does not work exactly?

Not actually able to cool a room!

The biggest issue is it cannot cool a room - not even close. (It can't heat one much either)

This is a temperature plot for my study, 3m x 3m, you don't get a lot smaller than that in terms of a room to air-con. A=Portable unit on, B=Portable unit off, C=Start two hour cool only full fan test.

The test was with the other room vent closed so the unit was only cooling one room, in to a closed empty room, no heating on anywhere in the house, and outside temp of 19C. Not a challenge for any air-con really, and as you can see, the cheap portable unit managed with no problem (even with the door open most of the day). And yes, the fan speed control does work, and was on full.

I expected at point C the room to cool at least as fast as the cheap portable unit. What happened is it just about managed 0.8C in two hours! It was blowing cold air (measured at 9C) but not as lot...

The fix - well, the unit only has a 100mm vent in to the room. This seems small I must admit, and at full fan like this it is noisy. So they are changing to a 150mm vents today...

Did it work? In short, no. The bigger vents are quieter, which is nice, but the same tests showed maybe 1.5C drop and bottoming out just below 21C after more than an hour. Compare these big 3.5kW systems to a much cheaper 1.5kW portable unit which is able to drop my study (and hall way as door was open) from 23C to 18C in 15 minutes. With the door open the new air-con cannot cool my room at all!

This is now waiting on Mitsubishi to explain and fix. I won't say who the installers yet as they have been pretty good. Let's give them the chance to get Mitsubishi to fix it all.

But how is this even possible?

The issue for me here is that they sell this system, even with the smaller 2x 100mm outflow vents. So forgetting, for a moment, whether the suppliers got it wrong for the rooms we are trying to cool (two rooms each unit, one of which is much bigger than this 3m x 3m study), we have the issue that this whole unit running at full cooling and full fan cannot cool a 3m x 3m room.

So what the hell is the this unit for - what size room are they expecting it to be used with, ever?

The change to 150mm vents actually meant them cutting out the larger holes as the cowl as it is only supplied with the 100mm outlets.

This leads me to think something else is wrong, but we have no idea what. How could this ever work anywhere?

Cannot set temperature!

The controller has options - either "return air" temperature measured at the lossnay unit, or the room temperature at the controller. The controller has a sensor in it. Given that we have two rooms per unit, we are using the temperature at the controller (which is not in the room with the return in it). This is all as per the manual.

Only it does not work! Cooling the room down to 19C (using the portable unit, obviously), it showed 24C. Indeed, it even went up from 23C while we did this. Using freezer spray actually on its sensor does nothing, still 24C. No clue where it is measuring but it is not in the room - we even tried putting hot air in the room that has the return air flow but that did not make it go up at all.

The fix: Well, again, waiting on Mitsubishi.

Watch this space.

2021-10-08

New Mitsubishi Ducted Air-con with Lossnay (bad user interface)

As some of you will know, I have moved to sunny Wales. My new home did not have air-con so I am finally having that installed. I have gone for a ducted system this time (yes, more expensive) as it allows simple vents in the ceiling rather than a large indoor unit in the rooms, and it should be quieter. However, the main reason is that we now live on a main road, so cannot really open windows to any of the bedrooms - the ducted system I have gone for has a "lossnay" which provides fresh air as well, and saves us having to open windows. More on the actual aircon later, this post is just about the quite unbelievably bad user interface.

For a start this is an "industrial" air-con, which sadly means it is a simple wired controller and not WiFi, or anything useful like that - do not be surprised to find a "reverse engineering Mitsubishi air-con controllers" in a future blog post :-)

The air-con is three parts, an outdoor unit, and indoor unit (GUG) which does the cooling/heating, and a lossnay which does the fresh air (filtering and heat exchange). This is in the loft...

The lossnay is on the left and the GUG is on the right. To be clear, the GUG is designed to work with a lossnay, it cannot work without one as it has no fans of its own. I think the lossnay could be used for fresh air without a GUG though.

Controller

The controller is not too bad, it has a dot matrix LCD and buttons. It is newer than some where they have fixed icons on LCD. It has the obvious controls: mode, temperature, and fan speed. Good.

But, no. The fan speed says "unsupported function" if you try and change it. You need to have a separate "lossnay controller", which basically just lets you set the fan speed.

But there is a 4 wire link cable between the lossnay and GUG, what the hell is that used for? Well, all I can see is that it means is it turns off the lossnay when turning off the GUG. Remember the GUG can only be used with a lossnay attached, this is not some obscure optional extra.

We (myself and the installer) found the setting to tell the GUG it has a lossnay connected (but this unit cannot work without one so why is there even a setting?!), and it shows a nice icon indicating it has a lossnay. But still does not let you control the lossnay from it. Why? Also, the icon looks like it shows the "mode" the lossnay is in (yes, it seems to have a non heat exchange mode, which is pointless) and fan speed, but in fact the icon does not change to actually show the mode or fan speed. How shit is the UI?

Apparently you can run the lossnay without a controller, and the GUG will turn on/off at full fan speed, which is not that useful.

Of course, this also means you cannot run the fan in an auto mode as the lossnay does not know what the GUG is doing. So you cannot have full fan to get to temperature and quiet fan to maintain temperature.

Oh, and crossed zeros. A pet hate of mine. This is not a hand written COBOL coding sheet in the '70s, it is a temperature display. Why make it look like 28℃ not 20℃ to anyone with poor eyesight?

Another gem is that you can turn the temperature down to 12℃, nice, but then it snaps back to 19℃. Why 19℃, that is way higher than I have seen on other air-cons - it will probably do as I would rarely want it that cold. But still, why? And why allow setting below that if it cannot be set lower? Just stupid UI again!

Another thing that seems odd is that the controllers are identical. Same display, and buttons. Looks like identical hardware. The lossnay controller even has a thermometer in it even though it does not need it. But they must have different firmware as they cannot be swapped around. I would have made one controller and made it generic to work anything, but no, they are different!

2021-09-23

A use for the keypad

The Solar System alarm that I have created does work with a standard Honeywell Galaxy Mk7 keypad/display module.

However, until now, I have not really managed to work out a good use for how the keypad can be part of the system. But I have been working on that.

We now have clear display of inputs that trigger alarm, or inhibit setting, or faults, or tampers. We have setting the alarm, and unsetting using a PIN. Yay!

The way it all works is down to a small PCB, designed to fit inside the case of the display. It works off the same 12V supply, and provides RS485 to the keypad/display.