Adding Bluetooth to Vintage Headphones – Part 2


First part of the article.

I received the parts and the PCBs:


First thing I noticed is that the hole for the screw that will press the button is missing. The cutout in the soldermask is there but not the hole. Damn you cheap chinese PCB manufacturers!

All right, now I remember: I did the PCB cutout in the soldermask and decided to draw it on the mechanical layer later*.


Well, it’s nothing a Dremel and a needle file can’t fix. And I need to countersink the holes for the screw heads anyway.

Yet another detail: I measured the diameter of the hole of the option for a bigger axis screw (M3) to be 4mm. I might have decided to postpone the before-order-review of my PCB for later™ too…

Anyway, I’m curious to see if everything fits as nicely as in my 3D model. Let’s start with the potentiometer.

The PCB holding the potentiometer and the screw for the pushbutton (hole on the left):


The other side, which will be attached to the  headphone ear cup and holds the axis screw:


Not bad**. (The nut on the axis screw which sets the spacing of the two PCBs is missing on the photo.)

The whole fist surprisingly well on the side of the ear cup:


You can see the pushbutton and its actuator screw.

On the other side, the potentiometer sticks out enough to be pushed or turned:


Now the main PCB with the BM62 Bluetooth module and the PIC microcontroller, and the small PCB for the USB socket and the RGB LED:


They fit nicely too:


After this, I could build the bracket for the USB and LED PCB. I made it of 2mm thick acrylic sheets which I glued together. The light pipe for the RGB LED is the same material:


The glue is two components epoxy. Note the BM62 Bluetooth antenna sticking out from under the main PCB.

The result on the other side is quite ok:


I filed and sanded the piece of acrylic so it’s flush with the ear cup plastic and gives a diffused light.

One thing I didn’t think through enough is the mounting of all the mechanical parts together.  Because the PCB holding the potentiometer blocks the access to the screws attaching the first PCB to the side of the ear cup, it has to be assembled last. But then the axis screw touches the USB PCB making it impossible to put a nut on it. And you can’t pre-assemble it because you need access the screws holding the other half to the ear cup. Neither can the two PCBs have an angle, because the screw pushing the button has a hole limiting the PCBs angle against each other. Vicious circle. I ended up filing a corner of the PCB holding the USB connector to have space to put the locking nut for the axis screw and inserting the actuator screw last..

Apparently, having your ways with a professional 3D software doesn’t make you instantly a mechanical engineer.

At the end it was tight, but everything could fit without too much cursing. The LiPo battery sits flat against the main board.


Now let’s take care of the guts!

The BM62 Bluetooth module

Microchip advertizes it as “a fully-certified Bluetooth module for designers who want to add Bluetooth wireless audio and voice applications to their products.” and “Easy to configure with User Interface (UI) tool, a Windows® configuration utility or directly by MCU”

A serial interface can be used to command the module (enter pairing mode, wake up, volume etc). For the configuration, there is an onboard EEPROM, also accessible through the serial interface. Microchip provides tools to help with the development (for free and without login/registration -a nice touch):

  • A program to edit the configuration.
  • An utility to download the configurations to the module’s EEPROM.
  • A program to configure the BM62 DSP.
  • A tool to connect to the BM62 via the serial interface and to change and query all the settings and the module status (the Command Set Tool).
  • Some documentation (for the serial protocol).

The first step would be to use the Command Set Tool to play with the module and to get familiar with the different modes.

In reality, I spent some hours trying to connect the tool to the BM62 without success. After cursing the entire earth and the human lineage, I saw on a forum post that the serial interface of the BM62 has to be enabled in the EEPROM configuration first.

This is how looks the user configuration file to generate:

eeprom conf.png

It’s only a part of the EEPROM binary and has to be wrapped with the help of another Microchip tool, “MPET”.

I am not sure there is a comprehensive documentation for every bitfield. Luckily, Microchip’s program “UITool” can generate the text file. Unfortunately, it looks like it was coded by someone with no idea of software design, or anything about Windows 7 and above.

A polite welcome message greats you at launch:


Then, things get a bit messier. Luckily, there is a help function with a nice yellow notepady background:


Ok, never mind.

Note also that the help windows sizes are kind of random but fixed, so depending of your screen resolution and DPI setting, it can happen that the scroll bar isn’t long enough:


The best is, once you generated the text file with your configuration, you still have to go through the MPET thing (a dozen or so clicks, three files to open), put the BM62 in ROM boot mode by holding a pin low while powering it up (too bad if you already soldered a battery – you’ll have to disconnect it), upload the configuration with the third tool and, finally, test your new modifications. Don’t expect to try small changes, unless you have plenty of time.

Anyway, I managed to enable the serial interface of the module. From there, I could connect with the Command Set Tool:


It looks like it was done by the same unpaid intern, but it gets the job done. A nice touch is the log section: it shows and translates the received and sent data. You can even copy the messages into the Windows clipboard. Woohoo!

The tool gave me a good start with the BM62 and helped me to test and tweak the configuration. It was convenient to debug my hardware and my code, especially in case of doubt.

The PIC code

The PIC18LF4550 will  manage the BM62 module, the pushbutton and the potentiometer.

The program has to:

  • Wake up and power off the BM62 module
  • Put the module into Bluetooth pairing mode
  • Read the potentiometer value and send it to the BM62
  • Put the PIC in sleep mode as often as possible to save the power

For this we have:

  • The pushbutton
  • The potentiometer
  • The red LED of the RGB LED
  • The serial interface

The pushbutton will trigger an interrupt (INT0 -pin RB0). The ADC acquisition will be triggered by the Timer1 and Capture Compare module 2. I tried to use the High/Low-Voltage Detect module to see if the USB cable was plugged and the battery charging (to for example, configure the PIC to act as a USB-serial converter, for debug purposes) but because the PIC gets its power from the BM62 “SYS_PWR” pin, the voltage was too dependent of the current the PIC was pulling from it, making the detection unreliable.

Speaking of the SYS_PWR pin, it’s the output of the BM62 internal power source switch (battery or USB) but it’s a pity the datasheet doesn’t give the current capabilities of this pin.BM62_power_tree.png

(There are three other pins with voltages from the BM62, VDDA, BK_OUT and VDD_IO, but here, the datasheet says you’re not supposed to use them).

Low power design

The BM62 power consumption is around 15mA when streaming music, so the current taken by the PIC at that time isn’t really a problem and because it runs on the internal oscillator, it will be around 2mA max. anyway. The concern is when the headset is in sleep mode, with the BM62 powered off (10uA power off quiescent current). The PIC18LF4550 has a sleep mode current between 1uA and 2uA, quite good.

But the problem is everything else. Here, I messed things up by connecting the potentiometer between the power rail and the ground. With a value of 270 Ohms, the current would have been 11mA all the time, enough to drain the 800mAh LiPo battery I chose in two days. Bad design. Luckily I had spare pads for the PIC I/Os and I connected the Vcc of the potentiometer to the PIC (through a 1KOhm resistor) and I am only switching it on when I need to convert the value. I am also putting all the other IOs in high impedance (inputs) to minimize the sleep current.

I measured the total battery current in sleep mode (both the PIC and the BM62) around 100uA. It gives more than 200 days in standby.

Driving the BM62

Because I hate to spend more time on the embedded code than on the electronics for one-off projects like that, I tried to keep the things as simple as possible. First, I was using the BM62 module’s configurable control pins, but it ended up to be half unreliable, half annoying because of the time needed to change and upload the BM62 EEPROM configuration. I went for the serial communication instead.

Here, Microchip provides an Excel file which lists all the commands and parameters. Someone had the good idea to make a sheet (tab) per command, so you end up with a file with more than 100 tabs. And the links to go back to the command list don’t seem to work with LibreOffice. Luckily, there is a doc file with the same content and linearly organized. It also gives the timings for the data and the error handling. Each serial command is composed of:

  • Start byte (0xAA)
  • Length (2 bytes)
  • Operation code
  • Parameters
  • Checksum

With an optional 0x00 byte at the beginning of each transmission, in case the USART controller of your system can interrupt on this break character (like the PIC18F4550).

The checksum is described as:

Check sum rule: Summation of every byte after START WORD(LENGTH, COM.ID, COM PARAM, CHK SUM) is 0xXX00

Well, it’s not. Here again I found the answer on a forum. Yes, you have to sum the bytes from the length to the last byte before the checksum, but then invert the value and add 1 to it. Here is a working code:

uint8_t calculateChecksum(uint8_t* startByte, uint8_t* endByte)
 uint8_t checksum = 0;
 while(startByte <= endByte)
  checksum += *startByte;
 checksum = ~checksum + 1;
 return checksum;

And here, for reference, the function I wrote to pause or play the music when you push the potentiometer button while the BM62 is streaming:

void TogglePause(LEM_state_t *s)
 char buf[7];
 buf[0] = 0xAA; 
 buf[1] = 0x00;
 buf[2] = 0x03;
 buf[3] = 0x04;//music control
 buf[4] = 0x04;//reserved ??
 buf[5] = 0x07;//play pause toggle
 buf[6] = calculateChecksum(&buf[1], &buf[5]);
 bm62Puts(buf, 7);

An other little detail missing from the documentation is about the two LEDs controlled by the BM62. Of course, you want a blue LED to flash when streaming, because you know, Bluetooth. The other LED can be green. Unfortunately, I could find nowhere in the datasheet or the tools which one of the two pins called LED1 and LED2 is for which color. Of course Murphy got me and I had to bodge the PCB to invert the two. For reference: the LED2 output is forthe blue one.

The source code can be found on my Github. Because I only included the files directly related to the BM62, you won’t be able to compile them directly (I omitted all the USB-serial converter files from Microchip). The code is quickly written and doesn’t reflect my magnificent embedded C skills… 😉


I made a short clip to show the headset working:

I’m very pleased with the results. I can use the headset a whole week, using it a few hours everyday on a single charge thanks to the 800 mAh LiPo battery combined with the low power consumption of the PIC and the BM62 module. The headset doesn’t seem heavier than before and the sound quality is the same. FTW!

Have a gif before you go :

BM62 LEM Headset.gif


**good enough

Adding Bluetooth to Vintage Headphones – Part 1


A few years ago, I rescued a pair of nice headphones from the trash and replaced the original speakers with better sounding Sennheisers.

Then, I changed the jack cable for something fancier (and I must admit, less practical).

Now, it is time to put the headphones on the operation table once again to cut the wires..

Because I wanted to keep the headphones as much in their original state as possible, without adding holes, I decided to use the original potentiometer for control and volume. This means I had to find a way to detect a press on the potentiometer. For the bluetooth part I will use the Microchip BM62 Bluetooth module. It’s really cheap and has everything already built-in (Bluetooth LE, a serial interface for control, pins for LEDs, a battery charger and an audio amplifier).

The potentiometer button

The potentiometer is original, 220 Ohms and audio-grade, from Dralowid, a now defunct german (DDR) company, from Berlin..

It was attached by two rivets and a bunch of washers to the side of the left ear cup:


After drilling the rivets out:


The back side:


The idea was to use the rivet holes in the earcup to attach a piece of PCB with a pushbutton. Another piece of PCB will hold the potentiometer and have an actuator for the button and an axis in common with the first PCB.

For this, and also to refresh my Autodesk Inventor skills, I decided to model the whole assembly in 3D.

First, the potentiometer:


Then, the earcup. It’s not perfect, but the essential part (the recessed half-round volume with the two rivet holes on the side, the potentiometer slot and the two openings on the “bottom” part are accurate):


From this point, we can try to make the first PCB with the axis and pushbutton:


The slot below the pushbutton will limit the range of the potentiometer push and pull course. I chose an SMD pushbutton hard enough not to need a spring. A piece of foam glued on the ear cup speaker will help to hold the second PCB in the “off” position.

I started with a M2.5 axis screw, but switched to a smaller M2 size because the screw head is smaller and makes a smaller countersink in the 1.6mm PCB. The two screws holding the first PCB to the ear cup are M2 with nuts and spring lock washers on the outside.

I designed the second PCB to hold the potentiometer and actuate the pushbutton:


I exported the drawings to Altium and designed the “real” PCBs:


I made two versions of each PCB: one with a M2.5 axis screw and one with a M2. The small PCB rings are to be soldered of the inner sides of the axis holes, to increase the inner axis length and to constrain the rotation.

Then an other export of the PCB step models into the Autodesk 3D model. Finally I printed the various parts on paper and cut them to check if they were accurate.

Signaling and charging

The left ear cup has two additional holes for the audio cable: a round one for the cable itself and a slot, for the cable restrain. These will do nicely for a RGB LED and a mini USB socket:


The USB socket and the LED are on their own little PCB, which is attached by two pieces of acrylic hand-cut to fit the curve of the ear cup (easier to adjust for the ear cup curves and to tweak the USB plug angle). I will create a custom light pipe for the LED, made of acrylic too.


The main PCB

The BM62 module has a serial interface, but can be used standalone with a button interface too. Because we need a way to read the position of the potentiometer, it would be best to interface the Bluetooth module to a small microcontroller. A PIC of the 18 range will do nicely, especially from the LF voltage range (2V … 5.5V). It will save the hassle and BOM lines of a DC/DC converter – the BM62 has an integrated battery charger.

An other plus for the microcontroller: the headset battery will be recharged via the mini USB socket. The Bluetooth module’s configuration is stored in its onboard EEPROM, programmed via the serial interface, the PIC will act as a USB-RS232 bridge, allowing me to easily reconfigure the module.


I tried to keep the things simple and, because at the time when I designed the PCB, I didn’t have the module or the microcontroller, I routed all the pins of the BM62 to the PIC. I also included options with 0 Ohm resistors to select the source of the PIC power supply (the BM62 has several pins tapping its internal voltage regulators) and to select the source of the LED drive (Bluetooth module or microcontroller).

The PCB with the USB socket and the RGB LED is connected to the main PCB with a flat flex ribbon (connector P5 on the schematics).


(sorry, my Altium version seems to have problems with 3D and bottom soldermask).

So, let’s see if we can get everything into the ear cup:


So far, so good. There might even be some room for a small LiPo battery.


I ordered the PCBs and the components. The 3D vs. reality and the final assembly will be for the second part of this article. Stay tuned!

Link to the second part of the article here.

Simple and Cheap Temperature Logger v2.1: Source Code

Hello everyone. I know this blog has been dormant for “some” time. I should post some new projects soon. In the meantime, I uploaded the source code for the USB logger to my Github repository and changed the licence to GPL v3. Like always, it is provided “as is”. Actually, you should read the articles and write your own source code, it will be faster than trying to make work the code I wrote.

I can’t provide any help – this is not a project for beginners – especially if you try to make a commercial project with it.


Bathroom Mirror

bathroom led mirror _updated

[First, I’d like to apologize for my too long absence. I’m now a full time hardware engineer, since two years. My job and the projects I’m working on are exciting, but also quite demanding of my energy and time. My level of laziness being constant, I gave up on writing articles (even if I still do electronic projects at home). This new article is about something I built last year. That’s being said, let’s start:]

[TL;DR: scroll to the end of the article to see more photos, a video and github]

For these of you who have been following my blog, my biggest project so far is the USB temperature logger. I enjoyed making it, I like the outcome, but it has one problem: if you’re not an engineer or a bit technical, it’s not cool. I wanted to make something people would see and find cool (you can add vanity to my laziness). Something with light and not an other LED strip attached to an Arduino. And this time, I wanted an enclosure.

The inspiration came from movies and a poorly lit bathroom: a bathroom washbasin mirror, with lamps around it. To spice things up, it had to be at least dimmable.

Something like that, but round:


After some experiments with lightbulbs and triacs, I decided it was a bad idea to have 220V-powered light bulbs (made of thin and sharp glass), ten centimeters from my head, when my face and hands are soaked with water … But I still wanted something looking like lightbulbs.

The solution came form Paulmann, a german manufacturer offering these things:


It’s supposed to be a customizable system of light bulbs (they offer different sizes, shapes and colours for the “bulb” and you can screw halogen, fluo or LED sockets inside). A bit on the expensive side (10€ for a set) but I was only interested in the glass bulb anyway (the bulbs can be bought separately, for cheaper).

With these, I would be able to use LEDs solving many problems:

  • Safety
  • 60Hz whine
  • System complexity (no more 220V, triacs, isolation to handle, just PWM)

I also wanted the possibility to display time with the lights, so I decided to fit twelve of them, on a round shape. Here are my first sketches:

LED_Mirror_Sketch LED_Mirror_Sketch_2

Because the LEDs will be driven by a microcontroller, I could add some cool features:

  • A motion sensor (so the mirror lights up when one enters the bathroom)
  • A capacitive touch sensor dimmer
  • An internal clock, to adjust the the luminosity according to the time of the day or night.

Let’s make a list of early parts/requirements:

  • LEDs: x12 High power (~10W each) warm white
  • Microcontroller with 12 PWM, USB, RTCC
  • Capacitive sensor (slider)
  • Movement detector (PIR type, as small as possible)
  • Off the shelf power supply
  • The frame of the mirror should contain all the electronics
  • A mirror (duh!)

I started by finding the right dimensions and design for the enclosure/frame. With standard mirror sizes (ie. the ones available at my local hardware store), a size and spacing of the bulbs that would look harmonious, I got an inner frame diameter of 52cm (Ø50cm mirror) —20 inches. The frame is 8 cm (3,15″) wide and the bulbs have a diameter of 6 cm (2,36″).

It’s made of wood. All the electronics and LEDs are mounted on the bottom ring, the upper ring has holes for the bulbs and supports the sides of the frame. Some pictures of the construction:

LED mirror enclosure - rings

The face and base rings, with spacers glued to the face ring. (upside-down)

LED mirror enclosure - face ring - inner view  LED mirror enclosure - front ring

Front ring, with holes for the LEDs. The wooden pieces act like spacers between the front and back rings and support the 1mm thin side plywood (just bent and glued around).

LED mirror enclosure assembled

Completed, with pivoting support for the mirror.

LED mirror enclosure - completed - with bulbs

With the bulbs. They are glued with silicone joint from inside. The silicone gives some compliance, so the bulbs can move instead of immediately breaking at their base if hit.

At the same time, I worked on the LEDs and the driver:

I chose Bridgelux BXRA-40E0810-A-00 LEDs. Warm white and star shaped footprint. 980 lumens @28,1V 350mA.


For the controller, I found the TS19371 Boost white LED driver, with PWM input and OVP. From Taiwan Semiconductor. As it’s a one-off project, I didn’t care about long-term availability. The other components are quite standard.


The LED current is calculated with the following equation:

Iled = 95mV / Rf

I have a 0,22 Ohm feedback resistor, resulting in a 430mA calculated LED current, which doesn’t match the values from the datasheet’s schematics or the current I measured.

Plot of the input power (@12V) and the LED power (@28V) vs. the PWM duty cycle:

TS19371 power vs PWM

Which gives the following efficiency (vs. PWM duty cycle):

TS19371 efficiency vs PWM

Not bad, especially the most comfortable luminosity is between 40 and 80%.

LED Driver Schematic (pdf)


There’s a bit of “whine” at some PWM values, probably due to the two big ceramic capacitors. (piezo effect). Later, I added big value capacitors (1000uF) across the power supply, every two driver boards.

Even if the LEDs are from a good brand and have a good efficacy, they get very hot without a heatsink. The problem is, the mirror frame is closed and doesn’t have any airflow inside. Putting a fan is of course, out of question, same with vent holes.

My solution was to mount the LEDs on aluminium rods, which act like a heat storage. I got twelve of these rods, 20m diameter and 25mm high, for one Euro each, already cut, on eBay:

BXRA LED Heatsinking

(first revision of the PCB)

Here’a graph of the temperature increase of a LED at the maximal voltage and current (100% PWM):

LED temperature curve

As you can see, no heatsinking isn’t an option. With the aluminium rods, the LEDs can be at 100% for quite long (bathroom timeframe). The software takes care of dimming the light after 15 minutes. There’s also a temperature sensor on one of the heatsinks. The maximal intensity is anyway too bright and shouldn’t happen too often. The startup luminosity is about 50%.

Some photos of the LEDs and drivers construction:


Heatsinks with tapped holes (plus one mounting hole –M3– on the underside).



Driver PCBs with solder paste — ready to be populated.


After reflow.



The next step was the capacitive touch dimmer.

I used the Atmel’s AT42QT2160 Qslide – Matrix Sensor IC. Quite powerful and versatile. It can have up to 16 keys or/and one slider of 8 keys/bits (0..255). For once, Atmel provides an exhaustive data sheet, plus a lot of design material for the keys/sliders/wheels. (Now, you can even get footprints for Altium designer).

It works by sending a charge pulse to one side of an electrode (the sensing element) and sampling it on the other side, comparing the changes over time. Fingers change the capacity of the electrode, as well as the intensity of the sensed electrical field. If the resulting signal goes below a threshold, the chip counts it as a touch. The electrodes can be laid out to form a linear pattern, making a slider or a wheel and the chip configured to output an X value corresponding to the touch position on the slider or wheel.

I followed Atmel’s recommendations for the design of my slider. I managed to get a very good definition, even through the thick wood. (On the first version of the mirror, the sensor was on the side, sensing touches through the 1mm thin plywood. After the update, it’s on the front and still works great through 5mm of plywood!).

Because of my requirements of sensitivity, wood thickness, length and definition, I designed a “Mutualy Coulped – One Dimensional – Two layer – Resistively Interpolated” Slider:

Large resistively interpolated capacitive slider

(Atmel’s “Touch Sensors Design Guide”)

The sampling signal is emitted on the Xn lines (top PCB side) sequentially and sampled on Y line (bottom side).

Which looks like that in real life:


Bottom (fingers) side with the Y sampling traces.


Top side: Xn electrodes. 0.8mm PCB, so it could be bent and follow the shape of the mirror frame. Even if the bend radius isn’t too small, I used 0402 components and tried to place them parallel to the bend. The PCB has a footprint for an EEPROM, sharing the sensor’s i2c bus. (The first microcontroller I used didn’t have any EEPROM).

Slider and AT42QT2160 Schematics (pdf)

The data sheet gives two important measures to make:

AT42QT2160-Cs-X7 Sampling Cap

The sampling capacitor Cs voltage. It shouldn’t exceed -0,25V and the ramp should be linear.


The charge transfer pulse (measured with a coin on the sensing surface): Should be square.

The AT42QT2160 connects to my microcontroller via an i2c interface. It has a lot of registers to tweak configuration and parameters for the touch detection. The sensitivity can be adjusted without having to change components on the PCB.

A “change” output pin can be used as an interrupt and relieves the micro controller from sending continuous interrogations on the i2c bus.

Led mirror AT42QT2160 touch sensor PCB on the frame

The touch sensor attached to the frame with double sided tape (on the front of the frame, after the update). Note the silicone joint holding the bulbs and the wooden spacers supporting the sides of the frame.

The motion sensor.

PIR sensors can be tricky to implement, so I took the easy way and used the Zmotion Detection Module II from Zilog. It costs 10€ from Digikey and only needs a 3.3V power supply and an RS232 interface.

I won’t write a lot about it, first because its implementation is straight forward and second, because I don’t use it anymore after the update, so I didn’t write the code to support it in the new microcontroller.

ZEPIR0BAS02MODG PIR sensor Zilog

It features a small microcontroller and a pre calibrated PIR element. Plug and Play.

It also has parameters to tweak the sensibility of the detection and can even tell the direction of the detected movement (going from left to right or right to left).

An other reason why I chose this sensor board, is because the PIR lens is really tiny and once mounted inside the mirror, it’s almost invisible (because of the shape of the bathroom, the sensor was on the side, even more difficult to see).

The light coming from the LEDs was messing with the sensor and it detected a continuous movement once the mirror was on. I had to isolate the sensor board with aluminium foil and tape. Not a big deal.

Putting everything together and giving it a brain.

Ok, now we have our mirror and the frame, 12 LEDs, the touch dimmer and the movement sensor. How do we make everything work?

For the first version, I used a PIC18F87J50. An Xmega256A3BU after the update. I won’t start a debate on Microchip vs. Atmel (that should be a future article), especially the mirror worked exactly the same with both of the microcontrollers.


If you’re familiar with these two microcontrollers, you’ll know they don’t have 12 PWM outputs.

So how can they control the intensity of each of the LEDs?

Simple: Software PWM. Because the LED driver has its own switching frequency (1,2MHz) and an enable input that can be used as PWM dimming, the PWM frequency coming from the micro controller doesn’t need to be too high. In my case, it’s between 120 and 300Hz. Enough to have a good persistence of vision.

(actually, the software of the first prototype was a bit slower and did a cool stroboscopic effect, you could see the water drops going up when you were taking a shower. Psychedelic, but not that funny at 7am, half asleep).

To implement my software PWM, I’m using a timer which fires an interrupt and increases a 8 bit “PWM counter” variable. Each LED has a variable with the PWM value it’s set to. In the same interrupt, I compare each of the LED variables to the PWM counter, setting the corresponding LED pin high, if the LED PWM value is higher than the PWM counter, setting it low if the LED PWM value is smaller than the counter.

There is a few more subtle things:

I’m using the Xmega virtual ports feature, it speeds up the execution of the interrupt (one ASM instruction instead of three or four).

Each LED value is compared sequentially, so they don’t switch on or off at exactly the same time. You cal call it a sort of crude spread-spectrum PWM 🙂

Schematics for my ATxmega256A3BU module

I’m using a 16MHz crystal to clock the Xmega, because the internal RC oscillator had too much jitter (which isn’t a big deal here, it just annoyed me).

Here’s the interrupt jitter with the internal RC oscillator:

Xmega Internal RC oscillator jitter

And (almost) the same measure after switching the oscillator to an external crystal:

Xmega External Crystal oscillator jitter

3,5us vs. 10ns Not bad.

I’m also using the USB interface to be able to monitor the microcontroller and set a few parameters (date/time, touch sensor sensibility, read the temperature etc.):

ATXmega256A3BU USB console

Measuring Temperature

I’m a big fan of the TCN75 i2c (or similar) temperature sensors, but here, I wanted something I could directly attach to one of the LEDs heatsink:


It’s a Thermistor ( NTCALUG03A473H ), a temperature-dependant resistor. I hooked it up to the Xmega’s A/D converter.

My voltage to temperature conversion is very crude, an array of voltages every 5°C, plus an interpolation to get 3°C resolution. I didn’t need more, because I’m just using it to dim the LEDs when the heatsink temperature is too high.


The thermistor, screwed to the side of the upper LED heatsink.

An other feature I found cool to implement, is an anti-fog system. To avoid condensation on the mirror when you’re taking a shower, the mirror is heated up with a resistive wire attached with kapton tape on the back side of the mirror.

Resistive Wire


The one I chose has a 6,93 Ohms resistance per meter. It gives a current of 1,73A per meter with a 12V power supply.

It’s annoying to work with, because it’s very springy. And it’s even more annoying to solder, even if the data sheet states the opposite.

Unfortunately, the way I attached the mirror to the frame when I built it one year ago prevented me from taping the wire till the center, so only the outer part of the mirror is heated. It works nevertheless not too bad to keep the center free of condensation.

I have two loops of this wire in parallel, taking 2A in total and heating up to 50-60°C. The kapton tape presses the wire against the mirror, ensuring a good enough thermal transfer.

The heating is switched on and off by the microcontroller via a MOSFET transistor (2KS4017).


Resistive wire kaptoned to the mirror’s back.

The power supply.

I said I didn’t want to play with AC and the whole mirror was running on 12Vdc. So what powers it?

PWS 150 150W power supply

A 150W 12V AC-DC converter. 150W is more than enough to power the 12 LEDs and the 2A resistive wire.

In the first version of the mirror (and the first bathroom), it was sitting on the side and the mirror was switched on and off by the motion sensor.

After I moved to my new place, it’s actually connected to the bathroom’s socket for the washbasin light and the mirror is activated with the switch on the wall (it’s a double switch, one for the ceiling lamp, the other for the mirror).

I put some white fabric sleeve on the wires, so they don’t look too bad.

Putting things together.

LED Mirror bottom

The twelve LEDs are attached round the enclosure’s baseplate with a screw, from the back of the baseplate to a taped hole in the bottom of each heatsink. The driver boards are held with a wood screw, directly on the baseplate.

LED Mirror Bottom wired

The driver boards’ power supply is just wired in parallel (the thick blue and brown wires). Each driver’s PWM input is connected to the microcontroller board.

LED bathroom mirror First test

First power up. I taped the bulbs to the heatsinks, because the LEDs are really powerful and hurt eyes if looked directly at them.

The development “simulator”

Every time I wanted to develop new functions for the firmware, I had to take the mirror from the bathroom, put it on my bench, open the enclosure, connect the AVR JTAG debugger, program the firmware, test it and put the mirror back in the bathroom. Not very convenient.

Because I made several ATxmega256A3BU boards and I order my PCBs from iTead Studio, so I always get ten of them, I could replicate the mirror on my bench, with 3mm LEDs instead of the Bridgelux ones. It has all the functionalities of the mirror, so I can take as much time as I want to write the firmware and to test it:



When I’m sure the new firmware is ok, I just update the real mirror via the USB bootloader. (I made a cutout on the top of the enclosure for the USB plug, next to the 12V DC jack socket).

Photos of the first version/bathroom:

Bathroom LED mirror

Bathroom lightbulb mirror

(The PIR motion sensor lens is clearly visible on the side of the frame)

When I moved to a new flat, after the update:

bathroom led mirror _updated

And a quick video showing the main features:

The firmware sources can be downloaded from my github:


The first version of the mirror has been running for one year without any problem. The updated version, for six months now. I wish I had written a series of articles along the design and build of this project, because even if now I still remember all of my process and decisions, the resulting article is a bit long and not detailed enough.

Concerning the mirror, having this big wooden piece the mirror is glued to, prevented me from putting the heating on all of its surface. It works ok, but sometimes it fails to keep the center of the mirror fog free.

If I have time, I’ll try to find a way to put resistive wire on the middle too.

Because the 150W AC/DC power supply has a lot of capacitance and the 12V rail has big capacitors, there’s a one or two seconds lag between the moment you switch the mirror off and the LEDs going actually off. It would be a nice to implement a 220V detection circuit, so the microcontroller knows when the AC current disappears and can switch the LEDs off quicker (and also with an “animation”).

Vintage headphones mod – The ultimate hipstery conclusion

I started this blog by modding some “vintage” headphones, replacing the original bad speakers by a pair of Sennheisers. It was almost two years ago.

Last month finally happened what usually happens to audio jack cables: “qsdfg#efdfg#jnd#qdfg#skdglcvnqse” instead of my usual music (which is almost the same, but without the “#”s ).

I decided to totally pimp the new cable by using one of those “fabric 220V cables”. I had the idea for a while, but I didn’t realise the fabric covering isn’t actually glued to the cable and you can use it on an other cable.

I got one on eBay, 1.99€/metre, plus a 5-metre long jack/jack cable of reasonable quality:

01-Fabric-audio-cableI cut the audio cable in half so I can still use the other half for something else (or as a spare).

The fabric covering is very easy to strip (it slides off) but more difficult to put back. It was a good idea to put tape on the cut end of the audio cable, so it could slide easier.

Then, I just glued the fabric to the jack plug and secured it with a cable tie when it was drying:


Soldering the cable back in the headphones:

04-Fabric-audio-cable(you can see how easily the fabric strips off and also the tape at the end of the audio cable to help with the sliding-in)

After, I added some turns of thin electrical tape, to avoid the fabric fibres to strip out:


Et voilà:

Headphones1(After testing the new cable, I realised it was the audio socket of my iPhone that had a problem, not the headphones’ jack.. )

Simple and cheap temperature logger: v2.1 [UPDATE: EEPROM in BOM corrected (SST25WF080) ] [UPDATE2: Link for the Github with source code]

Hi everyone!

It’s been too long since the last update. But it’s there! The last version of the temperature logger, the hardware and the source code.



The changes since the last version:


  • New footprint for the PIC18F26J50, easier to solder.
  • Only 0603 or bigger resistors/capacitors.
  • The serial EEPROM is now a SST25WF080, still 8Mb, but easier to source.
  • Some components price-optimized (USB connector, switch, 3.3V reg).


  • Each logger can get a number, shown in the mass storage device drive name: simply add an asterisk (*) followed by the number you want to assign to the logger (between 0 and 65535) in the config.txt file (after the logging period), save the file and format the logger.
  • Bug fixes in the FAT12 functions, but the logging space is still limited to the half of the EEPROM.
  • Other bug fixes (month and year change, added robustness). The memory and the EEPROM are now scanned when you plug the logger back, to get the last data and reconstruct the filesystem in the case of a battery failure.

Temperature Logger 2.1: Schematics and basic BOM

The Altium files

The source code (based on Microchip Applications libraries -Device – Mass Storage – SD Card data logger- MPLABX)

The source code is now available from my GitHub: Temperature Logger v2.1 – Github

I also made a program/debug adapter (especially useful for debugging):


USB-Temperature-Logger-Programming-tool1This is the “office” version of my previous peg-adapter 😉

A lot of people were asking me if I was selling these loggers. Unfortunately, no. The design and functionalities are sexy, but I don’t have the capacity to launch a production on my own. And if I had do make only a small batch, the price would be totally uncompetitive.

A big thanks for all the people who donated a little something to motivate me!! (or to help me be more ashamed of the lack of updates)

All the contents (except the parts of Microchip’s code in the source) are under the Creative commons license, Attribution – Share Alike – Non Commercial.

Creative Commons License
Simple temperature logger: v2.1 by Jean Wlodarski is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

Cheap, quick and dirty reflow oven

I got this cheap toaster in a “crap shop” for 11 Euros. It’s perfect for reflowing PCBs and small enough to fit in my lab:

Reflow-ToasterI tried to use only components I had at hand, including:

  • a DIP PIC 18F2450 (total overkill to control a heater, I know)
  • a relay from a timer AC socket
  • a small USB iPhone charger for the +5V supply
  • a K-thermocouple and a MAX6675 for the conversion (quite expensive chip, but very simple to use and I had it in a drawer)
  • a small LCD screen, two buttons and two LEDs

The PIC is running from the internal RC oscillator. Very slow, but enough for what it’s used for.

The relay comes from this timer I bought some time ago at Conrad:

It’s rated for 2000W, the PCB is easy to re-use and fuse protected. I added an opto-coupler, so the PIC and user interface are fully isolated from the 220V mains (also convenient for debugging). I thought about re-using the timer’s LCD and microcontroller, but it’s directly bonded on the upper PCB and difficult to hack.

I managed to squeeze everything into the toaster’s plastic flange. (Unfortunately the temperature can increase a lot inside, so I think I’ll move the electronics into a box, outside the toaster)

For now, I just have two functions:

Drying – keeps the oven at 100°C

Reflow – follows the standard leaded solder paste curve (2 minutes@150°C – 2minutes@200°C – 1minute@250°C)

The LEDs also act as switches to select between the two functions. I’m still looking for a good method to cut plastic in a clean way. It’s not so easy with my Dremel.

It took me more or less one day to build everything (I wasted some time for the LCD display control).

I’m only using the heating elements from the upper “toast hole”. The bottom stays cool enough for the toaster to sit on a table without the need of extra feet or thermal protection.

And of course, the oven works just fine for the small PCBs I have to solder!