Nixie clock prototype

Lasercut nixie clock prototype

This caught my eye at yesterday’s Open Hackspace session: Alex wired up the nixie clock he’s been prototyping, and got it mounted in a lasercut case. As good at it looks here, the phone camera doesn’t do it justice!

Other projects being worked on yesterday included a pedal-powered phone/GPS charger for an upcoming cycling holiday (which now works perfectly!), an improved bed for the lasercutter, some wooden shelf units, a network-controlled table lamp/sensor package, and the usual mix of teaching, swapping ideas, and terrible jokes.

What do you want to make? Turn up to one of our open sessions, or get in touch by email, and see what your local Hackspace can do for you!

Hacking De-bounce and Rotary Encoders

Prototype console interface for embedded projects

Prototype console interface for embedded projects

At the UK Makerfair during a brief lul the conversation turned to rotary encoders, simply as I had ordered a paw full from china for one of my many projects that simmer along in the background. The picture here shows the initial prototype that I used for this article. The feedback about rotary encoders that I received was that they were terrible and to be avoided. Principally as the switch contacts were very noisy and produced way too much bounce. I was still interested in using them firstly as having done embedded stuff for years bounce is something I consider trivial and fixable, secondly as they make a really cool, easy and feature full user interface using the minimum of pins.

De-bounce circuits

De-bounce circuits

The circuits I most commonly use for de-bouncing simple switch contacts are shown in the picture here. I ran this up in Kicad for the article. Something worthy of note is that Arduino’s and a number of other micro controllers have internal pull-ups that you could use. Do not use these when de-bouncing your inputs. They vary very widely in effective resistance value and the results will be massively variable when used with the same external components. Indeed a quick search of the internet shows a range of circuits and values mostly with a string of comments along the lines of someone found a different value or combination to work better. What is happening here, and why so much variability of what should be a trivial, bread and butter type, of interface circuit.

No de-bounce

No de-bounce

Time to dig out the Bitscope I bought from Pimoroni a while back and capture some waveforms. It will work as a capable enough DSO for this investigation. On the left is the A output of the rotary encoder from the previous picture set-up as a switch with pull-up as per the schematic above. The value of the pull-up resistor in this case is 10K Ohms a fairly typical pull-up value. The large nice square pulses are the outputs from the encoder and the very narrow horrible pulses are the switch noise and bounce. This looks reasonably what I would have expected although the switch looks to be more noisy than bouncy. I spun the input shaft quickly by hand to get enough pulses into shot and it is noticeable that the rubbish pulses produced are proportional to the speed of spin. The other thing that is noticeable is the duration of the pulse are quite short. With a standard press button you can not move your finger that quick and a de-bounce period in software of around 10mS is not uncommon. In this case though, if you did this it is clear that you would be missing a lot of steps from the encoder. Each one of those noise pulses is a full logic value in height and will trigger an interrupt, giving you a wildly incorrect count and wasting a whole shed full of precious processing cycles. I can see why you might think they were to be avoided if you had not de-bounced them in any way.

100nF De-bounce Capacitor

100nF De-bounce Capacitor

Adding a 100nF capacitor as per the above schematics produces the results below. This produces a very large reduction in the height of the noise pulses but they are still large enough to trigger some interrupts, the amount of processor time we waste though is reduced. The number of incorrect counts is also reduced but there are still some present. Also look at what is happening to the corner of the rising edge of the pulses that we want to work with. They are no longer square and are being rounded off. So a big improvement but still not as good as we would like. In a simple switch this rounding etc is not a problem. We are working with a rotary encoder though and the relative position of the edges in each channel is important to us. Where an edge curves too much it becomes unclear where the micro controllers input will decide it has switched from logic 0 to logic 1. If we got such a big improvement for adding in 100nF, will adding in some more be helpful?

200nF De-bounce capacitor

200nF De-bounce capacitor

So lets add in another 100nF capacitor in parallel across the one we put in last time. Taking the total up to 200nF. Yes the noise is reduced much further and we could probably work with that at a push. But look at the state of the rising edges. As we increase the capacitance we increase the loss of definition of the rising edge and consequently our ability to correctly resolve the direction of the encoder. The faster the encoder is turned the more problematic this becomes as the curve remains the same width but the width of the pulse we are relying on has become narrower. We could have kept the capacitance value the same but increased the resistance to say 20K and we would get exactly the same result. The RC network that is cleaning up our signal has a time constant that is proportional to the ratio of the resistance and capacitance that makes up the circuit. It is this time constant that is low pass filtering the pulses and giving us the effects we can see on the scope. Bearing this in mind if we check out the Atmel AVR data sheet, as this is the most popular micro-controller in the Arduino series, we see that the internal pull-ups have a value of between 20K and 50K. So a massive variation in the pull-up value and consequently a massive variation in the de-bounce action and on our pulse edges is produced by this, hence why de-bounce circuits that use the internal pull ups are to be avoided. We need results that are consistent.

For a simple press button a simple RC network as shown in the above works great as it is a very slow logic signal, but what can we do to recover nice square edges on our fast, encoder signal pulses, and get rid of the noise pulses. The answer is to use a Schmitt Trigger which increases the level at which a rising edge will be consider to have switched from low to high and reduces the level at which a falling edge will have switched from high to low. This circuit will ignore the noise pulses that we have reduced in height leaving us with a clean pulse train and nice square edges from our encoder. Check out the linked wikipedia article, ignore the over complicated mathy explanations and control theory waffle look closely at the wave form diagrams at the top right of their page. What is more this circuit is so useful that it comes already built in to a number of inexpensive logic gates. You don’t need to make one.

Unfortunately I don’t currently have the parts to hand to show the fully processed pulse train but the procedure is to add in a Schmitt Trigger logic gate (ie a 74LVT14 or similar)  as per the diagram above, pick the pull up resistor value for your chosen application 10K is good for most applications, looking at our scope waveforms you may want to go to somewhere conveniently around 20K. Then starting with a small capacitance for the de-bounce capacitor increase it until all your noise pulses on the output of the schmitt gate have gone. Using your scope to see when this happens. Once you have achieved this you know what the correct values are and can pick the nearest off the shelf value to use every time and get repeatable results. What’s more you will not be wasting any precious processor cycles on clever de-bounce code and unnecessary interrupts.

Take away points from this are:-

  • Do not use the internal pull-ups with de-bounce circuits it is a false economy.
  • Simple RC circuits are plenty good enough for simple push buttons and switches.
  • You need a logic gate with a schmitt trigger input to clean up the faster logic pulse trains from rotary encoders.
  • You can do a lot of electronics and get an intuitive grasp of what is happening by laying on a scope and laying off the math.
  • Clean up your signals before trying to code them clean, crap in equals crap out.
  • Rotary encoders are great if you know how to work with them.

Homemade smoke machine liquid!

A quick experiment by one of our members, in preparation for making a gun that shoots smoke rings.

(for anyone playing along at home: Mix 30% glycerol (also called glycerin) with 70% distilled water, and heat. Ideally, don’t do it in a small hackspace where the windows don’t open and other people are trying to make stuff. Oops.)

Mini PIR Sensor

Mini PIR Sensor

Mini PIR Sensor

I bought some of these mini PIR sensors on aliexpress, for the occupancy detector part of my ongoing NoTLamp project. They can be found for just under 1 UKP each. I want the NotLamp to work efficiently as it will be powered all the time. I also want it to all work from a single simple power supply and have chosen 3v3 as the lowest common denominator. I am taking the decision to work at 3v3 more often than 5V these days as so much is produced with 3v3 in mind. A big annoyance is the amount of 3v3 boards etc that are made 5V compliant and then used with other micro-controllers (ESP8266) or Pi’s that are 3v3. Very wasteful of both parts, and electrons. This picture shows the mini PIR sensor on top of a business card and next to a 20p piece so you can get a feel for how mini it really is. These little units are very simple with nothing to adjust and no daylight sensing, they are aimed at whole raft of people sensing switches etc and are designed to work across a wide voltage range from 4.5V up to around 20V. They have the part number DYP-ME003SE-V1 but can also be found online as an HC-SR505. These look to be almost identical bar the addition of a single capacitor on the front. I could not find any schematic for them which was disappointing, all the links claiming to point to a schematic take you to a schematic for the HC-SR501 the bigger brother to this one which uses a larger BIS0001 PIR chip.

Mini PIR Detail

Mini PIR Detail

These pictures show both sides of the board close up and side by side. In the left one you can see a 3v3 linear regulator and polarity protection diode, Those and the PIR detector at the top of the board look to be the only parts that are common between the two types of PIR sensor mentioned above. The IC is half the size of the BIS0001. The output is a 3v3 logic signal. Looking at the left hand image there is an unpopulated footprint to mount an S8050 NPN transistor for switching a relay or level translating the signal. You will also need to remove R1, just next to it if you want to do this. The presence of the 7133 3v3 regulator though is promising for my application as it shows that the circuit itself actually does run at 3v3. Just for the hell of it I tried the PIR at 3v3 and 5v to see how it did. It preferred 5V and worked reliably but dropping the voltage to 3v3 (Actually the test Arduino was putting out 3.73V) gave some interesting results. The device powered up and seemed to work OK but after triggering the detector the first time it re-triggered itself cycling on and off for its pre-set delay period. I counted the delay and it was around 10 seconds give or take a bit. Probing the underside of the board I found that for 3.73V in the protection diode was dropping about 0.2V giving 3.55V and the low drop-out (LDO) 3v3 regulator appeared to be dropping nothing. This was not very promising as the board should run at 3v3, given the presence of the regulator. Time to warm up the hot air pencil and iron then perform some surgery.

Modified PIR

Modified PIR

I first removed the regulator, and consulting a data sheet for the pinout, shorted the Vin to Vout pads where the regulator used to be. You can see how I did this in the before and after shots in this picture. Powering it up from the same source I checked the voltages but found it was performing exactly the same cycling of off to on all the time. So the cycling problem was not the regulator struggling with the low voltage. The voltage on the board side of the protection diode now measured 3.55V so given that PIR detector draw crazily low currents it should be working. But wasn’t. Given it was not looking very promising but I could not figure out why I removed the protection diode and placed a short across those two pins. Completing the modifications in the pictures. Now It worked fine exactly as it had done at 5V but now at 3.7V. So these were the mods that were needed to make the units I have functional at 3v3. Given the strange results we had been getting I hooked up the board to my bench PSU and an accurate multimeter and set the voltage for a real 3v3 and also took the board down to 2.9V in both cases it worked fine. So the issue had not been the actual voltage level as such. I can only think that there is insufficient capacitance across the power rails on the board and at low voltages the turn on/off glitches were enough to re-trigger the detector. Odd, not seen this problem before, but there you go.

In summary a nice little unit, very cheap, hours of fun can be had with them in your projects, watch out for the self re-triggering and it will work comfortably down to 3v3 if you remove the regulator and diode, then short the correct pads to make a straight through path for the supply voltage.

A few lasercut pieces…

Did we mention we have a lasercutter? We have a lasercutter. It runs off the open source LAOS controller board, and couldn’t be simpler to get your designs into.

We’ve been getting to grips with it, and our members are turning out things like leather bookmarks
IMG_20160116_194938[1]

…project boxes, tensegrity balls…
IMG_20150926_170234[1]
Tensegrity Ball

…rubber stamps
SHHM Logo stamp

…and quite a few other bits and pieces. What do you want to build? Come along to one of our scheduled sessions and say hello!

The Hunt for J5

Pi Zero J5 Connections

Pi Zero J5 Connections

J5 is alive, and is definitely not called johnny or a robot in a kids sci-fi film. J5 is the mystery connector footprint on the bottom of the Pi Zero. I have been puzzling over what it was intended for since getting my Pi Zero from Pimoroni.  Asking around amongst those who would know more than me about it (Not difficult to find) the hot favourite was a JTAG port but no one was entirely sure and there was no pinout. An extensive google around was surprisingly information free.

Time then for some reverse engineering, first stop was a USB microscope and a look see for obvious pin functions, gotta tackle the low hanging fruit first. Taking pin 1 to be the pin nearest the J5 ID we can see the footprint is for an 8 pin connector and the body or screen is not connected. 1 is the Pi system reset or run pin as it is labeled, 4 and 7 are ground connections. OK that leaves 5 pins to go. I visually traced the connections and lost them in to the maze of CPU via’s. As other than the reset they did not go to the GPIO pins I could rule out an easy hit as to what they were. The up side is if they were JTAG, it would have to be dedicated pins, not GPIO pins, and therefore projects could be debugged even with a phat in place. Hmmm what were those other 5 pins for. Normally at this point I would start on in with a multi meter or a scope and see what I could find out next. But serendipity smiled upon me, in that way it never normally does.

B+ J5 Connections

B+ J5 Connections

Putting some time into a side project (building a Graphite graphing server) I was working with a Raspberry Pi B+. Purely as I tend to mostly use Pi2’s now and was using up any older ones that were lying around. Embedding them irretrievably into other things. Fiddling with the board during one of many mental luls, I noticed the same mystery footprint on the board directly under the HDMI video connector. In fact it is so much the same it is also labelled J5. Cross referencing the ground pin outs that we know from the Pi Zero we get a match. What is more the 5 pins we had not identified are broken out to pogo pin pads bang next to the footprint. All along with nice labels. Combining the data we have then gives us the following table:-

J5 Pin Information
Pin No Pi Zero Function Pi B+ Function Comment
1 Pi System Reset ? Pull low to reset the Pi
2 ? TRST_N TAP Reset pull low to reset the TAP
3 ? TDI Test Data In
4 Gnd Gnd Signal Gnd
5 ? TDO Test Data Out
6 ? TMS Test Mode Select
7 Gnd Gnd Signal Gnd
8 ? TCK Test Clock

Some further technical info on TAP & JTAG can be found here worth a look at to illustrate some of the concepts behind JTAG. OK, all well and good, what is left to do, identify what sort of connector J5 actually is and make up a JTAG lead for it then connect it up and see if we are right.

Simply Crochet Robot

CSFZeZfXIAACp0b
[Post by SHHM member Sarah Cullen]

I enjoy mixing traditional crafts with tech. A while ago I decided to teach myself crochet, mostly using YouTube and a couple of crochet books. I found a pattern for a crochet robot toy and decided that instead of just crocheting buttons and a light, I’d use sewable electronics instead.

The crochet pattern came from Issue 16 of Simply Crochet.

I used a CR32 coin cell battery holder, battery, sewable steel thread and a large red LED for the light on the robot’s head.
To sew the light on, I pushed the legs of the LED through the top of the crocheted head and then used round nose pliers to coil each leg out to the side, flat against the crochet. On the inside of the head, I stitched from the negative terminal of the battery holder, lightly through half of the thickness of the crochet (so the thread didn’t show on the outside of the robot) to the negative leg of the LED. When sewing through the coil of the leg of the LED, I sewed knots as I went, as the steel thread has a bit of spring to it, and so wants to open up, but this can break the connections in your circuit. I did the same thing, with a separate piece of steel thread, for the positive side of the LED and battery.

The buttons on the front of the robot are a bit more involved. They needed 2 battery’s worth of power and a LilyTiny circuit board to create the flashing. The batteries are connected to the LilyTiny and then the LilyTiny is connected to the LEDs. Although the LilyTiny is designed for 4 LEDs, I connected more, in parallel, as I had more than 4 buttons that needed illuminating. The default patterns programmed into the LilyTiny were fine, so I didn’t need to reprogramme it.

The end result is here:

More LED crochet
I followed that project up with some a monkey & ninja from the Creepy But Cute crochet book and a pirate pattern from the author’s website. Rather than sewing their expressions on, I gave them sewable LED eyes. These were added behind the felt patches that are their faces. The battery holder is under each creature, which has meant I’ve needed to add a ring of chain stitch to the base, to hide the holder and stabilise each creature.

More recently, I made the robot from the Creepy But Cute book. Gee made a small circuit with cyclon style red LEDs that I used for its eyes. As these aren’t sewable LEDs and they’re tiny, it needed the crochet cutting so that they’d show through the felt face. The felt face stops the crochet from unravelling, so no problems there. At some point I may remake this but use a Adafruit Gemma / Flora to control sewable LEDs for the cyclon effect but I’ll need to find the time first!
The complete set is here:

They get taken to Make Faires with Pimoroni and recently featured in Makezine’s photos of the Berlin Faire.

All sewable electronics parts for the various projects came from Adafruit / Sparkfun / Kitronik via Pimoroni.

Inertial Logger Prototype

Prototype Inertial Logger

Prototype Inertial Logger

The prototype hardware for my inertial logging project is built. Lovely you say, looks nice, fits in a small tin, and just like everyone else, you immediately follow it with “What does it do ??”.

This project follows on from a bunch of discussions in the SHHMakers mailing list. Basically the idea is that you can record or log a track that the tin has followed using only sensing of the movement of the tin. The movement of the tin is the inertia bit. Everything has inertia and sensors that can measure that can also infer how much and by how far something has moved. Inertial guidance works on the same principles and is used for quad-copter pilot electronics etc. This is the point at which, like everyone else, you interject “I just use my phones GPS”. But what about those instances where there is no GPS signal. Try Caving, UrbEx, SCUBA Diving, or just simply finding your car in a multi-story, when you have forgotten where you parked it. Maybe you want to know where the tube system really is under the map of a city rather than the schematic map most underground systems give you. These examples are where inertial navigation and logging have a part to play.

“OK” you say “I understand now. how do you do it ?”. If you put on a blindfold and someone manoeuvres you along a track you can, if you concentrate remember it, this is the logging bit. Each time you are turned this way or that you can feel being turned, this is what a gyroscope measures, rate of turning. If you are moved quickly or slowly you can feel that too, this is what an accelerometer measures, rate of acceleration. If you are in a lift as well as feeling the acceleration, you can feel the pressure on your eardrums change as you go up or down, this is what a pressure sensor measures. You can feel if you are outside or inside by temperature changes, this is what a thermometer measures. People who are blind are more sensitive to these things than the sighted, purely as they use these clues to navigate in a world they cannot see. They also count steps. I don’t think this project will be sensitive enough to count steps but maybe it will. It certainly can measure the passage of time against acceleration/rotation and therefore infer distance.

Zoom in to see the contents of the tin

Zoom in to see the contents of the tin

“So what’s in the tin?”. You are bored with explanations now and want to know about the techy bit. If we zoom in to the tin, we can see a 10 DOF inertial navigation board (GY-87) top left. Under that on the left is a micro SD card. In the middle is a Teensy 3.1 micro-controller. At the right top there is an Adafruit Power Boost 5oo Charger. To the bottom right is the coin cell battery backup for the Teensy’s RTC (real time clock). Underneath the board is a 2.5Ah LiPo. The power boost, LiPo and teensy were bought in from our local supplier Pimoroni. The 10 DOF (degrees of freedom, or number of things it measures) board came directly from china via AliExpress. The power supplying arrangements are a compromise that niggles somewhat. Whilst the LiPo has plenty of power, all the other components actually run at 3v3. the conversion from 5v to 3v3 is done locally on the boards using linear regulators so we are wasting nearly as much power again as they draw. Unfortunately linear regulators dump the surplus energy as heat, far from ideal in a closed tin. Particularly where we want to be able to measure the temperature as part of your logging. Altogether though an adequate first pass for prototyping and testing purposes. There is a bit of a learning curve to be climbed and this is a reliable way to do it. The 10 DOF board has 3 axes of Magnetometer, Accelerometer and Gyroscope on-board as well as an air pressure sensor for us as an altimeter, giving the 10 things or DOF it can measure.

“If you were doing this again what would you do different ?” you ask. Well bearing in mind that I acquired the parts for this a bit back and they have been gathering dust the purchasing decisions would be different. I would be replacing the hand wired SD card holder and Teensy with a Pi Zero. But have to add an RTC. Also I would get rid of the linear regulator on the 10 DOF board and power it form the Zero’s 3v3. Just to move the self heating away from the air pressure sensor which relies on an internal temperature measurement for air density compensation. I would probably add a press button on the outside of the case so that way-points or events could be marked in the track log. Useful for overcoming cumulative errors. One last thing, inertial navigation chips and managers are a field of rapidly advancing technology, many of our smart phones already have them inside. The inertial sensor chips themselves are becoming ever more integrated placing it all on one chip together along with local processing to make them ever more accurate. So something to watch out for and periodically check the current state of play.

The firmware for this prototype is available from my git hub repository https://github.com/AndyKirby/Firmware/tree/master/InertialLogger please note it is a work in progress rather than a finished item.