Programming ESP8266 with Arduino IDE

One of the best things about ESP8266 ESP-01 WiFi modules is that they can be programmed
using popular and well known Arduino IDE and act as stand alone board with WiFi
capabilities. Thanks to ESP8266 group process of integrating ESP8266 and Arduino IDE
is pretty simple.

First step is to add to Additional Boards Manager URLs in Configuration in Arduino IDE.

Continue reading “Programming ESP8266 with Arduino IDE” »

Read More

Generate PPM signal with Arduino

In the beginning of this year I’ve written a short tutorial how to read PWM signals from RC radio with Arduino. While it is can be useful when building own RC equipment, it does not help much when one has to deal with PPM (CPPM) signal. Let’s be honest, PPM is much more useful than PWM: all RC channels are sent over single wire. On one side, it simplifies electrical design. On the other, it makes software part more “complicated”, since there is a need to encode multiple PWM channels into single PPM line in transmitter, and then decode PPM signal into multiple PWMs in receiver. And there are very little “ready and working out of the box” solutions in Arduino world.

In this short article I will show how to generate PPM (CPPM) signal using solution prepared few years ago by David Hasko. Originally it was posted of Google Code. But Google Code is not closed and who knows for how long it still will be available. So, let’s not let the knowledge got lost.

Code is relatively simple, and almost all work is done inside ISR(TIMER1_COMPA_vect) that is executed in the background by timer . Everything user has to do, is to put desired values to ppm array inside loop function. This code can generate both positive and negative signal. It can be easily ported to almost any project, as long as TIME1 is free to use.

Slightly more advanced example is available on GitHub.

Read More

How to measure battery capacity with Arduino

Battery capacity measurement can be useful in many situations. And it is not hard, only requires enough time to discharge battery completely with know resistance and a way to measure voltage in the circuit. Ohm’s law will to the rest: I = U / R

Let’s say, we want to measure standard AA 1.5V alkaline battery capacity. Why 1.5V? They are common, made by many manufacturers and sold for different prices. And not always more expensive is better. To do this, we will need:

  • AA 1.5V battery
  • resistor to discharge it. We need high current to discharge battery in reasonable time, so low resistance is suggested. On the other hand, high current means o lot of heat, so we need a resistor that can survive this. I suggest using 2.2Ohm 5W ceramic resistors.
  • Arduino to measure voltage in circuit. Any Arduino or plain ATmega or ATtiny with A/D converter will do.

So, first a simple electrical circuit:

how to measure battery capacity with arduino

And some code that will be run every second:

voltage = 5.0 * ((float) analogRead(V_METER)) / 1024.0;

float current = voltage / R_LOAD;
joules += voltage * current;
float wattHours = (joules / 3600.0) * 1000.0;

And here how it work:

  1. We need to measure voltage in circuit. This is why, in first step, we read 10bit A/D converter and scale output to 5V. Why 5V? Arduino Uno works on 5V, and it is the reference voltage here,
  2. Next, lets compute current using Ohm’s law I = U/R,
  3. With know current current we can compute work using P = U * I and store it in joules variable,
  4. Last step is to change joules to Watt hours.

If instead of Watt hours we want Ampere hours, there is no need to count joules. Instead of that, sum current and final value divide by 3600 (there are 3600 seconds in one hour). Like this:

voltage = 5.0 * ((float) analogRead(V_METER)) / 1024.0;

float current = voltage / R_LOAD;
ampereSeconds += current;
float ampereHours = ampereSeconds / 3600.0;

Full code is available here


  • this circuit allows to measure batteries with voltage up to 5V. Anything above it will damage A/D converter
  • to measure higher voltages, voltage divider will be required
  • with higher voltage, power loss on resistor will increase. It will get very hot and might burn

Read More

VirtualWire support for Raspberry Pi

FS1000A and XY-MK-5V 433MHz RF modules are very often first choice for cheap and dirty Do It Yourself wireless communication. Pair of those , allowing one way radio communication, const less than 3 dollars or euros. So they are really cheap. Limited range and transmission speed limits their real life usage, but simple assembly and extremely easy programming are additional advantage over more complex solutions. Specially in Arduino world, with VirtualWire library. I will not write about it right now, there is enough on the internet already.

FS1000A and XY-MK-5V 433MHz RF modules for Raspberry Pi

Continue reading “VirtualWire support for Raspberry Pi” »

Read More

Programming ATtiny85 and ATtiny45 with Arduino IDE

What is ATtiny

ATtiny is a fimily of microcontrollers by Atmel, the same company that provides ATmega series used widely in “real” Arduinos. Comparing to ATmega, ATtinys are much simpler, smaller (usually), with less features. But also cheaper, easier to connect, using less energy, and trust me, in many many cases you do not need 32kB of flash memory. If, for example, you want to build a device that will beep every 10 minutes which microcontroller would you use: huge DIP-28 ATmega328P from Arduino UNO R3 or small DIP-8 ATtiny25 that ususes way less power and costs around 1EUR? I would use ATtiny.

ATtiny85 as light sensor with I2C bus

There are many microcontrollers in ATtiny family. In this tutorial and all future in this series I will concentrate on ATtiny85 with 8kB of flash memory. There are 2 simpler versions of it: ATtiny25 and ATtiny45 with respectively 2kB and 4kB of flash, but price difference between them is so small, that I see no point of trying to use them. When buoght from China, it might be even possible to buy ATtiny85 cheaper than its smaller brothers. Continue reading “Programming ATtiny85 and ATtiny45 with Arduino IDE” »

Read More

Read RC PWM signal with Arduino

Arduinos are cheap and simple development board. You can do a lot with even the simplest of them. For example build you own quadcopter and flight controller (after all MultiWii = Arduino + MPU6050). Of course, this is not as simple as one might imagine and there are few (actually a lot) obstacles that needs to be overcomed. One of them, and very basic, is how to read RC PWM signal provided by radio receiver.

Signal to decode

RC PWM signal passed from radio receiver to servos, ESC, flight controllers is encoded with a length of pulse. Pulse length of 1000us (micro seconds) is minimum stick position and pulse of 2000us length is maximum stick position. Pulses repeat every 20ms for standard 50Hz refresh rate. Like this:

RC PWM Signal

So far, nothing fancy. Continue reading “Read RC PWM signal with Arduino” »

Read More

Note on Arduino Uno servo jitter

Yesterday I discovered very nasty feature of Arduino Uno (and all other AVR ATMega328 boards) when using servos. Although official Servo library states that it can support up to 12 servos on Arduino Uno (more on advanced boards as Mega), it does not say much about quality of PWM signal.

Since all connected servos (in case of Arduino Uno/ATMega328) are driven using the same timer (timer1), the more servos are connected, the more jitter is introduced to PWM signal. Control “window” of each servo starts to overlap. This results in a situation when real pulse width jumps up and down, sometimes even outside allowed values.

My experiments says that Servo library can support up to 3 servos per 16 bit timer with acceptable jitter level to use as RC control signal. Specially when PWM signal is fed to flight controller. With 3 channels signal quality was acceptable after enabling input filtering on Cleanflight. 2 PWM/Servo channels did not required input filtering.

4 or more PWM channels can be used when real servos, not flight controller inputs, are used. Servo inertia “solves” issue of signal jitter.

Read More

Using transistors as switches

I think all popular computerized DIY devices like Arduino, Raspberry Pi or any other microprocessor/microcontroller based boards has one common drawback: low output current. Few miliamps per pin. While this is enough to light a single LED or provide input to other electronics device, it is far from enough to run a motor or power a LED strip. It’s all about current.

Good thing this problem can be solved with two additional devices: resistor and bipolar transistor. Together they can act as a switch. Idea is simple: low current (and voltage if you wish) applied to transistor base causes bigger current (and voltage) to be passed between collector and emmiter. We have two choices: NPN or PNP bipolar transistor. Switch that uses NPN transistor is open/enabled when positive voltage is applied to base. In other words, base is connected to plus.

NPN transistor as switch Continue reading “Using transistors as switches” »

Read More

How to flash MW OSD to Micro MinimOSD

While playing with newly arrived Micro MinimOSD and attempting to flash it with latest MW OSD software, I’ve discovered that offical tutorial, as well as many other are missing one tiny detail that makes whole process much harder than expected. In theory, MinimOSD just Arduino Pro Mini with additional hardware. So, in theory, you plug in your FTDI USB adapter and upload a sketch. But if you never worked with Arduino Pro Mini (like me, it was always Uno, Pro Micro, or barebone Atmega328) you might not know one detail. Yesterday it took me more than 30 minutes to figure out firmware upload is not working, while it should. So, another tutorial will be written.

Micro MinimOSD with soldered pins

Micro MinimOSD pinout


To flash MW OSD to Micro MinimOSD we will need:

Continue reading “How to flash MW OSD to Micro MinimOSD” »

Read More

Simple servo tester with Arduino

Servo tester is a useful little device that is needed specially when you do not have one. I’ve been placed in a situation like that few days ago what I was trying to connect ailerons with servos on my Depron plane and setup correct control throw. Luckily, I own a few Arduinos,  so 15 minutes later I owned a divice like that:

Servo tester with Arduino

It is an extremely simple servo tester based on Arduino Pro Micoro that can send 3 different PWM pulse lengths: 1000us, 1500us and 2000us. That gives min, neutral and max stick position on RC radios. Perfect to setup control throws and neutral positions.

Required parts:

  • Arduino. Any Arduino will do. I used Arduino Pro Micro, but any can be used. Even barebone ATmega328 running internal oscillator on 8MHz,
  • Breadboard,
  • Tact switch,
  • Some golpins to make servo connector,
  • Cables.

Electrical diagram goes as follows:

Arduino servo tester diagram

Program is also not complicated:

And at the end, it works like that:

Source code is available on GitHub.

Read More