Search This Blog

Showing posts with label diy. Show all posts
Showing posts with label diy. Show all posts

Thursday, 2 November 2017

"A bit cheeky..." 2

The SMD soldering went..er...let's say it just went. I don't usually enjoy it, but the results didn't look too shabby. After a quick "smoke test" with the meter, I checked for continuity where expected, and not where it was not. All good.

Then - just to show how paranoid (read "safety conscious") I am with mains electricity - I built this little rig so I don't have to go anywhere near it while its under test and can be done fully hands-off. So much so, that the mains plug is into one of my WiFi truc devices and switch remotely from the bench! "The management eats here".

The PCB is a 1" square type that I came across on ebay some while ago - they are absolutely indispensable for knocking together little bits like this: buy them here. The came as 24pcs for eu6.62 or a measly 28c each - my kind of component. I always keep plenty in stock.

Anyway, once the power went on:


I would have hoped for a little closer to 3.3v but a) its all cheap parts b) its a cheap meter c) I'm sure it will be fine d) I'm over the moon it worked at all!

Find out if I'm right when I start the first "production" build of my ESP-01S powered wall switches which this PSU is for!







A bit cheeky...

I recently bought some of these AC-DC converters from ITEAD to run my truc devices from the mains. Mainly they are Wemos D1s but I also decided to build smart wall switches using ESP-01S as they are very small - but they run on 3.3v.


Click here to buy them yourself

"No problem...", I thought - "...looks like they do 3.3v too - bonus!". If you follow the link above to buy one, you'll see that ITEAD's latest photo has no 3.3v pin any more and on closer inspection of my own units, I can see why:


Seems that they are economising the few extra cents per unit of a 3.3v LDO...To be fair to them, the unit is clearly advertised as 5v and that's what I bought it for, but I couldn't help thinking "a ha'porth of tar..."

I also couldn't help thinking that if I could buy a few cheap LDOs in SOT-89 format with the right pinout, then I could right this "wrong". Don't misunderstand me, I'm very happy with ITEAD products and I have bought a lot of them - I trust them and I highly recommend this one, but...you know what I mean?

Anyways, it took a little research to find the right part, and as usual (I get the majority of my components from ebay.com) I found a seller doing five AP1117Y33L (here) They are incorrectly tagged as "Diodes" - but that's half the fun of ebay isn't it? Either way, they are what I needed.

There's a whacking great cap on the input side (470uF) but - as you can see - none on the output side. The datasheet for the AP1117Y33L states it needs a 22uF cap on the output for stability. So as long as I hook one up there on the final board, I should be "quids in".

Now all I have to do is a) bemoan my failing eyesight and b) get the fine tip on my soldering iron and "bite the bullet". If you aren't a big fan of soldering SMD parts ("fiddly" ain't the word), look away now...

I shall report back in due course.






Wednesday, 1 November 2017

Testbed 6 - the "Mothership"

The last piece in the jigsaw is of course the Wemos D1 mini, which runs everything. So here, she is: the "starship enterprise" ready to boldly go...well, onto my landing to be precise.


Once in place, I can do a final full systems test and get the raspberry Pi NODE-RED controller ironed out.

Before that happens I'm going to build a "production" wall switch using the ESP-01S + touch controller and wire it up to the mains.

Finally, I will put together some videos showing it all working "without its clothes on" including the NODE-RED controller and the Esparto live web interface built-in to each device.

Then...phew!...I may will release the long-overdue Esparto v2.0. Anyone can then download and use it on Sonoff, Wemos D1, NodeMCU, ESP-01S etc which will reduce the 6months+ lead-time its taken me to about 15 minutes to get a fully functional MQTT-controlled IOT box up and running.

My next post will be a "sneak preview" of Esparto v2.0 as running on the very piece of "Heath Robinson" junk you see above...




Testbed 5 - The "business end"

The whole point about most IOT devices is that the switch on a mains-powered appliance. In the real world (and my "Chez Toi ioT" home automation system) this will be done by commercially available Sonoff devices. The main ones are the S20 sockets, but I'm also going to deploy a few "Basic" modules in places where I'm never likely to change appliances (dusty corners, overhead lights atop beams, for example) and the low-voltage (or "safe voltage" as ITEAD call it) SV model.



The SV will be powered from a 12v battery and kept "topped up" by a solar powered controller. These units will be set up on buildings away from the main house, driving PIR lights so I don't have to go running for a half-dead torch every time I hear wild boar ripping up my lawns. I'd also like to be able to switch them on remotely before going out as there is a lot of ground to cover in the dark in some parts of the "estate" before the sensors will pick me up.

 So the "business end" of all my devices (apart from the wall switches) is a power relay and so my testbed has to have one. I have chosen the ubiquitous (on ebay at least) Omron G3MB-202P which is only rated at 2A, but I'm only going to be testing it with a single low-wattage lamp plugged in: all I need is to see it go on or off at the right time.

Now then, here's the thing with 3.3v devices: the solid-state G3MB needs 5v to switch cleanly and it also "draws" way more current than a GPIO pin can give or take for long periods, i.e. it needs about 20mA. So a "driver" is essential. A single 2N2222 is wired with a 10k base resistor into the GPIO. The "top end" of the G3MB relay is wired to 5v and through the LED to the collector of the 2222. The "bottom end" is wired - with the 2222 emitter to GND. It's about as simple as you can get, providing both the necessary level conversion and sufficient drive current.

Now we are almost ready to go...

Testbed 4 - more sub-assemblies: temp and rf433

This one has the (very "bouncy") tact button that all my IOT devices have on GPIO0
  • quick press: switch on / off
  • medium: reboot
  • long: factory reset


It also has the TMP36 temperature sensor and the output module to transmit RF codes to my "el cheapo" sockets: These are what I bought for the 300+ year old farmhouse before I had the (insane) idea to replace everything with a fully-fledged WiFi IOT Home automation system.


Being one who doesn't have a lot of cash to splash, I wondered if I could re-use them...Then I found the wonderful rcswitch library https://github.com/sui77/rc-switch and I found some ridiculously cheap RX/TX pairs on ebay (buy similar here) 5 sets for eu2.79 or 56c a pair. So the TX you see here set me back - what - 28c? I love cheap.

Setting it up was easy: The rcswitch lib has an example that uses the RX to read the codes of the handsets. I was short of Wemos D1s at the time, so I dragged a dusty old Arduino UNO out of a drawer and had the code running in about five minutes flat. I captured all the codes from my four handsets for on and off. I then knocked a little transmit library for the Wemos with a few "hard-coded" values and no-one was more surprised than me to hear the happy sound of clicking less than an hour or so after I started! Tweaking the code, removing the hard-coded values and setting up the automatic re-configuration then occupied me for the next few days, of course...

Now my system uses these as "slaves". Each "truc" or Wemos-controlled "big box of sensors" reads MQTT configuration data at startup to see which RF switches are linked to it. When it next switches on or off, it automatically sends the RF codes to make all its "slaves" match. In the real world, the main box would be wired in with the overhead light in each room, and the el-cheapos would be floor lamps, or corner lamps. When commanded either by touch or remote MQTT, all go on/off at once.





Testbed part 3 the Wemos sub-assemblies

I like to try various different (cheap) sensors to find which ones are best in terms of:
  • build-quality
  • flexibility
  • size (they have to fit into Small boxes eventually)
  • price (as I'm going to need several of each)
To make life easier, I have done two things: 1) I have made everything modular from the start so I can just "swap out" various gadgets. This also makes testing the code a lot easier too: it's done one chunk at a time. 2) I have modularised my code too and written a library which adapts to pretty much any sensor type and does all the "heavy-lifting" for me. Try it out: http://github.com/philbowles/smartpins

The library is what allows me to do this in my main IOT firmware "Esparto":


Which is a real-time display of what all the pins are doing. One neat feature is that the pin descriptions change for each board type (NodeMCU, Sonoff etc)

Anyway, the "main" sensor module looks like this when dismantled:


And like this when assembled with the smaller of the PIR sensors:


There is plenty of debate as to whether the ESP8266 can tolerate 5v on its GPIO pins. A lot of folk say you can - but I'm not going to chance it when a) 3,3v works fine with most sensors* and b) once my IOT devices are deployed, I can't afford to rip down walls or climb ladders when I find out that most folk meant "...for a while" and never "soak-tested" their findings...Always best to play safe where electricity is concerned, as I have found (to my - ouch - cost) on more than one occasion.

*The PIR sensors are a good example. The larger one has an onboard 3.3v LDO, so even when fed 5v, the signal out is only ever 3.3v max, so it goes straight into a GPIO. Oddly, even when fed only 3,3v, it still works fine. The smaller one (fitted) will run with 3.3v but it  will not trigger. It has to have 5v to function properly.

The light and sound sensors are both marked with 5v Vcc on the boards, but both work fine with 3.3v - some don't and that's why a) I went modular  b) experimentation is the only true way to find out - but test the OUT pin with a meter first!!!



Wemos "tripler" base - design flaw "gotcha"

I love Wemos products. I still do despite this discovery. I have been using their "doubler" bases for a while and they make life very easy. As my IOT project expanded towards completion, I needed to connect several sub-assemblies.

To my great joy, Wemos announced the "tripler" and I ordered three from an ebay seller. They are solid and well-made (as I'd expect from Wemos) and are just what I needed.



Well, almost...

I was 90% of the way through soldering header pins to the first when I realised problem no. 1:

The spacing between the 3 layouts is NOT breadboard-friendly! Between 1 and 3 it is, and there is a common GND/5v/3v rail between all three layouts, so it's not a major disaster, but certainly worthy of note. After a little de-soldering and I was soon back on track, till I met problem no 2.

Each of the "boxed" and silkscreened sets of pins are connected. The left-hand side tracks are clearly visible and each right-hand layout has the corresponding tracks in the underside of the board.

EXCEPT ONE PAIR ON ONE OF THEM!!!

The "inner" 5v pin on layout 1 is open-circuit. Every other 5v pin is connected to every other 5v pin, except this one, which is connected to...nothing. You will need to "jumper" it!


And yes, dear friends, that kept me scratching my head for quite a while before I found it. A simple continuity test with the meter confirmed that it wasn't just my failing eyesight...

"Experimentation always beats assumption". Don't bother searching for that quote, I just made it up.

Testbed part 1

Here is the testbed I built to cope with both ESP-01S and Wemos D1 Mini devices.

It has mains input which is fed to a relay board and then on to the actual appliance (usually a lamp) - this is used for final testing, which is all remote (via MQTT) as I don't like going near bare mains wires - and neither should you!

Most of the "bench" testing is done with 12v input from a PSU which is dropped to 5v by an L7805. That's fine for the Wemos D1, as it has an oboard 3.3v LDO, but when I'm testing ESP-01S, it doesn't, so there's a socket to take an external 3.3v LDO (an AMS1117) on a 3-pin breakout board.


The baseboard itself is from a company that doesn't seem to make them anymore, which is a shame as they are solid, rigid and very well-made.

Next comes the Wemos "tripler" base - a lovely piece of kit, but with a serious "gotcha" (see later post)


And then the separate sub-assemblies each of which I will detail in a separate post