Welcome to CuVoodoo,
the sorcery of copper.
In this video I will talk about this scale.
A friend gave it to me because the battery ran out,
and he did not want to buy new ones.
And this is because as you can see here
it uses two coin batteries.
2x CR2032.
Each one provides 3 V, so both of them provide 6 V to the board.
And because 6V is quite an unusual voltage for electronics,
I thought there would be a voltage regulator
which would convert the 6 V to probably 5 V or 3.3 V.
And since there is a voltage regulator
I thought "why not provide even more".
Here we have a 9 V battery
which provides the power,
and which will replace the two batteries.
These batteries are a lot easier to find,
and a lot cheaper than coin cells.
And if we try it we see it works perfectly fine.
The other modification I did was this.
As you can see here there is a USB port.
And the idea I had is that I want to connect this scale to my computer,
so it can automatically can read the weight which is on top of it.
And I wanted to know how easy it is to make that,
and how easy it is to read the measurements from this scale,
and interface it with a computer.
Now if you want you can now use it as part of the quantified self movement,
and track your weight gain, loss, change over time, directly by connecting to the computer.
And we'll have a look in details how I did it and how it works.
As you can see font the back there is not a lot of interfaces.
I already change the battery,
and then we have one switch and two pins.
The switch is to change between the units which are used.
Right now it uses kilograms.
The screen is flipped because normally this is on top.
Here we can see "kg".
If we change to the middle,
wait until it switches off.
Let's start it again.
It re-calibrates.
Here we have "lb". This is the sign for pounds.
This is the imperial unit which is used in the US.
But I really prefer the units from the International Systems (SI), so kg.
And then the last one, it has 3 positions.
And the last one is even a weirder measurement unit.
Let's wait until it stops and then we will see.
Here it starts again.
And here it is: "st".
"st" stands for stone.
This is a British unit, and I think it's around 6 kg.
1 st ~ 6 kg.
1 pound is a bit less than 0.5 kg.
Here we have the switch.
The second thing we have here is the two pins,
which you can see here.
And this is probably not an interface to connect to the computer.
One is ground.
One pin would be ground.
and the other would be just one signal.
It could be just to communicate with the scale.
You would have to implement a one wire protocol,
if you want to have it bi-directional.
You only want to put such an interface if you want to calibrate it.
But having this implementation of a one-wire or single wire protocol
is quite a bit of an overhead for just a very cheap scale.
We you have 2 pins you immediately think about jumpers.
If we put the jumper on these two pins ...
I hope I can do it through here.
Here.
Now we have the pin.
And if we switch it on ...
Let's put to kg.
And if we switch it on,
we see it shows all the segments and then it's in "CAL".
So it's really for calibrating the scale.
And how is works is that you put 50 kg on top of it.
We it started it just measured 0 kg.
This is what you see in the initialization,
when the "8" moves.
Then you put 50 kg on top of it
and then because it is probably linearly proportional
it just knows what the slope is,
so it can figure out the weight on the scale.
This is how you calibrate the device.
And as we can see, it's not really an interface.
So the next thing is, we want to have a look inside,
and see if there is an interface hidden inside.
As you can see I already did some modifications.
The first one is this battery which goes here to the battery port.
Then we have cables.
These are also what I modified afterwards on this pin header.
This pin header wasn't there in the beginning.
Neither was this one.
Only this pin header for calibration was populated,
and this row,
this row too,
which goes on both sides.
Probably it's for the weight gauges.
Remove the battery.
I added also this one so I connect the battery directly, instead of having cables.
We'll have a look at all these ones once we see the other side.
But as we can see the board is pretty simple.
We have a paper board,
because of the brownish color.
It is single sided.
There are no traces on this side.
We only have some components.
But no all the components.
They use a mixe between surface mount components and through hole components.
Let's have a look at the other side.
This is the other side.
As you can see it's pretty simple.
We have three buttons on the top.
And this is for the menu, so you can set the profiles
about individual persons.
Then we have here a zebra connector.
The zebra connector is connected to this sort of cable.
And then it goes to the LCD.
Then we have here the voltage regulator.
So we actually do have a voltage regulator,
and that's why providing 9 V is not an issue at all.
Here we have a quad op-amp.
I'll explain a bit later why we use an op-amp is weight scales.
And this is memory.
This is I²C EEPROM.
And this is to save the data which you configure using these buttons.
And then you can have you weight recorded over time.
And here we have as always a die under a blob of epoxy.
And this does all the calculations and so on.
It handles the LCD.
It handles the I²C memory to store the data.
And it handles the input which is coming from the quad op-amp.
Actually we need an op-amp ...
How weight measurement works is pretty easy.
They use strain gauges.
As you can see here.
We'll take one off.
These are all the cables. We have 4 of them.
1 in each corner,
and we've seen with the feet on the other side.
1, 2, 3.
The other one is also in the corner.
And how these work is that whenever you apply pressure ...
This is just bare metal.
And the the bare metal you have 3 wires.
What it under the bare metal is just some resistors.
And the idea is that when you push on the metal,
because of the weight,
you will deform it.
You will distort it.
One side will get compressed,
when you push hard on it.
And the other side will be expanded.
And this change the resistance of the metal, and trace connected to the wires.
So what they do here is, they just take the resistance,
and then it goes to the op-amp.
And the op-amp amplifies this subtle difference.
So you can really measure the weight using that.
And this is how simple it is.
We also have two cables right here.
And these go to the metal plates,
as you've seen on the other side.
Now the buttons are falling off.
We have metal plates on the four corners.
These are used to measure the conductivity of yours skin.
They use that to determine the amount of water or fat you have in your body.
But I don't know how this is done actually.
I was only interested in the weight.
So this is the weight gauge.
Here we can see we have a small push button.
And this is what we hear clicking,
every time we step on the scale.
We even have two of them, in the front.
On the back.
On this side.
One here, and one on the other side.
And the scale only activate if you push on this button.
Then it starts measuring whatever is on these strain gauges.
That's pretty much all actually.
We have 4 strain gauges,
which go to the op-amp.
And then this is processed by this micro-controller.
And here is the connector which I soldered.
The signals come directly from the chip itself.
So probably this is already some processed data.
We want to identify what these pins, which I soldered here, and these pins are.
This will be our next step.
Now we want to find out what's on these pins here.
And the first thing you always do is find the ground pins.
For that you will just use the multi-meter,
in the continuity test mode.
You can see here we go in the continuity mode.
What it does is that, whenever you short the leads,
it just beeps.
And this tells us that the two pins are directly connected.
We know ground from in battery in the beginning.
The minus pole which is here from the battery is also used as ground.
And then anything else is ...
And then this is power (positive voltage).
We go through the pins.
(beeps) We only have one ground pin.
This is ground. This is also why I soldered a cable.
On the calibration pins, the right pin is also ground.
And the left one is probably connected to a pull-up resistor.
So when there is no connection on this pin,
then it's high.
And then when you put the jumper,
it ties this pin to low.
And this way it knows "ok, now I have to calibrate".
And on these pins, there is no ground.
I don't know what BM is. I couldn't figure out.
But we'll have a look at these pins.
Now we know that this one is ground,
we want to see what voltages are on these pins.
And for that I will first connect the battery on it.
And we will measure the voltage of each pin.
Now I'll connected back the battery and will measure the voltages which we find on these pins.
For that you just use the multi-meter, go in voltage mode.
I'll put it here so you can see the values.
Here we know we have ground.
Then we can just probe the other pins.
First we have to switch on the board.
So we press on the foot, and there is a switch, as you can hear the small click.
It switches on the board.
And then we can measure the voltages.
Nothing.
3.3 V.
So we know that the voltage regulator regulates at 3.3 V.
3.3 V.
Here we have 1 V,
but it's fluctuating.
as you can see.
It's 1 V, but it's fluctuating a lot.
And here we have 2.3 V, and this is not fluctuating.
We wait until it switches off.
There is a timeout.
Here. Now we see it switched off.
And when it switches off, this pin here, as well as this pin,
just go low.
So whenever you press on the button again ...
Let's press on it,
here we can see it's back at 3.3 V.
We can use this one to figure out when the board is on,
and when it performs measurements.
And this is why I connected this cable here.
This cable, as we've seen, varies a lot.
Now the board is off.
Press again.
You can see here 3.3 V.
And this one fluctuates a lot,
depending actually on how strong I press on the foot.
But as you can see, it fluctuates a lot.
This is probably some kind of data which is transmitted.
And we'll have a look on the oscilloscope
what the signal looks like.
Let me connect the oscilloscope to it.
Here I've connected the ground probe of the oscilloscope.
We have the blue probe which is connected to this signal,
which we've seen is at 3.3 V when the scale is on.
And then the yellow probe conected on this 1 V fluctuating signal.
If we look at the oscilloscope, ...
Zoom more.
When I press on the feet to switch it on,
we see that the blue one is at 3.3 V,
as indicated here,
and the yellow one is some sort of a Pulse Width Modulated (PWM) signal,
as you can see here.
And its frequency is around 3 Hz.
But if we look closer a it,
we can see that this changes.
Not only do the duty cycles of the high an low do change,
but also the frequency changes.
It's not exactly 3 Hz all the time.
It's fluctuating a bit.
We see it between the minimum and maximum.
And the stronger I press,
the shorter the high duty cycles is,
and the longer the low duty cycle is.
This is at 0 kg.
And when I press hard on it,
you can see that the high signal is shorter,
and the low signal is longer.
And this gets back.
So we know that this has something to do with the weight.
This is just the signal to know if it's on or off.
And this PWM signal somehow encode the weight which is measured by the scale.
Here you can see it again.
Now I want to measure this value.
We can see it on the oscilloscope,
but we want to interface it with the computer.
So we need something else than an oscilloscope.
Something a bit smaller.
But one which can also measure these signals.
At that's the next step.
And the best way I came with to interface to the computer
is simply using one of these micro-controller based boards.
This micro-controller is just an Atmel ATmega328P.
Here we have USB.
This is the USB to serial converter
to talk to this micro-controller.
And actually although it's written Deek-Robot NANO V4.0,
it's an Arduino Nano clone.
They are pretty cheap,
and this is why I have no remorse putting it inside,
and using it simply for this task.
And I write my own C code for this micro-controller.
We just have to connect the 3 signals which we figured out
to pins of this micro-controller,
so we can measure it.
The most important pin is ground,
which is connected here.
Then we have ...
This is the on/off signal.
I decided to connect it on this pin.
And this is the PWM signal.
So the Arduino ...The Arduino ...
This Arduino Nano
works at 5 V.
So the pins on the ATmega operate at 5 V.
Now we've seen that this is 3.3 V,
but 3.3 V crosses the 0.6x5.0=3.0 V threshold.
So whenever you get a 3.3 V
the 5 V pin still detects that it's high.
But the problem is with the 1V cable.
1 V doesn't cross the 0.6x5.0=3.0 V threshold,
when it operates at 5.0 V.
So we can not simply use a digital I/O pin,
and check if it's low of high.
And we can no use this a trigger.
But there is a special function
provided by this ATmega.
It is the analog comparator.
And this triggers whenever the signal is higher of lower than the negative value.
It has two inputs.
A negative signal, which is on this pin.
the minus pin (AIN0 on PD6, on D6).
And the positive signal which is here (AIN1 on PD7, on D7).
And whenever the value which is on the positive (+) pin
is high than the value which is on the negative (-) pin,
then the analog comparator will tell it's a 1.
And you can even trigger an interrupt based on that.
And this is what I did.
This is also why you see the three resistors here.
This is just a voltage divider.
Here we have ground,
ground and +5V.
So what I do is, I simply divide it by 10,
using these resistors.
And here we then have a 0.5 V signal.
So whenever the pin which is at 1 V crosses the 0.5 V threshold,
we have a 1, and else we have a 0.
And this is how I can measure this signal
and then trigger on whatever is on it.
And the other thing I did is,
simply use a timer to measure the width of this signal.
And then by cutting out a bit from the scale here,
so I can fit this Arduino Nano clone board,
I can just put it inside.
And then we have USB on the front,
as you've seen in the beginning.
You can directly connect to the USB.
I'll shortly talk about the code.
Then we can test it.
Let's have a look on the firmware which I wrote for this ATmega micro-controller.
This is the source code.
It will also be available in the git.
As you can see there are not a lot of files.
And the code this pretty small.
It fits in around 200 lines of code.
Now we can
compile the code,
and directly flash it on the micro-controller,
which it does here.
And now we connect to the serial port
of this board.
For that I use picocom
to open the serial port.
We provide the baudrate,
which you set in the source code.
And then the port which it connects too.
And when you connect to it, it welcomes you with a message.
If I now press on the scale,
it reads the weight.
And whenever a weight is stable,
it will show you this value.
So when I press on the scale
and have a stable value for 1 s,
it will show me ...
for 3 measurements,
but there are 3 measurements per second,
then it will show me the current weight.
But it's only if it's stable.
It's not like the scale which shows you continuously,
but here I only show you when it's stable.
Here the next measurement.
And it I let it rest
it will go back to 0 kg.
And it will stop showing the measurements
once the scale is off.
Now the scale is running.
It still shows measurements.
Now the scale turned itself off
because of the timeout.
And there is nothing displayed anymore.
If we switch on the scale,
then we start from the beginning.
And how it works is pretty easy.
It really takes the PWM ...
Actually let me show it to you.
Let's clean this
and let's make the debug version.
The debug version will show you how it works.
We compile the debug version.
We flash it on the device.
And now we connect back to it.
When I press on the button
it detected that the scale started an is on.
And now you see all these measurements.
Let me press just on the scale to have one measurement.
Let it switch off.
And the we'll go through
from beginning on.
If I can scroll back to the beginning.
Here you can see that the scale just started.
And we see two values.
As we've seen the PWM has two values:
when it's high,
and when it's low.
And this is the number of ticks
I measured on timer 1
for high and low values.
And here I always show which is the current value,
because I average over the last stable values,
and how long it's stable.
Every time a new measurement comes in
it will change.
And if the next value it too far away from the previous value,
it resets this stable counter.
This is where it start to get the zero value.
When the scale initiates
you see an "8" going from left to right,
calibrating the scale,
and zeroing the current measurements.
This is what you see here.
The scale starts.
Then is comes to this value,
and here it gets pretty stable.
This low value is stable,
and then the high value is stable,
and so on.
And we see we have three stables measurements.
Since it's the first measurement,
we count it as zero.
These are the values for the 0 kg measurement,
based on the timer ticks.
And then it starts again.
And every time the value is stable,
within 5 or 10 ticks
of these measurements ...
I think it's 10 ticks on timer 1 and 5 ticks on ...
10 ticks on the high value,
and 5 ticks on the low value.
But you can configure this threshold in the source code itself.
So whenever it is stable,
which you see here:
we have 3 stable high and low measurements,
then it shows you again which was the 0 value,
which is the current value which has been measured and is stable,
from time 1,
and then it interprets it in kg.
And this is what we see when we don't have the debug firmware.
And it continues on and on.
And here we can see for example we've pressed on the scale.
So the value ...
For example here the value is too far away from the previous value.
So it will reset the stable counter.
Start from 0,
and wait until it's stable enough.
And we will see here again here the value is too different,
so it will restart the stable counter.
And after some time we will have a stable value,
and we show the weight which is on the scale.
How I determinate the weight
based on this timer tick,
is pretty simple.
I used this debug interface,
and then I put some well defined weights on the scale,
which I can read on the scale itself.
You just have the 0 value.
You put a weight on the scale,
which doesn't move.
The scale will show you the weight of this object.
The program will indicate the number of ticks it measured.
And based on that I could plot
the relation between the number of ticks and the weight which is there.
And we'll have a look at that.
Here we can see how I did it.
I putted different objecst with different weights on the scale.
And the from the output we just saw from the firmware over the serial port,
I recorded the 0 value:
the timer 1 ticks for the zero value
for the high PWM signal,
and for the low PWM signal.
As you can see it is pretty stable,
if you don't put any weights on it.
Then you put the two values which it has measured,
and which were stable.
This is the difference between the measured value and the zero value,
the delta.
Then I just plotted it.
As you can see, the delta low
is pretty linear and proportional.
While the delta high is not that linear.
By knowing the number of ticks for the low signal of the PWM,
the low value of the PWM signal,
you can proportionally figure out which weight
the object has.
Here we have the number of ticks
and here we have the kg
which are on the scale.
As you can see we can figure it out.
Now the idea is to find the coefficient
and the origin
of this slope,
of this line.
And for that I simply use Wolfram Alpha.
I ask for a linear fit,
because it's a linear curve,
as we've since, it's proportional.
and I want to fit all the point which are in there.
Here we can see the weight,
and the number of ticks.
These points are plotted here.
On the X-axis you have the number of ticks for the low count.
And on the Y-axis you have the weight.
As you can see it is pretty linear.
As the diagnostics also show.
This is the slope.
And this is the origin.
And you can see the origin is not actually 0.
So the scale needs a bit of weight
before it can start measuring correctly the weight.
If we come back to the figure,
maybe it uses the delta high for the low weights.
I don't really know.
Maybe it just corrects what it on there.
But the dots after a certain weight
are quite linear.
And here we have this linear coefficient.
We have the two values:
the slope,
and the origin.
If we look at the code
this is exactly what I put here.
The origin of the low signal,
and the coefficient for this slope.
The value which we see here.
And then I calculate the difference between the 0 level and the measured value,
I multiply it by the coefficient,
I add this origin,
and I just display the weight.
Because the values of the low measurements are more stable and more linear,
I only use that to show the weight.
And that's it.
This way I can put any object on the scale
and read it's weight.
I did some tests,
compared what I measured to what is written on the screen,
and there is a difference of 200-300 g.
Up to 200-300 g.
But that is ok.
I don't require to have a that precise scale.
And the scale itself, if you do the measurement over some time,
for the same weight it will show you different weights.
For the same object it will show you different weights.
So I accept this error.
As long as I have 0.5 kg precision
that's pretty fine for me.
And here we have the end product.
We have the scale,
and we can connect it over USB to the computer.
And whenever we switch it on,
and it does some measurements,
then the micro-controller which is on the back
will send the interpretation of this measurement
and it will tell what weight is on this balance.
It doesn't exactly show the weight which is on the screen,
because this is interpreted a different way.
I simply use the PWM and I interpret the PWM my way.
So they might be a slight shift of up to 300 g
between what is displayed here and what I measured.
But that's ok. That's precise enough for me.
Even more that this scale,
if you measure a two different days,
the same weight,
then you may have a difference of 400 g.
So an error of up to 300 g on the interpretation of the PWM signal is quite ok.
The problem now is that this is not very practical.
Although you can have the measurements over serial using a USB cable,
you don't want all the time to have a computer connected on the scale.
Preferably you would like to have it wirelessly.
And this is quite easy to do.
As we can see here
on the left side we still have our micro-controller,
which is connected over USB,
but then on the right side I have a small module which makes it wireless.
This is an HC-06.
It's a quite cheap UART to Bluetooth converter.
On one side you connect the UART port from this micro-controller,
and on the other side you have the antenna for Bluetooth.
And it provides the serial port profile.
So whatever data is sent over serial,
which you normally read over USB,
is also sent to this board.
Now we can simply take one phone,
which connects over Bluetooth to this Bluetooth module.
And whenever we switch it on,
and do some measurements,
we should also see the measurements appearing here.
And this is what we see.
Here 0 kg.
And whenever I get some stable measurement ...
Let's try to have that.
Here.
With one finger I pressed around 3 kg.
And this way we can read wirelessly the weight which is measured by the scale.
So this is if you want to transform your scale into a very cheap connected device.
You just need a mirco-controller. That's not expensive.
The USB to UART converter.
The UART to Bluetooth converted.
And now you have your own wireless scale, for less than 20€.
And with that,
the project is done.
video blog: https://www.cuvoodoo.info documentation wiki: https://wiki.cuvoodoo.info source files: https://git.cuvoodoo.info Creative Commons Attributions Share-Alike 4.0 International