Arduino, ESP32 and 3 hardware serial ports

When working with ESP32 WiFi/Bluetooth MCU under Arduino SDK for ESP32, you will notice that Serial work just fine. But Serial1 and Serial2 do not. ESP32 has 3 hardware UARTs that can be mapped to almost any pin. But, Serial1 and Serial2 will not work. In case of ESP32 this just has to be done in a slightly different way:

The trick is to use HardwareSerial library to access UART 1 and 2 instead of Serial1 and Serial2

  • Class HardwareSerial accepts one parameter in constructor, it is a number of UART. Values from 0 (UART 1) to 2 (UART 3)
  • HardwareSerial(0) is the same as Serial so be aware
  • begin method accepts 4 parameters
    • baud speed
    • UART mode
    • RX pin
    • TX pin

The real beauty of this solution is that almost any pin can be used as TX or RX pin for any UART. Most ESP32 dev boards have labels like TX2 or RX2, but you really do not have to exactly those pins. Every other GPIO pin can act as Serial RX, but only the ones between GPIO0 and GPIO31 can be used as TX. Still, that gives plenty of pins to choose from…

Read More

DIY RC radio link: the problem of protocols

So, you want to build your own RC radio system? Long range maybe? Cool, I want to do it too. Since I'm pretty deep in that topic now, I can give you a hint or two. For example, have you thought about a protocol your radio system will implement?

RC link simplified

Or rather should I say: protocols? Why plural? If you want to do a RC link that talks with popular radios like FrSky Taranis on TX side and servos or flight controllers on the RX side, it will have to implement at least 2 different protocols. More likely 3. And if you will want to add telemetry downlink, 4 or even 5…

Continue reading “DIY RC radio link: the problem of protocols” »

Read More

Generate S.Bus with Arduino in a simple way

Did you noticed that lately I write about radios quite often? Well, I do and it's not a coincidence. Proper introduction for what I'm working on will happen in a next few days, but now I will only write that this will be a mid-range, cheap, DIY radio link for UAVs. By mid-range I mean up to 5km. So, it will be positioned somewhere between 2.4GHz systems and full sale LRSes like DragonLink or TBS Crossfire.

Back to business. I've discovered, that there is very little in The Internet how to generate S.Bus with Arduino. OK, there are few libraries for reading Futaba S.Bus protocol like mikeshub/FUTABA_SBUS or zendes/SBUS but the only library made simple I've found is bolderflight/SBUS. Too bad it works only with Teensy devices. So, after a few hours of hard work, reading code of OpenTX, MultiWii, INAV, reading RcGroups and final help of Konstantin Sharlaimov (Digital Entity of INAV), I give you:

Generate S.Bus packets with Arduino in a simple way

But first, few simple facts:

Continue reading “Generate S.Bus with Arduino in a simple way” »

Read More

E45-TTL-100 not transmitting when connected to Arduino

While working on one of my project involving Arduino and E45-TTL-100 LoRa 868MHz radio modules, I've discovered that it is not working exactly like expected. Documentation states:

(…) When the data inputted by user is up to 58 byte, the module will start wireless transmission (…)
(…) When the required transmission bytes is less than 58 byte, the module will wait 3-byte time and treat it as data termination (…)

If I understand this correctly, E45-TTL-100 should begin radio transmission when:

  • 58 bytes were sent via serial port
  • serial transmission stopped for 3 bytes. So, at 9600bps, 3ms pause whould trigger transmission
void loop() {
    Serial.print("Test");
    delay(100);
}

In theory, code from the able should send string "Test" every 100ms. Unfortunately, it was not happening. Second E45-TTL-100 was not receiving anything. Also SDR dongle was not catching any transmissions. Something was wrong. I even contacted CD Ebyte, but they were unable to help me and The Internet was equally useless. What was wrong? No idea… looks like some kind of E45-TTL-100 MCU bug…

The solution

The solution is, hmmm, surprisingly simple. You not only have to stop transmitting, but also end serial port (Serial.end()) and open it again (Serial.begin()) after short period of time. In my experiments I've determined that 20-30ms of closed port selves the problem. So, code from above should be replaced with following:

void loop() {
    Serial.print("Test");
    Serial.end();
    delay(30);
    Serial.begin(9600);
    delay(70); //The rest of requested delay. So 100 - 30 = 70
}

It might not be the prettiest solution ever, but it works.

Read More

FC Soft Mount With Adhesive Pads FTW!

I will not try to proof if you should soft mount a flight controller on a racing drone. I will only say, that few months ago I was against it, but lately I changed my mind. Stronger motors, stronger magnets, more torque, more speed and out of nowhere, incredible amount of noise can be fed into gyro signal. Sure, this is not required, but motors, ESCs and battery will thank you when you soft mount flight controller. Less, noise, less restrictive filtering required, lower signal delay, better flight performance.

In most places over internet you can find either a rubber standoff or double sided tape solution. Sure, that works, but there is something better. Dedicated, double sided adhesive, vibration dampening pads. There are many sources, and many names. I'm using Sekisui brand. Check ebay, Amazon, HobbyKing. Look for gyro pads, vibration pads, vibration dampening. I do not want to advertise any particular seller, so you are on your own here.

Sekisui adhesive gyro pads

Continue reading “FC Soft Mount With Adhesive Pads FTW!” »

Read More

Working solution for USBasp driver in Windows 10 64bit

Yesterday I've spent like 2 hours fighting to make USBasp ISP programmer work under Windows 10 64bit. Seriously, that was like some kind of nightmare that turned into a comedy. All web pages that I've found suggested following procedure:

  1. Download zadig
  2. Install libusb-win32
  3. Be happy

Unfortunately, in my case all attempts failed miserably. All I was getting from avrdude was

avrdude: error: programm enable: target doesn't answer. 1 
avrdude: initialization failed, rc=-1

I've found a solution. Internet was wrong. libusb-win32 was not the correct driver for USBasp. The correct driver was libusbK (v3.0.7.0). After installing libusbK USBasp came back to life!

usbasp driver for Windows 10 64bit

Read More

The best GPS module for INAV

This is my personal best GPS module for INAV: Beitian BN-880 based on Ublox Neo-M8N. Currently I have 3 pieces of BN-880, all works just great, and if I will have a need to have another one, I would also choose it.

Why? It really works well. On the outside it gets a solid 3D fix in less than a minute. It even can get a fix with 9-10 sats in a center of a city when only a small piece of sky is visible simply by lying on a windowsill. It take time, but works.

Beitian BN-880 - best GPS module for INAV?

Continue reading “The best GPS module for INAV” »

Read More

How to print with elastic filament

Elastic filaments opened brand new areas for 3D printing. We are finally able to print something that bends, compresses and stretches. While TPE (ThermoPlastic Elastomer) filaments like NinjaFlex or FlexiSmart are still about 4 times more expensive than plain old PLA, they are not so expensive not to give them a try.

Unfortunately, due to the fact that they are elastic even before melted and extruded, they require special printing conditions. During my experiments with FlexiSmart I've came down to following conclusions:

  1. Because TPE is elastic, flow through the nozzle has to be as smooth as possible. If not, it will coil inside extruder
  2. Bowden extruder system greatly increases chance of failure. Friction of bowden, while small enough for ABS or PLA, is too big for TPE. Filament will coil. Direct extruder gives less chance of failure
  3. One has to pay big attention to the distance between extruder nozzle and bed. Usually it has to be a litter bigger that for PLA or ABS. In all the cases when I was switching from PLA to TPE, I had to raise nozzle a little. If not, TPE coiled. TPE has better initial adhesion than PLA, so rising a nozzle does not have side effects
  4. Filament retraction is a huge NO NO. Disable retraction since it will increase the chance of coiling significantly
  5. With no retraction it is a good idea to enable Combing. Nozzle, instead of taking the shortest route to travel, dripping TPE everywhere, will move above already printed layer. This greatly improves print quality
  6. Top printing speed is 30mm/s, but I recommend slower speeds. I have best results when printing at 15mm/s. On 25mm/s quality is still acceptable, but degradation starts to be visible
  7. I had best results of TPE printing on glass with 220deg nozzle temperature and 60deg bed temperature
  8. Not everything can be printed with elastic filament. Any thin vertical structure will come deformed. After all, it will move during printing due to a friction with extruder nozzle

While I was printing with FlexiSmart, almost all points from the above list will be true for other TPE (NinjaFlex). Temperatures might be slightly different, but general rules applies.

Read More

Simplest hardware inverter for flight controller

Together with increasing popularity of STM32F4 flight controllers, telemetry became hard topic again. Why? Most popular telemetry protocols, SmartPort and FrSky telemetry , requires inverted signal. Zero becomes one, one becomes zero.

In case on STM32F3 that was not a big problem. Those CPUs have built in inverters. STM32F1 and STM32F4 does not. So, if flight controller designer did not put external inverters on UART ports, FrSky telemetry, SmartPort and even S.Bus would not work.

Luckily, simple inverter for FrSky telemetry and S.Bus can be build using only few electronic parts:

  • Small logic level N-channel MOSFET transistor. One of the best choices is 2N7000
  • 10kOhm resistor
  • few cables

Continue reading “Simplest hardware inverter for flight controller” »

Read More

Flip32 F4 and Airbot F4 Software Serial

When STM32F4 based flight controllers made its way to the world of MultiWii derivatives (Cleanflight and whole family), all I think all developers assumed that SoftwareSerial feature will not be needed on those boards. Why it should be? STM32F4 has enough hardware UARTs to satisfy everyones needs.

Unfortunately, live had it’s own point of view on that topic:

  1. Most F4 flight controllers have only 2 to 3 hardware UARTs available and usually one of them is shared with I2C (Revolution, Airbot F4)
  2. STM32F4 does not have internal hardware inverters. Hardware manufacturers usually put only one external inverter for S.Bus and that’s all

Because of that, Software Serial feature is coming back to F4 boards. Together with INAV 1.5, SoftSerial will be available on Airbot F4 / Flip32 F4 target on two small pads located near UART3 connector. RX line on pad CH5, TX line on CH6 line. Pads are quite small, but with basic soldering skills and decent soldering iron there should be no problems to solder thin cables to them.

Since F4 CPU is much more powerful than F1, limitation of 19200bps on Software Serial UARTs is no longer actual. I have tested 57600bps and 115200bps should be archivable.

Read More