PWM overview

PWM signal is a square wave, which is used in electronic control system to control such things as steering gear position, motor speed and LED brightness. It is based on two important parameters: frequency and duty cycle. Frequency is the number of repetitions of the waveform in one second. The duty cycle represents the percentage of time that the signal is high and low. The average value of the waveform obtained determines the amount of power transmitted to the load.

Raspberry PI and Arduino raspberry PI are credit card sized microcomputers

, partly because of its computing power, size and price. Raspberry Pi is based on Broadcom bcm2835 embedded multimedia application processor. It is equipped with multiple connection ports, which can be easily operated by plugging in a TV or monitor and a USB keyboard. It is also compatible with many operating systems; However, raspbian, a Linux version tailored to raspberry PI, is one of the most commonly used operating systems.

Arduino is a platform based on single board microcontroller, which can provide simple and quick access to embedded electronic design for inexperienced and experienced users. It is an open source hardware design that provides analog-to-digital signal conversion, input and output control, and PWM signal generation. Arduinos also offers a wide range of connectivity options through its on-board i/o connections and available expansion boards.

poYBAGKn-x2AXGuVAAFdOcg6Spo008. png

PWM on raspberry PI: limited control capability

Considering a task involving building a robot car, you need to control two motors through the raspberry PI, which has 26 general purpose input / output (GPIO) pins. Among these pins, there is only one easily accessible PWM output pin, which is not enough to drive anything requiring more control, not just the on / off function. The servo motor and RGB LED cannot be driven separately through this pin.

Strategies to enhance the PWM function of raspberry pi

Many solutions have been proposed to overcome this limitation of raspberry PI. Many people use accessories that support I2C (internal integrated circuit) or SPI (serial peripheral interface) for this purpose. These devices are controlled by raspberry PI and generate PWM signals for control purposes. The PWM generator accessory can also be used to add PWM enabled output pins to the raspberry PI.

Another method being used is to perform software PWM on other pins that support GPIO. The wiringpi library is an example library that allows this type of control. It uses a real-time scheduler to preferentially generate PWM signals by running various threads, but because the operating system used on the raspberry PI performs multitasking, this solution is not suitable because it provides low timing resolution and high jitter.

Arduino: the right solution

Solution one solution to easily develop PWM signals is to use the Arduino development kit. The Arduino board is available in a variety of configurations. For example, the Arduino due has 54 digital pins (12 of which can be used for PWM output) and 14 analog pins. With so many configurable i/o pins, the Arduino due and generic Arduino boards are ideal for external sensing and control boards that interface with the raspberry PI.

poYBAGKn-xeARYCVAANUCCad2v4371. png

Connecting Arduino and raspberry PI via USB

Solutions with powerful PWM functions and highly configurable user interfaces can be found by matching the raspberry PI and Arduino platforms. The Arduino based development board can be connected with the raspberry pi to add PC functions, network communication and multimedia tools, the ability to interact with the environment through the use of microcontrollers, and the portability of mobile devices. As mentioned earlier, arduinos is a microcontroller based platform that is well suited to running code for applications involving sensing and control. A very convenient, low-cost and reliable way to connect the raspberry PI and Arduino boards is through the USB cable. This is a convenient solution because it requires a minimum amount of hardware. In addition, it usually provides motor and power control with accurate real-time response, such as high precision and low jitter, which is important for many control applications.

By using the USB interface on each board and the ready-made pyserial library, you can send commands from the raspberry pi to control multiple i/o of Arduino. Moreover, in the opposite way, when Arduino reads multiple data types (such as temperature, speed or other external data to be monitored), serial data can be sent back to pi from Arduino.

Reviewed by: Guoting

Leave a Reply

Your email address will not be published. Required fields are marked *