As I made Wi-Fi scales or where not quit, and generally keep quiet about life

From the title it is easy to see that on an adventure I spodviglo banal desire splagiatit header guys Madrobots . And this is really it was an adventure: one story with only prolonged purchase INA125U so boring that can be a maddening anyone but me. But maybe I'm something about themselves still do not know.

So the scales. I, as usual, did everything wrong. Namely - I did not even look at what they can do at the moment the typical development of the Internet of things the representatives of this group, so to speak, of the scalar. So my weigh scales are able to separate the three different species of man (me, wife and spherical guest in a vacuum), and - five cats. Results sounded nearby smartphone and published in the tablet Google.

And now - on how to do it, having the balance from IKEA, the op amp TI INA125, Arduino Pro Mini, Converter Serial - Wi-Fi HiLink HLK-RM04, a little off rassypuhi and hefty pain in the ass.

There is a contact! h4> Actually, when I bought on Converter Serial - Wi-Fi, it was not so much fascinated by its possibilities (I thought of them then had a very vague concept), but the price - compared with the same Wi-Fi-Shield for Arduino. Of course, it soon became clear that the difference in price for a reason: because the inverter box that bears little resemblance Shield. And, yes, I know - it's obvious to you, but for me it was a revelation, that any GET / POST just will not.

However, I almost immediately after buying tried HLK-RM04 in. First - and all without a microcontroller. Simply plug the power supply (5V) and go on credit default address that is specified in the manual. There, after some doubts (something might screw up) drove their Wi-Fi setup and gave converter static IP, so you do not look for it all over the net.

These are turned settings. Looking ahead - a complete set of options for scales (IP and SSID to substitute their own, but the port speed is quite important - at this rate HLK-RM04 will communicate with the controller):

In the second stage connected to the controller and see what you can do without a library and without effort. It turns out that if you switch the mode to a server connected to the serial port Arduino, and write code that something periodically publishes this very port, then the browser can be viewed printed. Also, in principle, not bad, but not very inspiring. However, I remember it as a last resort.

In general, I would have rolled HLK-RM04 in a dusty box, if not Madrobots. I considered all options are and make the inverter run the web client, and if not, then at least take away from him the data on the smartphone by Tasker, Tasker same post where I want. Fortunately for the first version found Try library WiFiRM04 , which ultimately behaves almost like a library Wi-Fi to Arduino.

There are, of course, and specificity. This library is collected based on the Arduino Mega, and whose memory a lot and serial ports - above the roof. Therefore, the author of the library by default sweeping gesture using two ports Arduino Mega to communicate with HLK-RM04, and the remainder had a connection to the desktop via USB for simultaneous debugging.

And by the way, also taking into account the default debug module is included, even a tiny program with the library WiFiRM04 kompilliruetsya in slightly less than 30KB, so the prospect of migration on the Arduino Pro Mini seemed a little questionable. However, there is good news: the author has provided and still work with the single-port and off the debug module.

On the first written on GitHub, and the second I learned from the форума .

And yet, to be honest, I was debugged on Mega, because it seemed very much a chore permanently disable plug-HLK-RM04 - in fact on Pro Mini it takes only one port, so even banal download a new version of the converter should be turned off. But there is a trick: if after downloading the program to connect to the Pro Mini and HLK-RM04, while a desktop with a monitor port, you can see that it is the controller sends the converter. And it allows us to understand in what he is able to do.

The bottom line for the adaptation WiFiRM04 for Arduino Pro Mini required:

1) at_drv.cpp do so:

 & lt; code class = & quot; cpp & quot; & gt; #define DEFAULT_BAUD1 9600 #define DEFAULT_BAUD2 9600 & lt; / code & gt;  pre> 
 2) In the same place - that way:

 & lt; code class = & quot; cpp & quot; & gt; // use Serial1 as default serial port to communicate with WiFi module #define AT_DRV_SERIAL Serial // use Serial2 to communicate the uart2 of our WiFi module #define AT_DRV_SERIAL1 Serial & lt; / code & gt;  pre> 
 3) In the same place - comment out the #define _DEBUG_

 & lt; code class = & quot; cpp & quot; & gt; // #define _DEBUG_ & lt; / code & gt;  pre> 
 4) There's also - do not forget to put your favorite digital pin in #define ESCAPE_PIN

 & lt; code class = & quot; cpp & quot; & gt; #define ESCAPE_PIN 4 & lt; / code & gt;  pre> 
 3) The change wl_definitions.h MAX_SOCK_NUM 1

In both cases, that Mega, Pro Mini that performance of this hybrid snake with a hedgehog checked in practice - sends a request to the server, which could capture their preparation.

Its burden is pulling, then pulls h4> The next step, I began to study the issue of getting data from the balance. The theory is that, depending on the type of scales are equipped with one, two or four strain gauges. Opening the usual ikeevskie scales I realized that here, in general, the classical scheme: each heel - Sensor, for a total of four sensors. Confused only the number of wires.

. the original fee scales

Around the left, that each sensor is equipped with three of these useful things. However, the same theory is that generally at (constant) resistors two conclusions.

. strain gauge

Aliexpress thoughtful study revealed the following: the cunning Chinese produce sensors in the form of half a fairly popular измерительного Bridge (Wheatstone bridge).

The bridge itself looks like this (picture from Wikipedia, a reference to that next):

And, in principle, everything was clear. But I could not grasp as four half-bridge connected to one bridge and why it is needed. The answer to the first part of the problem has given native fee scales. Those Chinese people to not to waste copper, connected ready common points where it is necessary: ​​to the power supply and to the receiver capability. And all the rest put together so as to obtain a bridge. As a result, every factory poluplecho the fourth shoulder:

Well, okay.

The principle of measurement of weight is quite simple: the load changes the resistance strain gauges, which naturally results in a change in the way the output voltage of the bridge. Moreover, the voltage varies linearly depending on the weight. In general, all is well, if not for one thing: the output voltage of the bridge is too small to measure it directly ADC Arduino. Almighty Internet tells us that success requires a suitable amplifier - with sufficiently high gain, with sufficiently small noise.

The same online tool suggests using an operational amplifier INA125 production of the famous Texas Instruments. Many relevant circuit solutions repeat each other as a blueprint and practically do not depart from the classic circuit in the datasheet. Still, I decided to be original and chose to repeat just such a scheme :

Here R1: 39 ohms, R2: 1 k, C1: 100 nF, C2: 100 uF. For sites 1, 2, 3 and 4 connected measuring bridge, and if I have anything to understand, when you connect to the bridge specifically choose the point is not necessary, as long as V +, V-, Vref and GND went through one, that is. e., for example: Vref, V +, GND, V-. On the other hand, I then did not take risks, but simply looked notation on home plate weights, there were: E +, E-, S + and S-, and properly connected all this to an amplifier (E + = Vref, E- = GND, S + = V +, S- = V-).

It would seem that everything is clear: purchased parts - and sit payay amplifier. However, even in the DS it proved once hellishly difficult to purchase one (1) amp TI INA125, and especially - in DIP. Prices are ranging from 100 to 800 rubles, the delivery - from tomorrow until a month later, the location of offices and shops is such that even in depressed depression begins.

I was going with the forces about a month. Then he spit on everything and ordered the boutique Chip-and-Dip, but through their website. Thus saving on the seeds, if I am not mistaken, the minimum batch of 20 resistors cost almost as much as the unfortunate one resistor in the offline store. At the same time I found that SOL16 - it is much, much less there than I thought. And just like in the canopy did not unsolder.

I'm pretty upset, but still decided to look for a solution. It was found in the same boutique. This ready-handkerchiefs adapters where cockroach SOL16 suddenly rastopyrivat on site with a completely sane 2.5 mm pitch. To celebrate, I bought three pieces. What they told me - I can not imagine all the toad.

. cockroach on board

Other details, however, are wired vnaves. And foolishly wired plugs, as Arduino. I thought that I would be connected via a wall outlet, for simplicity. However, the reality turned out to be more severe, and eventually had to roll up the fork, and the entire board at all tape. There is another school of architecture: duct tape - white.

. to HLK-RM04 connected via fork (2 mm pitch). It turned out - correctly, otherwise tortured solder-otpaivat: after a while you need to disconnect from the debug module to release the controller port

Surprisingly (I'm always surprised when something out-of-work of my hands), but willing to pay, and connected to the balance, and Arduino, began to give adequate results. So now my hands were all components of the scales: scales with voltage converter and controller communication unit. So I threw the pathos and called the first alpha version of the program. As it turned out - for good reason.

. almost beta: alpha, LED on the controller board

In principle, the alpha worked good until the controller has been connected to the computer (at the time I used or Mega, or Pro Mini, but - without HLK-RM04, at the aforesaid higher due to the lack of serial ports). However, during the transition to self-powered the feeling that the whole construction has gone mad. A small investigation revealed that I was again faced with a problem familiar from the automaton light and music Asim-AU-2-6 . Namely - the constant fluctuations in the values ​​of reading pin analog controller, which I associate with pulsed nature of the power supply.

You can admire the most fluctuations dormant

 & lt; code class = & quot; cpp & quot; & gt; 17.05.2014 23:55:51 user 28 17.05.2014 23:56:03 user 21 17.05.2014 23:56:28 user 11 17.05.2014 23:56:41 user 17.05.2014 23:56:53 user 58 10 22 17.05.2014 23:57:05 user 17.05.2014 23:57:18 user 30 17.05.2014 23:57:30 user 26 17.05.2014 23:57:42 user 9 17.05.2014 23:57:55 user 17.05.2014 23:58:07 user 22 28 22 17.05.2014 23:58:20 user 17.05.2014 23:58:32 user 17.05.2014 23:58:45 user 29 13 26 17.05.2014 23:58:57 user 17.05.2014 23:59:10 user 22 17.05.2014 23:59:22 user 44 17.05.2014 23:59:34 user 17.05.2014 23:59:47 user 22 58 13 17.05.2014 23:59:59 user 18.05.2014 0:00:11 user 29 18.05.2014 0:00:24 user 14 18.05.2014 0:00:36 user 51 18.05.2014 0:00:49 user 18.05.2014 0:01:01 user 22 11 30 18.05.2014 0:01:14 user 18.05.2014 0:01:26 user 27 18.05.2014 0:01:38 user 18.05.2014 0:01:51 user 9 29 28 18.05.2014 0:02:03 user 18.05.2014 0:02:16 user 9 18.05.2014 0:02:41 user 22 18.05.2014 0:02:53 user 8 18.05.2014 0:03:06 user 18.05.2014 0:03:18 user 28 27 22 18.05.2014 0:03:30 user 18.05.2014 0:03:43 user 27 18.05.2014 0:03:55 user 18.05.2014 0:04:07 user 31 22 28 18.05.2014 0:04:20 user 18.05.2014 0:04:32 user 22 18.05.2014 0:04:45 user 10 18.05.2014 0:04:57 user 24 18.05.2014 0:05:09 user 18.05.2014 0:05:22 user 27 22 27 18.05.2014 0:05:34 user 18.05.2014 0:05:47 user 23 18.05.2014 0:05:59 user 18.05.2014 0:06:12 user 22 14 28 18.05.2014 0:06:24 user 18.05.2014 0:06:36 user 59 18.05.2014 0:06:49 user 55 18.05.2014 0:07:01 user 18.05.2014 0:07:14 user 27 58 27 18.05.2014 0:07:26 user 18.05.2014 0:07:38 user 22 18.05.2014 0:07:51 user 24 18.05.2014 0:08:03 user 18.05.2014 0:08:16 user 28 57 28 18.05.2014 0:08:28 user 18.05.2014 0:08:53 user 28 18.05.2014 0:09:05 user 28 18.05.2014 0:09:18 user 24 18.05.2014 0:09:30 user 18.05.2014 0:09:43 user 23 8 28 18.05.2014 0:09:55 user 18.05.2014 0:10:07 user 13 18.05.2014 0:10:20 user 18.05.2014 0:10:32 user 22 36 30 18.05.2014 0:10:45 user 18.05.2014 0:10:57 user 26 18.05.2014 0:11:10 user 59 18.05.2014 0:11:22 user 18.05.2014 0:11:34 user 57 29 27 18.05.2014 0:11:47 user 18.05.2014 0:11:59 user 27 18.05.2014 0:12:11 user 28 18.05.2014 0:12:24 user 18.05.2014 0:12:36 user 27 17 11 18.05.2014 0:12:49 user 18.05.2014 0:13:01 user 21 18.05.2014 0:13:14 user 53 18.05.2014 0:13:26 user 54 18.05.2014 0:13:38 user 56 & lt; / code & gt;  pre> 

Studying online showed that I was not such a happy one. One of the recommended methods of combating this effect - to pull the analog pin to the ground, use a minimum length of wire. But I had a wire no longer than 10 centimeters, and analog pin is easily seen from the scheme, had pulled to the ground. So we had to turn to a proven methodology: first, added to the program a certain weight threshold, certainly larger than the observed fluctuations. And, secondly, because the fluctuations are too noticeable, counted as the average weight sufficiently large, although not infinitely large number of measurements. More specifically, the averaged thousands of measurements that are more or less results in fluctuations (and values ​​in general) in a more or less reasonable limits.

But that was not the only problem. I'm so used to rely on someone else's scheme, which at first did not understand why the scales at some point begin to show the same value. And then it became clear that this ceiling measurements. I'm not a genius, so spent a lot of time and figuring nemudrenyh this fact, and to solve the problem.

The essence of the problem is that the gain INA125 resistor R1 is given by the formula:

Thus, according to the authors amplification circuit is set at 1500 (1542, 5, to be precise). Apparently, it was chosen for a specific instance of the balance of what I really thought. For my weights, judging by the results, it was too much. So I added another 39 ohm resistor and got a slightly different result: the gain in the region of 773.

It should be remembered that on the basis of the same datasheet INA125 , the output voltage of the amplifier is not more than 3.8 AT. Hence we obtain the maximum value of the read analog pins Arduino: (3, 8 * 1024) / 5 = 778. At this point, I also managed to attach to the balance, so found that the ratio between the weight and value of the analog Pina is about 7, 25. < br />
Summary: with the current strengthening of the theoretical limit of the scale is about 107 kg, which is more than satisfied me. But if there is something to disturb, then, perhaps, to change the resistor and pick up to the operational boundary of 150 kg. And the post-resume for the curious. Libra I calibrated weights on the other floor. It is clear that there is accuracy of plus or minus sneakers, well, the original and it is the same.

No reference weights are not used. Just three measurements on one, three measurements on the other. And the arithmetic mean of each instance divide each other. Hence, the ratio between what gets Arduino and the real weight.

One for All h4> So, I have been calibrated scales and pieces of iron that can transmit readings ... somewhere, in general, are capable of. There are very few: write a working program with a multi-mode multi-species and, if possible, more or less comfortable way of switching types and users.

The explanation is simple. I would like to receive identifiable weighing results for himself, his wife and give the guests to play without mixing them with its results. And sometimes I would like to weigh our cats, and with a minimum of effort. You know how cats are weighed, huh? You take the cat in his hands, get up on the scales, the storage weight, letting the cat again, get up on the scales. Then read of more of less.

In general, word for word, and defined two kinds (humans and cats) and eight users. So I remind, is more or less convenient control was highly desirable.

From the idea of ​​using the native LCD I refused almost immediately as read about reverse engineering the protocol to communicate with him. And on the occasion of the purchased 0.96-inch OLED-screen I could kill somewhere in the course of the experiments (perhaps he was still at 3.3V and not 5V, as promised the Chinese). Yes, and honor, I am terribly screwed up: on the photo display seemed pretty big, but in fact turned out to be tiny - with a height of growth still nothing would be seen. In addition, at the stage of testing I found that with a library and a library display WiFiRM04 do not get along. Obviously, Memory Pro Mini for them both too little.

Therefore, the withdrawal of funds remained tweeters and LEDs. Digression: Now to me rides segment LED display, which is probably bolted to the scales, but maybe not - too much I like that happened. LED I planned to show a willingness to work scales, and squeaky - voiced current status, successful sending and reading errors.

With regard to the input means, I wanted to do the absolute minimum. Just imagine: you stand on the scales and some other buttons, switches - what is it? At the same time, and did not want to be chained to your phone, if it is assumed that the desired setting is activated to a smartphone. That is, ideally, the management of my idea should be such that the middle of the night, and with closed eyes could not weigh the issues.

And then I thought, "Hey, dude, you have the same wonderful underfoot four weight sensor (well, ok, one synthetic). Why not use them as almighty button? ". Honestly: half of the individual (activity) was delighted with such an elegant solution to the problem; second half (lazy) - in deep anguish. But the idea was fascinated, and after some time of trial and error came to light following the concept of control: switching and user clicks on the table of weights and display the current status - beeps.








See also

New and interesting