Member-only story

How to Write your own Flight Controller Software — Part 2

A Diversion down Hardware Lane

--

Before proceeding with the flight controller software, we need to sort out a couple of hardware issues. These are, controlling a buzzer (i.e. a passive piezo) and understanding remote control inputs via SBUS.

Figure 1. 3–30V Passive Piezo.

The Buzzer Issue

Why can’t we just connect a piezo to a pin on our Nano and use PWM to create a tone? I’m glad you asked! The biggest problem is current limits on the I/O pins. If you have a look at the pinout information for the Nano 33 IoT, you will see that the maximum current per pin is 7mA. For the Nano 33 BLE, maximum output current is 15 mA, maximum input current is 5 mA and the maximum total current for the MCU and all GPIO’s is 25 mA.

We have selected the PS1440P02BT Piezo (Figure 1) as our noise maker. The data sheet doesn’t provide the current rating for the piezo, possibly because it varies with the voltage used. For 3.3V, the typical maximum current drawn for these devices is 9–14 mA, which is too much for our Nano. Thus we need to drive it via a transistor. Our buzzer driver circuit is shown in Figure 2.

Figure 2. Piezo Driver Circuit.

The piezo acts a bit like a capacitor, so we need to place a 1K resistor in parallel with it, to allow it to discharge. Without this, the volume is barely audible at 3.3V. The transistor is a common PNP BC327, which we are using as a switch. When the base emitter voltage, VBE > 0.6V the transistor turns on (saturation), and when VBE < 0.6V the transistor turns off (cutoff). In our schematic, pin 1 is the emitter and pin 2 is the base, thus VE = 3.3V.

This transistor can handle up to 800 mA of collector current (pin 3), which is heaps for our purposes. We can check this by doing some simple calculations.

If the piezo draws a worst case of 14mA, it has an equivalent DC resistance of:

RP = 3.3 / 0.014 = 236 Ω

Our total transistor resistance (RL) is RP in parallel with R8 = 191 ohms. Thus our collector current will be:

IC = VCC / RL = 3.3 / 191 = 17.3 mA…

--

--

David Such
David Such

Written by David Such

Reefwing Software · Embedded Systems Engineer · iOS & AI Development · Robotics · Drones · Arduino · Raspberry Pi · Flight Control

Responses (1)