Tuesday, 24 April 2018

ESP8266 SPI Spy

I came across a very useful post by Thomas Scherrer that describes how to read data from a Peacefair PZEM-021 energy meter by spying on the SPI bus with an Arduino. I decided to do the same thing with an ESP-12F WiFi module so that I could view the results remotely and plot graphs, etc. It took me a lot longer to get this working than I anticipated due to a few problems along the way.



The main hardware difference is the ESP8266 is a 3.3V device but the Arduino is 5V. The PZEM-021 is actually a mixture. The RN8208G metering chip is a 5V device. It is a SPI slave, the SPI master is an STM32 ARM processor that is 3.3V but with 5V tolerant inputs. That means the signals originating from the CPU can go straight into the ESP8266 but the data out from the RN8208G would need attenuating.

Copying Thomas, I removed the mains dropper components C1 and R1 and powered the PZEM-021 from an external supply. This allows it to measure voltages right down to zero instead of cutting out at 80V. I used this little 12V 1A supply recommended by Big Clive on YouTube.


I powered the ESP-12F from the same supply with a tiny 3.3V MP2307 buck converter module.


WARNING: when connected to PZEM-021 the 0V rail is at mains neutral potential. This has to be treated with the same precautions as live because if the mains lead happened to be be reversed or the neutral connection broke it would become live. Don't connect a USB programmer or a scope ground to the circuit unless you power it with a mains isolation transformer. Fortunately the ESP8266 can be programmed wirelessly from the Arduino IDE once a sketch with ArduinoOTA has been installed and this is much faster than USB.

During the hardware development I used a mains isolation unit that I made after watching this video by Paul Carlson, another of my favourite YouTubers. I built this originally to allow me to repair a switch mode PSU that was part of a friend's home cinema unit. It allows me to connect my scope to the live part of a circuit but then of course it is no longer isolated, so great care has to be taken not to touch the high voltage bits.

It is a DiBond box with 3D printed frame, handles and rubber feet containing an isolation transformer and a small variac. It also has two 100W light bulbs in parallel with a bypass switch for optional current limiting, a different model of power meter and some 4mm jack sockets allowing me to attach my Mooshimeter to log voltage and current.


The first task was to solder wires on to the PZEM-021 PCB to bring power in and data out to my circuit.


I didn't see a need for the chip select / word latch signal and I took the data from the other end of R9 compared to Thomas. The signals are as follows:
  • Red is 12V, black is ground. 
  • The word latch going to the display from chip U2 pin 7 on the left, used for synchronisation. 
  • MISO data coming from the energy chip via R9.
  • The SPI clock coming from U2 pin 12.
The two wires on the chip are tricky to solder due to the fine pitch, which is much smaller than a practical soldering iron bit. I used the following technique:
  • Strip some wire-wrap wire and trim the end to be the length of the flat part of the pin.
  • Tin it. It doesn't hold much solder due to being such a small radius.
  • Add plenty of liquid flux around the pin.
  • Line the wire up along the top of the pin with an Andonstar ADSM201 microscope camera.
  • Put a very small amount of solder on a small chisel bit.
  • Press the iron on top of the wire and leave it long enough to conduct the heat through the wire to boil the flux and melt the solder on the pad below.
The amount of solder on the iron bit is crucial. If you use too much it will bridge the pins. To remove a bridge add plenty of flux and wipe the pin with a large flat bit. Surface tension will cause some solder to wick onto the bit, wipe it off and repeat until the bridge breaks.

When I looked at the levels of the signals I got a bit of a surprise. I was expecting MISO on channel 2 to go to 5V but the other two come from the ARM and should be 3.3V signals.


They seem to have a 20kHz ripple that takes them up to 4V. I looked back at Thomas' oscilloscope pictures and see the same ripple there. It doesn't make any difference for him because he is using a 5V chip but I didn't want to stuff 4V into my ESP8266!

On further investigation I found that the whole 3.3V rail had this ripple on it. It comes from a Holtek HT7133-1 3.3V LDO regulator. The datasheet for that suggests 10uF decoupling capacitors on the input and output. The circuit has what looks like a 10uF tant on its input but the output decoupler is a tiny MLCC that looks too small to be 10uF. I added a 10uF electrolytic in parallel and that killed the oscillation. It is the blue radial cap across C1 in the photo above.


That just left the issue of the 5V signal to contend with. R9 turns out to be 1K so simply adding a 2K2 to ground drops the signal low enough.


It also changes the first eight bits from FF to 00. This is actually when the command byte is being sent to the meter chip on MOSI and MISO is tri-state, so it doesn't matter.

Hardware done, on to the firmware. Before starting the project I had seen that the ESP8266 has a spare SPI port available and I assumed it would be straightforward to just read a stream of 13 bytes, wrong! It wasn't because the SPI port it a relatively complex device with dozens of registers that doesn't just send and receive bytes. It actually works at the command level, expecting to send or receive a command and address and then send or receive status or data bytes.

When in host mode it is possible to configure it to send and receive arbitrary bytes, indeed that is what the Arduino SPI class does and it works on the ESP8266 more or less the same as it does on an AVR. In slave mode though it has to receive a command and address according to the technical manual and the command defines what happens next. The relevant sections are:
4.3.2. Communication Format Supported by Slave SPISlave ESP8266SPI communication format is almost the same as that of the master mode, i.e. command+address+read/write data, but the slave read/write operation has itshardware command and undeletable address, which is,
  • Command: a must; length: 3 ~ 16 bits; master output and slave input (MOSI).
  • Address: a must; length: 1 ~ 32 bits; master output and slave input (MOSI).
  • Read/write data: optional; length: 0 ~ 512 bits (64 Bytes); master output and slave input (MOSI) or master input and slave output (MISO).
4.3.3.Command Definition Supported by Slave SPIThe length of slave receiving command should at least be 3 bits. For low 3 bits, there are hardware reading and writing operation, which is,
  • 010 (slave receiving) : Write the data sent by master into the register of slave data caching via MOSI, i.e. SPI_FLASH_C0 to SPI_FLASH_C15.
  • 011 (slave sending):Send the data in the register of slave data caching (from SPI_FLASH_C0 to SPI_FLASH_C15) to master via MOSI.
  • 110 (slave receiving and sending): Send slave data caching to MISO and write the master data in MOSI into data caching SPI_FLASH_C0 to SPI_FLASH_C15.
On the face of it this looks like it will not work in this application, which is unbelievable that a SPI port can't read arbitrary data as a slave and is hard coded for emulating flash chips and the like. 

I couldn't find any proper register level documentation for the ESP8266 other than various .h files on the web. The Arduino library uses shortened names which are very cryptic but some headers use longer names. While searching for these I came across the technical manual for the ESP32 and realised it has SPI ports that are nearly the same. It also has register level documentation in it's technical manual so I was able to get a slightly better understanding. After a lot of experimentation I found a solution.

The first n bits get interpreted as a command, where n is 3 or more and defaults to 8. The start of the 13 byte sequence that I want to receive is always zero now that I added the pull down resistor. So it always receives command zero. The bottom three bits normally control what happens next and zero defaults to read status. However, it is possible to override this with user definable commands by setting  SPI_SLV_CMD_DEFINE in SPI_SLAVE_REG. That makes the SPI_SLAVE3_REG define what the command values are for four different actions. By setting SPI_SLV_WRBUF_CMD_VALUE to zero and the other three values to nonzero I was able to make it interpret the command as write buffer, so the rest of the data gets written into the buffer.

Well that was the theory but I was missing two bytes at the beginning. This was because it was being interpreted as an address. The default address length is 24 bits. I changed it to 8 by setting SPI_USER1_REG and now I get the 12 bytes of data following the zero byte. Now this doesn't make sense because if the first 8 bits are being interpreted as an address where is the command coming from? The command length is set by  SPI_USER2_REG and it defaults to 8. I was expecting to have to set it to say four and set the address length to four bits so that they could share the first byte but any value between 2 and 8 seems to work and makes no difference. I don't know if it is a bug in the chip or I don't understand something but I get to read my 12 bytes of data

So in conclusion you can't read a completely arbitrary SPI data stream but you can if the first few bits are a known value.

Here is my code that sets up the HSPI:

When the data is received I get an interrupt where I copy it from the HSPI's dword buffer into a byte buffer in RAM.

I set up the sync pin to generate an interrupt on the falling edge. This resets the HSPI and unmarshals  the data:

I found that when I switched the load on and off I sometimes got a data packet shifted right one bit. That points to a spike on the SPI clock line into the ESP8266 but I could not find one with a 100MHz scope triggered on the mains switching edge. I added a snubber close to the switch but that didn't cure it, so I bodged it in the firmware and moved on. If a voltage sample is not more than half the previous one I ignore it once.

Another oddity is that when there is no load and the voltage is relatively high the power reading would go slightly negative. I detect that and set it to zero.

The foreground loop looks for the new_readings flag to be set and does the conversion to real units:

The conversion constants are close to what Thomas used but slightly different, so the ARM must have some per unit factory calibration constants in it.

So it took me longer than I anticipated to follow in Thomas' footsteps because of the complexity and lack of proper documentation for the ESP8266 HSPI peripheral but I got there in the end. I hope others find this as useful as I found Thomas' work.

By now you are probably wondering what this is all for. Well, while investigating a strange line regulation problem in a power supply I got annoyed that the mains voltage in our house is constantly varying, making it hard to make measurements of input versus output. This is what it looks like logged every 10 seconds over a couple of days using my Mooshimeter.


As well as the small modern variac shown above I have a old WM5 model that I got on eBay. The only data I could find on it was from 1955. It still works fine so I decided to automate it with a small stepper motor to maintain a specified voltage. I.e. make a WiFi control IOT variac.


Another DiBond and printed part creation but the front panel had to be acrylic to let the WiFi out. Fortunately the front of my bench faces towards my router. The ESP8266 controls the motor via a Pololu stepper driver.


The control interface is a simple web form that also shows the current readings using AJAX as described here.


The control algorithm is very simple. The motor is stepped at the specified speed by the error in voltage multiplied by the gain. The readings update every 200ms but they lag a lot. That causes overshoot if the gain is set high. It would probably benefit from a full PID controller but it works well enough for now. The deadband setting allows it to stay in a range without constantly moving because I don't want to wear out the variac. Servo control of a variac is a standard way of regulating mains but I have no idea how long the brushes last. Manual mode disables the motor.

The readings can be read and the settings changed from the command line or from a Python script using cURL. Here is an example that sweeps the voltage from 10 to 250 in 10 Volt steps and reads the current and power.

Here is a graph showing current, power and resistance versus voltage of a 60W light bulb


I plan to use this to plot a power supply line regulation graph. For that I will need a way of reading the output voltage in my script. I have two scopes that have network APIs as well as my Mooshimeter that has a BLE interface. I just need to work out which is the easiest to access in Python.

Here is the full ESP8266 sketch.

Sunday, 15 April 2018

ESP8266 contention during programming

To put the ESP8266 into serial programming mode it needs to be reset with GPIO 2 held high, GPIO 15 low and GPIO 0 low. On the other hand to start it executing flash GPIO 0 needs to be high during reset. I have seen lots of circuits on the web, for example the NodeMCU board and Adafruit's  Huzzah board that pull GPIO 0 to ground with a switch and / or with DTR from a USB to serial adapter.  Reset can be driven from RTS to automate programming with the Arduino IDE.

A lesser known fact is that when the ESP8266 goes into programming mode it outputs a 26 MHz clock on GPIO 0 with considerable drive strength and fast edges. Shorting this to ground or DTR is not good at all as it causes massive contention and generates a lot of noise. This can cause programming to fail unless there is some hefty decoupling on the supply rail. The simple solution is to put a resistor between GPIO 0 and whatever is pulling it low. Here is what the signals look like with 10K between GPIO 0 and DTR from an FTD1232.


The oscillation doesn't show up at full amplitude with a slow time base but I can assure you it is full swing with plenty of overshoot due to not being terminated. You can see a bit of it coupled onto the TX line and this is when it is through 10K. Imagine how noisy things get when it is fighting with the FTD1232 DTR line and winning.

Another lesser know fact is that when the ESP8266 is in reset its GPIO lines get pulled up internally. You can see with 10K pulling it down the GPIO line only goes down to about 0.7V during reset.

Before reset my application is driving GPIO 0 low. RTS goes low a short time before DTR, so it briefly becomes an input and gets pulled to 3.3V by DTR before it pulls it low again. This explains the spike on the left.

I haven't seen any circuits published that avoid this contention.

Tuesday, 3 April 2018

Printed ESP-12 module breakout adapter

I plan to make a few projects based around ESP-12F WiFi modules. These are postage stamp sized modules containing an ESP8266 chip plus 4MB of flash. The ESP8266 chip is a 32 bit MCU with an integrated WiFi transceiver and TCP/IP stack. They come programmed as a WiFi modem but they can be reprogrammed with the Arduino IDE to do other things in addition to the WiFi. Great for IOT applications because they are so small and cheap (less than £2) but reasonably powerful. A lot more powerful than an Arduino, for example, but with less I/O.


The solder pads are on a 2mm pitch, so they are often used with a breakout board to adapt them to 0.1" pitch for breadboard or perfboard, etc.  That adds cost and increases the size somewhat because the through hole pins need to be outside the perimeter of the module. I solved the problem another way, by using a 3D printed wire guide that routes wires from the 0.2mm pitch holes to the nearest 0.1" hole, minimising the space used and costing virtually nothing.


The holes in the module are quite small so I use stripped wire wrap wire. I push it through the module, down through the guide, which routes it to the correct hole in the perfboard. I fold the top over, solder it to the module and trim it. I do the four corners first and pull them tight and solder underneath to secure the module.

Here is a module mounted on perboard.


It doesn't use any extra board space outside the 0.1" holes it uses. I.e. the adjacent holes are all usable.

I didn't break out the end connections because they are not very useful. They are all GPIO lines used internally for the flash. I read it is possible to free up two by removing the can and re-configuring the flash chip to use a two bit interface instead of four bits, but that is too much hassle for me.

Here is the OpenSCAD that produced the adapter: -

The only notable thing is the squeezed wall definition, see my previous post.





Avoiding voids

The thinnest practical wall you can print, (with Skeinforge at least), is two extrusion widths wide. Any bigger leaves a gap, until you get to three extrusions wide, and then you get infill in between them.

If the wall is exactly two extrusions wide then they only touch tangentially and have a weak bond because the edges of the filament are rounded.


I discovered that if you make a wall even thinner then Skeinforge still lays down two paths equal to the extrusion width but places them closer together. This is because it always offsets inwards by half the extrusion width, even if the resulting paths overlap. I found I can make use of this to squash the plastic together, making a stronger wall with less voids.

An optimum amount of squeeze is to place the nozzle aperture just free of the flat part of the first path when extruding the second. The width to make this happen is $extrusion\_width - layer\_height / 2 + nozzle\_aperture / 2 + extrusion\_width / 2$.


Of course, despite what Skeinforge thinks, the plastic volume can't overlap, so regardless of where the nozzle is the minimum width the wall can be is $2 * extrusion\_width - layer\_height * (1 - π/4)$ due to the volume of plastic extruded, i.e. if it manages to completely fill the voids. This is shown below: -


The grey area is where the edge would have been with the wall two extrusion widths wide. There isn't much difference, and depending on the viscosity of the plastic, the real width should be somewhere in between. But the big difference is the walls are strongly fused together. The top void should be completely filled because it is right under the nozzle, leading to a smoother top surface. And the bottom void has more chance of being filled due to the back pressure caused by the filament having to flow more to the right.

To put some numbers to the diagrams, these have been drawn to scale for 0.25mm layer height and 0.5mm extrusion width, 0.4mm nozzle. The requested wall width is 0.825mm but the volume of plastic means it must be at least 0.946mm, only 0.054mm less than the original 1mm wall.

I made a test script that makes a box with two 1mm walls and two 0.825mm walls.


Here is a corner of the box under a microscope. The wall on the left is seamlessly fused and the wall on the right clearly has a void.


The wall comes out a bit thinner than the theory predicts, I am not sure why, maybe the increased pressure causes the plastic to feed a bit slower.

I used this technique to make the Mendel90 fan guards a lot stronger part way through production because I had some fall apart one day when my filament was a bit undersized.

It would be nice if the slicer could do this automatically, so you can keep a 1mm wall in the design, but it would make it by extruding one side of the wall as normal but the other side it would offset the nozzle to fill the voids and then extrude a little more plastic to make it still 1mm thick.

In fact it should really do this anytime it is extruding against another extrusion path. E.g. when doing multiple outlines and when doing infill. I.e. the only time the tool path of the nozzle should be down the centre of the extrusion path is when there is nothing either side, or it is enclosed on both sides. And in each of these three cases a slightly different flow rate would be needed to get the new exposed edge in the correct place.

Saturday, 2 December 2017

Fretting corrosion

Long ago I noticed friction fit connectors are not reliable in 3D printers: hydraraptor.blogspot.co.uk/2011/06/reliable-connections. For example, 0.1" Molex connectors that are rated for 3A burn out when only carrying 1A motor currents. Even signal connectors on HydraRaptor lose contact and need re-seating occasionally. I figured it must be due to vibration and / or thermal expansion and contraction.

It is one of the reasons I choose the Melzi electronics for Mendel90, i.e. because it has screw terminals instead of Molex connectors that are common on other boards like RAMPS. While looking at some connectors for another project I came across the term "fretting corrosion", which is exactly the problem that causes failed connections when you have vibration or thermal movement. There is a marketing video explaining it here:


Basically contact mating points need to be gas tight to prevent corrosion and any relative movement breaks the gas tight seal. You can now get connectors that have sprung female parts to absorb any motion and prevent this mode of failure. Worth considering if you are designing a 3D printer.

Monday, 7 August 2017

Will it burn

I always intended to put lots of different tool heads on HydraRaptor but after being a milling machine for a while it got stuck as a 3D printer until I started making Mendel90 kits and then it sat gathering dust.

Back in 2009 I bought a 1W 808nm infra red laser diode to experiment with but I never got around to trying it out until recently.


I bought it on eBay for £292, which seems very expensive now, but the seller claimed it has a spot size of only 13um x 120um. That would give a power density of 640 W/mm2, assuming a rectangular spot. In comparison a 40W CO2 laser with a round spot of say 0.25mm would give a power density of 815 W/mm2, so I expected to be able to cut through wood and plastic a few mm thick with it.

Inconveniently, the anode of the diode is connected to the case. 

It came with a driver board that takes 11-18V and a TTL enable signal and produces a constant current drive.


It is all a bit last century with through hole components and a relay. I looked at the switching waveform and found that the relay added an 8.2ms delay and there was a 2.95ms rise time.

The blue trace is the enable signal and the yellow trace the output voltage.

The two TO220 devices had their markings ground off but it was trivial to trace the circuit and work out what they are: a 7810 10V regulator and an LM317 variable regulator wired as a 1.25A constant current source.

Laser didoes are very easily destroyed by overshoot transients of even a few micro seconds duration, so most of the circuit seems to be to avoid those. R2 and C3 seem to be to stop inductive spikes from the relay getting onto the 10V rail. R4 and C6 are probably to filter any relay contact bounce but they also make the rise and fall times very slow. D1 is a mystery because it can never be forward biased, so might as well not be there.

I hacked the PCB and reconfigured the circuit to replace the relay with a MOSFET, speed up the edge rate and added a big red LED to warn me when it was on. I have a pair of Thorlabs LG9 safety glasses to protect my eyes.
Here is the new switching waveform: -


This time the yellow trace is the enable signal. The blue trace is the current waveform measured with the hall effect current sensor mentioned in my last post. The small delay turning on is while the output capacitor charges enough for the diode to start conducting. The rise and fall times are now less than 1ms which seems more reasonable.

The forward voltage of the diode is about 2.2V at 1.25A giving a power dissipation of 2.75W and an efficiency of 36% assuming the output is 1W. I mounted it on an old PC CPU cooler which was complete overkill.


I made a rough estimate of the thermal resistance of the heatsink with the fan on by attaching a 50W resistor that has the same case style as the laser. The heatsink itself is about 0.23°C/W and the case of the resistor a little more, 0.48°C/W in total. So the temperature of the diode casing will rise by less than 1°C.

These dashes were made by waving a random piece of black plastic (most likely ABS) in front of it while the 100 Hz test waveform above was driving it.


With continuous power it makes deep scars.


Holding it steady I was able to slowly drill all the way through the 1.75mm thickness but it left a ring on the surface. The exit hole was clean though. By all accounts ABS doesn't laser very well.


With these rough manual tests I established the focus length was about 35mm, which I needed to know to be able to design a mount for HydraRaptor, so that I could position it relative to the Z probe to give me auto focus.

I also established it has no effect at all on white paper because that reflects red light and this is near IR, so it will behave mostly the same as red light. It also had no effect on some Kapton (polyimide) film because that is transparent to red light. With near IR you can only cut materials that absorb the red end of the spectrum. If they are transparent or reflective to red they are unaffected. In contrast, CO2 laser light is far infra red with a much longer wavelength and that is absorbed by most things including optically transparent materials like glass and clear acrylic and white materials like paper.

I designed HydraRaptor in 2D and that was all it needed at the time because it was made from flat sheets of MDF and had no 3D printed parts. In order to be able to add new parts to it I decided to re-model it in 3D in OpenSCAD.


I mounted the heatsink on a printed bracket that aligns the laser with the centre of the table and also supports a radial blower and duct for air assist. That is a jet of air that blows the smoke away from the cut and the lens.


I made a steel plate bed to protect the XY table and allow me to hold down the work piece with magnets. An L shaped bracket made from DiBond allows repeatable alignment with the back left corner of the bed. I used that corner to allow oversized sheets to hang over the front right where there is maximum clearance.


The hole in the corner of the L is needed because an internal corner would otherwise have a radius equal to the tool radius that cut it.

The first task was to find the exact focal point and I did that by burning a line of spots from different heights into the paint surface of an off-cut of DiBond and looked for the smallest one. I have hundreds of these off-cuts from making Mendel90 kits and because the paint is a thin layer on top of aluminum it seems like a good way to measure the spot size.


After I had established the focal point I then needed to establish how big the spot is. I have a microscope and a graticule slide but it was too hard to align it by hand. The alternative method I came up with was to make a line of spots 0.1mm apart so that I could compare the spot size with their pitch and use the ratio to work out the size.


As you can see the spot isn't quite aligned with the outer case of the laser. The size works out at 0.16mm by 0.07mm. This is a lot bigger than the 0.12mm x 0.013mm advertised and only gives a power density of 90 W/mm2. The bright area in the middle where it looks to have cut to full depth is 0.036mm wide.

Laser spots don't have well defined sharp edges. An ideal laser has a Gaussian intensity distribution which falls off  away from the centre asymptotically to zero. The beam diameter is sometimes defined as where the intensity drops to half the maximum and other times where the intensity drops to 1/e2 ≈ 13.5%. So my power density calculations are somewhat naive.

The beam starts off long and thin because it comes out of the edge of the chip die. The cleaved edges form the two parallel mirrors. Whereas I think of lasers having a parallel beam, the beam from a diode laser diverges at tens of degrees. And it diverges faster in the axis at right angles to the die than it does in the axis parallel to the die. So although it starts out wide and short it ends up tall and thin.


Not only that, but the beam also has astigmatism. That is: the point that the beam diverges horizontally from is further back then the point it diverges vertically from. So focusing it to a round spot requires tricky anamorphic optics. Mine just has a plain lens that is rotated in a screw thread to adjust the focus, so it can't correct the elliptical beam shape.

My next experiment was to work out what travel speed I can engrave at. This will be different horizontally and vertically because the energy density applied to the material will depend on the area swept out as well as the power and time. This will make motion planning interesting as the speed will need to vary depending on the slope of a line and so will the kerf compensation. Alternatively the laser could be mounted on a rotary axis to keep it pointing along the axis of travel for maximum detail. That would need a very accurately aligned axis though to avoid the spot wandering as it rotates. A round spot would be a lot easier to deal with!

I engraved a 5x5mm crosshatch with each line at a different speed. Speed reduces from left to right and bottom to top. The speeds are 5mm/s, 5/2mm/s, 5/3mm/s. ... 5/13mm/s.


By looking at the cross over points one can tell if the maximum engraving depth has been reached or not. So it needs go as slow as about 0.5mm/s horizontally to not show the vertical lines.

Note that it never goes deep enough to reach the aluminium skin. It looks bright but when I check for conductivity with a mulitmeter I have to scratch away the white layer to get contact. I think there must be white primer underneath the black paint and that reflects the laser, stopping further ablation.

Here is a 5x5mm rectangle engraved with a raster of lines overlapping 50%.


I don't know what gives it an apparent texture.

While doing these tests it soon became apparent that I needed fume extraction because removing even a tiny amount of paint smelt unpleasant. I thought I might get away without it for shallow engraving as there are many open frame laser engraving machines on the market. My first attempt was to add an 80cfm fan close to the edge of the bed that sucks air and blows it down a 1" pipe that I hang out of the window.


It produces quite a powerful suction and this reduced the smell but not enough. I switched to tests on balsa wood because I thought it would be less toxic. I have a lot of 2mm sheets left over from the early days of RepRap when it was used as a bed material for PLA before better options were discovered.

It still smelt very smokey, so I decided to make an enclosure. I had always intended to do this. Way back when I bought the laser, I also bought some brushed aluminum DiBond sheets big enough to make a cover but ended up using most of them for other things. I did have two left to make the front and top and some black off-cuts from Mendel90 production long enough to make the sides.

The width of HydraRaptor is 511mm and that is bigger than the X axis of my CNC router, which is 450mm. By hanging it over the side of the bed so it just cleared the gantry I was able to route one side at a time. I made some tooling holes in the corners of the door cutout that allowed me to turn it around 180° but maintain accurate registration. If it had been 1mm wider it would not have fit the router!


The door is an acrylic one I recycled from my Mendel case. I might replace it with DiBond to remove the need to wear safety glasses. It is sealed around the edges with rubber sealing strip tape. The enclosure isn't airtight because there are holes for wires to the z-axis driver, etc, but it is under significant negative pressure when the fan is running, so they are not a problem. I cut an 80mm hole opposite the extractor fan to get a good stream of air across the bed.

The enclosure removes any smell in the room while it is engraving wood but the smokey smell remains inside the machine even after a couple of weeks.

I did a larger grid test (50mm x 50mm) to see what speed I could cut through 2mm thick balsa wood but found it didn't matter how slow I went it did not go right through but it did give a wider charred area. The speed is 5 / n mm/s, where n is the line's index.


Here is the underside: -


Just a few pin prick holes and some surrounding char where the slowest lines cross.

I did another test where instead of reducing the speed by the line's index I kept the speed constant at 3mm/s (5 mm/s for y) but repeated the line n times. I found this gave far less char and actually cut all the way through.


So horizontally it took 4 passes at 3mm/s to cut through and vertically 6 passes at 5mm/s. Working out the power energy density as passes * power / speed these are more or less the same, which is odd considering the big difference in beam width.

The next test I tried was to cut out a square using four passes at 3mm/s in both directions.


I was disappointed to find it didn't cut all the way through so I re-ran the grid test above and the laser power dropped to zero and it never lased again. The left edge of the wood was not very straight where I cut it with a knife and it left a small gap that allowed the laser beam to hit the steel plate below. What seems to have happened is the reflection was enough to destroy the diode's mirrors. It still takes the same power but gives no output. This is known as Catastrophical Optical Damage.

Where the beam had previously gone all the way though to the steel it had created black stains so that stopped any reflection. So it looks like I should have painted my steel plate black. I was also lucky that the DiBond didn't engrave down to the aluminium surface as I expect that would be an even better mirror.


So a disastrous end to the experiment!

I have ordered a 2.3W blue laser from China so I will continue experimenting with that when it arrives. I also have a 12W IR fiber laser to play with but that requires a serious power supply and cooling system, so I will get more experience with lower power lasers before I attempt to power that up.


Sunday, 30 July 2017

Adding weight

Sometimes it is desirable to make 3D printed items with heavy bases, so that they stand up or are not easily moved. An example is this base I made to hold two tiny PCBs.


They are Hall effect isolated current to voltage converters that I plan to use to measure stepper motor current waveforms in conjunction with an oscilloscope. They don't have any mounting holes, so I clamped them by the corners and screwed them onto a printed base.

I wanted the base to be heavy to stop them being dragged around by the scope leads. A while ago I saw a Youtube video by Warner Berry where he used lead shot to make printed parts with heavy bases. He prints parts with no bottom layers, so the honeycomb infill is exposed. He fills that with lead shot and then pours in epoxy resin. When that has cured he sands the base flat and sticks on a rubber sheet to make them non-slip.

I found lead shot on eBay sold for filling diving belts but I also found steel shot sold for filling teddy bears and that was much cheaper and available in smaller diameters. Steel has about 2/3 the density of lead, so it is a cheaper way of adding weight if you can accommodate 50% more volume. It also has the advantage of being non-toxic of course.

I got the smallest size, which is 1mm balls, on the basis that they will fill a space slightly better than larger sizes. The downside I found was that when pouring them they tend to bounce and fly all over the place. They don't vacuum up because they have a very high weight to air resistance ratio being spherical. I had to use a magnet to capture them. In hindsight I think 2mm balls would be easier to handle.

Instead of printing infill without bottom layers I simply made the whole base hollow. It doesn't need any infill for strength because it is going to be filled with resin. It is quite a large area to bridge without infill but it gets covered, so it doesn't matter how ugly it prints.


The screws go into brass heat fit inserts that I press in with a soldering iron. In hindsight I should have capped the holes to prevent resin getting in them.

After I filled it with the steel shot I poured in two part polyurethane resin that I had left over from an experiment nearly 10 years ago:hydraraptor.blogspot.co.uk/2008/03/hdpe-pu. I was amazed it still worked. It is probably better for this application than epoxy resin because it is less viscous, so should fill the gaps more easily.

Here it is after I sanded it down: -


Not the best casting as I under filled one corner and there are some bubbles, but it doesn't matter at all in this application.

I covered it with a sheet of adhesive backed neoprene rubber. It is probably not the best choice of rubber because it seems to be quite slippery.

The end result weighs 80g which feels quite heavy for something this size and is just about heavy enough to not be dragged around by scope leads. If I was making it again I would make it a bit deeper and try to find a better non-slip rubber.

Another way to encapsulate the shot would be to pause the print and pour them in before before the top layers are printed. They would then rattle of course, which might be annoying. On a moving bed machine like Mendel90 there would be a limit to how much weight you could add without lowering the acceleration. Also adding weight might cause the bed to drop in level slightly giving an uneven layer. Neither would be problems on HydraRaptor because its moving table weighs 9kg and has a load capacity of 125kg!

Friday, 16 June 2017

Mooshimeter Mod

Last year I bought a Mooshimeter wireless 2-channel multimeter. It is a multimeter front end that links to your mobile phone with Bluetooth and displays the results in an app.


It is handy because you can read it remotely, it can measure voltage and current simultaneously and display power, it can log to an SD card and graph the results. It can also speak the results.

Despite all these good features my "go to" multimeter is still my EEVBlog branded Brymen BM235. So my Mooshimeter sits in a drawer for most of its life. When I get it out it usually wants to do a firmware update, which needs fresh batteries. Because it has no off switch the best you can do is put it into shipping mode. It still flashes its LED occasionally, so the batteries run down over a period of several months and are then not up to doing a firmware update.

Devices with no proper off switch are a pain if you only use them rarely because the batteries are always flat when you come to use them. This is particularly a problem because modern Duracell batteries seem to leak and corrode as soon as they are flat. This didn't used to be the case. I found some very old ones that I had abandoned in outdoor devices that I expected to be corroded to hell but in fact they were not corroded at all, despite being well past their use by date. In contrast I have had many corrode recently that were flat, but still well within their use by date. I have stopped buying Duracell and now use Costco's own Kirkland branded ones. It is too early to say if they corrode or not.

So I normally remove the batteries from devices I use rarely but with the Mooshimeter this involves removing the casing that is held together by two screws. I decided to add a switch to it but it has a cat III safety rating and cutting a hole in the case would void that.

I had two ideas to get around this: the first was to put a normally closed reed switch in series with the batteries and 3D print a cradle with a magnet in it to turn it off. My second idea was to use a mercury tilt switch to turn it off when placed upside down. I ordered both but as the mercury switches arrived first I implemented that and it works well.


I decided the easiest point to break the battery circuit was the link between the two cells. For some odd reason that is a copper fill rather than just a track. It is on the top side of the PCB so I had to desolder one of the contacts to get at it.  Fortunately the battery contacts have thermal relief connections so I just cut two of those to isolate the pad.


I then made an insulating washer out of Kapton film. I used that because it is very thin and can handle soldering temperatures. I stamped it out with a hole punch but I found it very difficult to get the hole concentric. This is my third attempt that was just good enough:


And here it is in place:


I reinserted the clip over the top and resoldered it. I then soldered the tilt switch between the two now isolated battery terminals.


When upright the contacts are bridged by the mercury, which is very low resistance. When I turn it upside down the mercury flows to the top of the bulb and isolates the batteries.

So all I have to do is remember to place it upside down in its case. If you want to attach the meter to something moving then the reed switch idea is the one to go for. I think it can probably be mounted in the same place if you use a neodymium magnet. You can get it nearer the back of the case by mounting it on the other side of the PCB but I don't know if that affects clearance distances for class III.

Sunday, 3 April 2016

Beware fake wire!

I bought some test leads with banana plugs and alligator clips for £0.99 on Ebay from Hong Kong. They were described as "Alligator Probe Test Leads Clip Pin to Banana Plug Cable for Digital Multimeter GF". I don't know what the GF means.


Very cheap and what could possibly be wrong with them? Well actually, almost everything!

The first time I used them to connect a regulator to a bench PSU they got hot and dropped several volts. Without needing to do any sums with wire gauge and current I felt the resistance must be too high, so I measured it to be about 1.4Ω for the round trip. Way too high as multimeter leads are generally about 0.2Ω.

I unscrewed a plug and found this: -


The screw bites down on the soft insulation and that presses the folded back strands against the barrel. Not the best way to make a connection as you want the screw biting down directly on the strands, or better still a ferrule.

At the clip end it was more of the same: -


The strands are trapped between metal and plastic again instead of being soldered through the hole. The crimp is there just for mechanical strain relief, not the electrical connection.

I removed all the connectors (the clips pull off really easily due to not being soldered) and measured the resistance of the wire on its own. Still 1.4Ω, too much I felt for that gauge of copper wire 2m long. The simple explanation is that it isn't copper.


The fact it sticks really well to magnets leads me to believe it is copper plated steel. That might be OK for measuring voltage but no good for measuring or carrying current. I can't see any reason for using it other than it must be cheaper.

I replaced it with 32/0.2mm copper wire half the length and got a total resistance of 20mΩ. Much more suitable for hooking up PSU test circuits but a bit less flexible than ideal for multimeter leads.

So basically I got usable connectors for £0.99, which is still probably cheaper than I could buy them for in the UK. The wire and the construction were junk.