Testing the WiFi range of ESP32

I have a project, which requires long distance (approximately 1 km) communication, in my mind. Recently I got super excited about ESP32, so I thought why not to use it. After all, CNLorh has shown us that ESP8266 has a surprising range – over a kilometer.

I wrote a simple program for two ESP32s using PlatformIO and the Arduino framework (as working with wifi in ESP-IDF is kinda hell). Here you can find code for the master device, and here for the slave. Basically, Master setups AP, slave connects and the master sends UDP packets. If the slave receives a packet, it toggles an LED. That’s it.

The MH-ET LIVE module
The MH-ET LIVE module

The first test was unsuccessful. I took two MH-ET LIVE D1 modules and went outside. When I went around a corner of 4 storey building, the connection was lost. Sight-to-sight I was able to communicate on 150 meters.

Then I found out ESP32 supports the WiFi LR protocol. By using this protocol it should be possible to sacrifice communication speed and gain increased the range. This protocol can be easily enabled by calling the following function after the WiFi peripheral has started:

esp_wifi_set_protocol( WIFI_IF_AP, WIFI_PROTOCOL_LR )
esp_wifi_set_protocol( WIFI_IF_STA, WIFI_PROTOCOL_LR )

I did a second test. I could walk around the building and the communication was perfect. I didn’t observe a single glitch. Sight to sight I was able to communicate up to 200 meter. If I put the master roughly 2 meters above the ground, I could get 240 meters. Improvement, but not significant. However the reliability of the connection drastically improved with the LR procol. The connection was much better, however it was still rather a disappointment.

As a last resort I tried different hardware – I tried to cut PCB under antenna on the MH_ET LIVE D1 modules and I also tried to use the original ESP32 DevKit-C modules. I got roughly the same results. No improvement.

The MH-ET LIVE module after modification
The MH-ET LIVE module after modification

The last thing left to do was to make the same test with an access points instead one of the ESP32s. I used TP-LINK TL-WR741n. Guess what – no improvement. I got exactly the same results.

To conclude – even ESP32 is a great chip, I am not going to use it for long-range communication. I am aware, that my experiment does not feature controlled environment and a fancy setup. However, this is all I got time for. Have you done some range tests on your own? What are you results? Please, share in the comments or send me an email.

Rotational encoders on the cheap – the capacitive way

Rotational encoders are definitely a must-have even in hobby robotics. When you want an encoder in your project, you have many options:

  • traditional optical encoders (IRCs) – precise, fast, not so cheap and big
  • “ball-mouse like” optical encoders – cheap, fast, reasonably big, poor resolution
  • magnetic encoders – small, wonderful resolution, not so fast and expensive
  • etc.

With two projects in my mind (one really up budget, the second one requiring really small and really fast (>100kHz) encoders) I thought: why not to build a capacitive encoder? Basically a variable capacitor whose capacitance determines the position. It could be cheap (etched on a PCB) and really fast. So I decided to explore possibilities of this approach.

Overview

As usual, I started with an overview of existing solutions. Surprisingly, it is hard to find any reasonable resources. I found only two types of existing projects – professional solutions without any documentation for scientific purposes and a really nasty hobby projects which are far-far away from any reasonable results. There was only one exception – Elm Chan’s laser projector, which uses a capacitive encoder for galvanometer feedback.

In his project, he uses a diode bridge and a high frequency AC voltage (>8 MHz) to measure a capacity difference of two capacitors. The circuit should produce a small voltage on a output proportional to the difference. However, I wasn’t able to reproduce his results. My circuit produced a lot of noise and was practically useless. Clearly I am not an analog guy. So I decided to do it in more digital way.

First prototype

The idea is simple – I create a plate capacitor with half-circle electrodes by etching a pattern on main PCB and on a small PCB carried by motor shaft. Then I use the 555 timer in an astable configuration with the plate capacitor for timing. The circuit will produce a square-wave signal with a period proportional to the overlap of the electrodes and therefore, proportional to the shaft position. The frequency can be measured using a timer on a MCU in the input-capture mode. Simple, right?

First prototype of capacitive encoder

After designing a simple PCB, I etched it and populated it. To protect the electrodes from a short and also to create as small spacing as possible (to increase capacity) I covered one of the electrodes with a transparent tape. The diameter of the semicircles is 15 mm (and therefore the active area is roughly 88 mm2. Based on resistor values I used, and the frequency I obtained, the capacity of this capacitor is about 8 pF – 5 times more then I expected (the tape is probably a better dielectric then I expected).

The first tests looked promising – I was able to measure a position, however the whole system was quite noisy and especially sensitive to touch – and mechanical stress. This is probably due to movement of the plates – event they lie on a the tape, if you squeeze them a little, they move closer together and it leads to big increase in the capacity. I also think this setup is quite sensitive to air humidity and temperature. Also it does not allow for continuous rotation because of the wire connecting one electrode to the main PCB. I was thinking about connecting the the other electrode via the motor shaft and the motor case, however, one of my friends had a nice idea (thanks Jiří).

Second prototype

The idea behind second prototype is quite simple – do not move the electrodes, move with a semi-circle of a good dielectric material between two fixed plates. The electrodes are fixed and therefore it is easier to maintain a fixed distance between them. Also, even if the dielectric semicircle does not maintain a constant distance from the electrodes, it makes no difference as the ratio of air and dielectric is the same (and that’s what affects the capacity). For the material I used FR-4 – it is easy to get and has 4 times bigger dielectric constant than air.

Second prototype
Second prototype

I also tried to make two electrodes for the second prototype to get rid of humidity and temperature dependency – I wanted to measure a capacity difference by measuring two capacities and making the compensation in MCU. However it wasn’t a good idea to put the two 555 timers on the other sides of PCB. Even with a decent battery of capacitors, they interfered in their function and produced an instability in the oscillation.

The other side of PCB with a ground plane and without the second 555 timer

When I got rid of one of the second timer and also introduced a ground plane on the other side of the circular electrodes I was surprised with results. To test the capacitor I used ESP32 with a motor control timer in the input capture mode. This timer’s clock tick at 80 MHz and feature a 32 bit counter. First, I arranged the resistors of the 555 timer to get a frequency around 100 kHz (I was aming for really fast encoders). With this setup, the timer makes roughly 800 ticks per period. As the capacitor still has a capacity even when there is no dielectric, the low period was 720 tics and the high period was 860 period – i.e. I got resolution of 140 positions. When the encoder is stable, there is a surprisingly small noise – only +-1 tick. Also I let the encoder run for over two hours and there was no drift in the position. You might think – 140 positions isn’t much, but I can read it at 100 kHz! When I lower the frequency (or if I could get the timers in ESP32 to tick faster) I am able to increase the resolution. So basically it is a trade off between speed and resolution.

What about continuous rotation?

If you read carefully and think a little, there is one small glitch in my setup – I am only able to detect position in the range 0-180° and no more. If I continue the movement above this range, I am not able to tell if I continue or if I am returning back as the capacity decreases the same way on the both sides. There is however a simple solution, which I unfortunately haven’t tested yet.

Electrode pattern

You need two electrodes A and B and a dielectric disk taking 2/3 of the full circle (semi transparent in the image). In this configuration you can always tell in which direction you move.

Conclusion

I would call my work as “proof-of-concept”. I think ultra fast capacitive encoders are feasible if you can measure period fast enough or you make Elm Chan’s circuit to work and use ADC instead. The capacitive encoder can be also a dirty-cheap solution – you need only a space on PCB, two 555 timer, 4 resistors and 4 capacitors. As the capacity of my plate capacitor is roughly 10 pF I think you could reduce its size 2 or 3 times and still get reliable results so not much of a space is necessary.

But always remember – time is money and an “expensive” solution in a form of a magnetic encoder IC might be in the end the cheapest solution.

Thinking about BOMs and Component Management

Let’s start with a disclaimer: I am a hobbyist. I do electronics mainly for fun, occasionally for serious business. All my thoughts are related to the context of single-person hobbyist (such as me) or a small group of hobbyist/semi-professionals such as RobotikaBrno. What I state here, might not be useful for the professionals.

Recent experience with Kitnic made me think again about component management in my projects – choosing, buying, storing and using electronic components. Before I present my idea, let me briefly describe my workflow.

My Current Workflow

Let’s start in the middle; as you could read in my previous posts I store my components in following manner:

  • I have a basic set of 0603, 0805 and 1206 resistors and capacitors in a special boxes (roughly 50 pieces per value).
  • ICs like MCUs and various sensor are stored in a grid of small boxes with labels.
  • Boards, china modules, etc. are stored in several paper boxes.
  • All the other components are in plastic bags with a hand-written label. These bags are kept in groups like transistors, diodes, LEDs, etc…

I also think it a good idea to have some parts on stock. I think everyone is familiar with the situation, when you are making a quick fix and you miss the resistor of the proper value. Ordering a component is time consuming (it takes few days to arrive) and costly (there are the shipping costs).

When I design a board I usually draw a schematics with respect to BOM and my home supplies. That means for example, if a value of a resistor is not critical, I try to match it to one of the values I already have in stock. But I do it only based on what I remember as going through the bags is time consuming. This also works only for my current stock, the stock might be different in a year.

I don’t use BOMs with precise order codes as I am a hobbyist, who populates boards manually and make only 1-5 pcs of a board. I have to care about minimal order quantity and I wonder why are there such a big price differences in practically identical components. When I need to order a component, I generate the BOM for several projects and go through the supplier website finding a component to match my needs with respect to price. I also try to match the components between projects. I don’t care much if I receive my components in reel, tape or a bag (precise order code usually forces me to buy a given packing, which can be in low quantities expensive). The process of ordering components is slow and annoying.

Also there is always a problem to decide what to order and what not to order. I usually base my decisions on my poor memory – I often don’t remember exact quantities I have on stock (and I am lazy to go through it). Therefore I rarely miss a component and usually order something I already have on stock. Also sometimes I order components for a project, which is for some reason left unfinished. Therefore my stock is constantly growing and contains components I will never use again (in my current workflow).

To sum it up – it is a little bit messy. From my experience, I am not the only one having this issue. Even some small companies have it.

What Would Make My Life Easier?

All these problems boil down to common source – component specification. When you use a component in a schematics, you should specify it. People use two methods:

  • They supply the part value (resistance, capacity, voltage etc.) and sometimes they add other criteria (e.g. power rating of a resistor).
  • Or they supply precise part name or event an order code for a supplier of their selection.

The second method might work for large companies producing thousands of boards – it is easy to order the components and the designer has everything about the components under control. It is also a good way to go with ICs and special components on hobbyist boards. However, when it comes to passives as resistors, capacitors, coils, etc., it does not work well for the hobbyist. If you specify the order code, then it is hard to use your stock supplies. If you decide to stick with a single type of your resistors or capacitors for the stock, it can get quite pricy, as you cannot buy the cheaper alternative. Also if you decide to build a board designed by someone else, you either have to match you stock supply with the order codes on the board or order components specifically for the board.

Let’s take it to the extremes to illustrate my point; when I have a small toy board, I don’t care whether a pull-up resistor is 10k or 12k. I want to specify it to be in range 8k-15k, in 0603 package and power rating greater than 0.05W. Nothing else, like manufacturer, height of the package doesn’t bother me. And any component fulfilling this specification will work for me. The same with capacitors – I usually need a given capacity, least voltage rating, package and min/max ESR and nothing else (like dielectric material) doesn’t bother me a lot in many cases.

The previous paragraph was rather extreme. Usually what I aim for is to make following step easy and repeatable for different settings: “I need an order code for the cheapest resistor with this value, at least this power ratig and with a tolerance at least 5%”. And ideally make the procedure automated based on schematics and allow for merging of BOMs and their simplification (e.g. I can replace 5% resistors with 1% resistors).

Let’s be honest – I think many hobbyist does exactly the same thing when order components for their designs. They do this matching by hand. And it can be a source of bugs as the specification isn’t written anywhere – especially if you are not the author of the board and you don’t know what parameters are critical. Well, it is usually enough that you order for a board designed a year ago.

Therefore I would like to keep track of this specification in schematics. I would like to attach attributes with the specification in KiCAD; like “resistance > 10k && resistance < 12k", "package ~= (0402|0603)". Then I could use an automated tool, leveraging for example Octopart, to find a part matching my criteria. Of course, if something needs to be precise, I put precise specification for the component.

Having this option would also motivate me to store my components in bags/boxes with a sequential numbers and the precise part name and keep an electronic track of my components. Then I could just export this “smart BOM”, verify it against my database and find out, that I should use 100n capacitors from bag nr. 42 and the remaining two capacitors can be taken from a bag nr. 87 (as they probably differ in voltage rating, but I don’t have enough of the first variant). This would force me to reuse most of my stock material and I would by only the necessary things.

It would also ease the situation when I need to find an alternative for a component as I miss one component and I prefer to buy it from a local seller to save time. But the seller does not have the precise component. Given the specification, I know which parameters of the component are crucial, and which not as much. The same case is the situation when I want to build someone else’s board and use as much stock material, as possible.

The Tools

I am not aware any of any ECAD program out there, which would support such a specification of components. Is there something out there I miss? Even a third party service I am not aware of? Do you see any flaws in the component parameter specification? If so, please let me know!

For me the outcome is: This can be easily added to existing tools like KiCAD and Eagle – both of them support attributes. What is needed is a format of these attributes to specify the constraints. Then we can easily build tools on top of it, which will make our life easier.

Morse Thing

Let’s start with a disclaimer: This is a one afternoon project, without a lot of planning, made only from home-available supplies.

As I wrote in the previous article, I organized a night game for K-SCUK 2016 few weeks ago. The message of the game was clear — nothing complicated, just “wow”. To accomplish this task, I wanted a stage with technical gadget. The idea of the Morse Thing was born.

The Morse Thing
The Morse Thing

Continue reading “Morse Thing”

Navigation Thing

Let’s start with a disclaimer: This is a 4-day project, without a lot of planning, made only from home-available supplies.

I’ve been helping to hold K-SCUK (a week long outdoor seminar for high school students interested in informatics and biology) for few years now. This year was no exception. I was put in charge of the night game, which was supposed to uncover some information about K-SCUK background story. I decided to go for a simple game with “wow effect” instead of a game with sophisticated rules and deeper message. I wanted a simple and enjoyable experience for the contestants. To accomplish that, we prepared linear route in a forest with several stops featuring a simple task (a cipher for example). This alone wouldn’t be enough to provide a memorable “wow” experience.

The NavigationThing
The NavigationThing

Continue reading “Navigation Thing”

The New Way of Storing and Organizing SMD Components

In my previous article I briefly showed the way I store and organize my SMD components. Even it is way better than storing parts in labeled plastic bags, in which the parts are usually shipped, it is still far away from being perfect. I was already looking for a better solution for a six months or so, when I finally found two products, which seemed like a possible solution – Aidetek Box-All Cases and WenTai Boxes.

My SMD Collection
My SMD Collection

Continue reading “The New Way of Storing and Organizing SMD Components”

Face the Fail: Piezo or Not to Piezo?

In the last week I’ve been working on a device, which uses an electronic compass. I chose HMC5983, so no rocket science happening – I used the recommended layout, made a prototype PCB, populated it and wrote the firmware. Everything went smoothly on the first try.

Then I adjusted position of the components on the board, repositioned few wires and made a batch of 6 new PCB. After I populated them, the compass stopped working – the X axis showed fixed value, the other one were working properly. Strange, right? If it was one board, I would thought about damaged component. But all 6 boards featured the same behavior. After two hours I finally localized the cause of the troubles – a piezo buzzer. At least I thought it was a piezo buzzer.

My board uses a pizeo to notify the user via beeping. I used the standard 12 mm piezo in a plastic housing:

A standard 12 mm piezo buzzer
A standard 12 mm piezo buzzer

Continue reading “Face the Fail: Piezo or Not to Piezo?”

How Do You Store Your SMD Components?

I use SMD components in my projects whenever it is possible. I like when things are compact, look professional and also I hate drilling PCBs. Also many modern components aren’t available in other packages. However with bright sides of SMD components comes the dark side — the storage.

You need several hundreds type of components to do something meaningful. The components are small, come in similar packages usually with no labeling (capacitors, inductors, SOT, QFN — all of them have no, or at least not fully descriptive label). Putting them in a one large bag isn’t a good idea. Once you loose track what kind of component is it, you can throw it out. Sometimes it can be measured, but usually the time doesn’t worth the money.

I used to keep my components in the original carrier tape, usually with a handwritten label. All the tapes were in several plastic bags. After my collection of components grew up a little bit, this kind of storage was unusable. Lookup a component of a particular type was time consuming, reading small, often blurred hand-written labels, was a pain. Maybe you know it by yourself.

Continue reading “How Do You Store Your SMD Components?”

Cheap Minimal ESP8266 ESP-7/812 Breakout Board

ESP-12 modules are great for integration to custom product as they fit nice on a PCB. However the prototyping process can be painful due to the incompatibility with standard 2.5 mm pin headers. You can use a full development board like NodeMCU with all its imperfections (size, high current consumption1 compared to ESP sleep states, mismatched pin names 2, etc.) or you can take a soldering iron, wire and do all the necessary wiring as a “3D post-modern artistic piece from a copper wire”. To remind; ESP8266 requires several GPIO pins to be pulled-up or pulled-down in order to boot from flash memory or to enter a bootloder (see ESP8266 Wiki for details), so a little bit of wiring is unavoidable. In some cases you might want to attach a voltage regulator.

Continue reading “Cheap Minimal ESP8266 ESP-7/812 Breakout Board”