# Electronics

## Capacitive reactance online calculator & Python code

Use this online calculator to compute the reactance of a capacitor in Ω at a specific frequency given its capacitance.

TechOverflow calculators:
You can enter values with SI suffixes like 12.2m (equivalent to 0.012) or 14k (14000) or 32u (0.000032).
The results are calculated while you type and shown directly below the calculator, so there is no need to press return or click on a Calculate button. Just make sure that all inputs are green by entering valid values.

F

Hz

#### Formula:

$$X_C = \frac{1}{2\pi fC}$$

#### Python code:

The preferred way is to use UliEngineering’s UliEngineering.Electronics.Reactance.capacitive_reactance:

from UliEngineering.Electronics.Reactance import *
# You can either pass strings like "150 pF" or values like 150e-12

capacitive_reactance("150 pF", "10 MHz") # returns 106.1032953945969

from UliEngineering.Electronics.Reactance import *
from UliEngineering.EngineerIO import *

# Compute value as a string
xc = auto_format(capacitive_reactance, "150 pF", "10 MHz") # "106 Ω"

# ... or print directly
auto_print(capacitive_reactance, "150 pF", "10 MHz") # prints "106 Ω"

In case you can’t use UliEngineering and you want to do it manually, here’s a minimal example:

import math
def capacitive_reactance(f, c):
"""Compute the capacitive reactance"""
return 1./(2*math.pi*f*c)
Posted by Uli Köhler in Calculators, Electronics, Python

## Volts to dBµV online calculator & Python code

Use this online calculator to convert a voltage in Volts to a voltage in dBµV.

TechOverflow calculators:
You can enter values with SI suffixes like 12.2m (equivalent to 0.012) or 14k (14000) or 32u (0.000032).
The results are calculated while you type and shown directly below the calculator, so there is no need to press return or click on a Calculate button. Just make sure that all inputs are green by entering valid values.

V

#### Formula:

$$U_{\text{dBµV}} = \frac{20\cdot\log(1\,000\,000 \cdot U_V)}{ \log(2) + \log(5)}$$

#### Python code:

import math
def volts_to_dbuv(v):
"""Convert a voltage in volts to a voltage in dBµV"""
return (20*math.log(1e6 * v))/(math.log(2) + math.log(5))

Posted by Uli Köhler in Calculators, Electronics

## dBµV to Volts online calculator & Python code

Use this online calculator to convert a voltage in dBµV to a voltage in Volts.

TechOverflow calculators:
You can enter values with SI suffixes like 12.2m (equivalent to 0.012) or 14k (14000) or 32u (0.000032).
The results are calculated while you type and shown directly below the calculator, so there is no need to press return or click on a Calculate button. Just make sure that all inputs are green by entering valid values.

dBµV

#### Formula:

$$U_{\text{Volts}} = \frac{10^{\frac{U_{dBµV}}{20}}}{1\,000\,000 \frac{V}{µV}}$$

#### Python code:

def dbuv_to_volts(dbuv):
"""Convert a voltage in dBµV to a voltage in volts"""
return (10**(dbuv/20.))/1e6

Posted by Uli Köhler in Calculators, Electronics

## How to install picamraw using pip

First try installing it normally:

sudo pip3 install picamraw

In case that fails with this error message (like for me):

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting picamraw
Could not install packages due to an EnvironmentError: 404 Client Error: Not Found for url: https://www.piwheels.org/simple/picamraw/

download it and install it manually: Copy the link of the most recent .whl file from https://pypi.org/project/picamraw/#files, download it using wget and install it using pip3, e.g.:

wget https://files.pythonhosted.org/packages/1e/47/4efb0d0ab5d40142424e7f3db545e276733a45bd7f7f9095919ef30c96b3/picamraw-1.2.64-py3-none-any.whl
sudo pip3 install picamraw-1.2.64-py3-none-any.whl

Posted by Uli Köhler in Python, Raspberry Pi

## How to capture Raspi Camera image using OpenCV & Python

First, install OpenCV for Python 3:

sudo apt install python3-opencv

Here’s the code to acquire the image and store it in image.png:

#!/usr/bin/env python3
import cv2
video_capture = cv2.VideoCapture(0)
# Check success
if not video_capture.isOpened():
raise Exception("Could not open video device")
# Read picture. ret === True on success

cv2.imwrite('image.png', frame)
# Close device
video_capture.release()


Run it using

python3 cv-raspicapture.py

Posted by Uli Köhler in OpenCV, Python, Raspberry Pi

## How to fix Raspi camera ‘mmal_vc_component_create: failed to create component ‘vc.ril.camera’ (1:ENOMEM)’

### Problem:

You are trying to acess the Raspberry Pi camera using raspistill or raspivid, but you see an error message like this:

mmal: Cannot read camera info, keeping the defaults for OV5647
mmal: mmal_vc_component_create: failed to create component 'vc.ril.camera' (1:ENOMEM)
mmal: mmal_component_create_core: could not create component 'vc.ril.camera' (1)
mmal: Failed to create camera component
mmal: main: Failed to create camera component
mmal: Camera is not enabled in this build. Try running "sudo raspi-config" and ensure that "camera" has been enabled


### Solution:

The most common issue here is that you don’t have the camera interface enabled. Read How to enable Raspberry Pi camera using raspi-config for instructions on how to do that.

If the camera interface has already been enabled (remember that you need to reboot for the changes to take effect), the most likely reason for error messages like this is that the camera is not connected correctly to the Raspberry Pi:

• Is the CSI cable inserted the right way? The silvery contacts need to face away from the Ethernet connector!
• Is the CSI cable fully seated?
• Did you insert the CSI cable into the Display connector? It needs to be inserted into the CSI connector, which is the one closer to the Ethernet connector.
• Is the other end of the CSI cable correctly attached to the camera board?
Posted by Uli Köhler in Embedded, Raspberry Pi

## How to enable Raspberry Pi camera using raspi-config

You can enable the camera interface by running

sudo raspi-config

Select 5 Interfacing Options and press Return.

Now select P1 Camera and press Return.

Select Yes and press Return.

Now that the camera interface has been enabled, press Return.

Press Tab twice to select Finish and press Return. You are now asked if you want to reboot:

Select Yes and wait for your Raspberry Pi to reboot. Your camera interface will be enabled after the reboot.

In case you are not asked to reboot, your camera interface was already enabled. In this case, select Finish on the main raspi-config screen by pressing Tab twice and pressing Return:

After pressing Return, check your shell again. Reboot (sudo reboot) so that any previous settings will take effect and then try

sudo raspistill -o myimg.jpg

in order to test your camera.

Posted by Uli Köhler in Embedded, Raspberry Pi

## How to fix Raspi camera ‘failed to open vchiq instance’

### Problem:

You are trying to access the Raspberry Pi camera using raspistill or raspivid. Although you already enabled the camera interface using raspi-config, you see this error message:

* failed to open vchiq instance

### Solution:

Your user does not have the permissions to access the camera interface. As a quick fix, you can run raspistill or raspivid as root using sudo, or add your user to the video group to acquire the required permissions:

You only need to do this once. After that, log out and log back in (or close your SSH session and connect again). If in doubt, restart the Raspberry Pi. See What does &#8217;sudo usermod -a -G group $USER&#8216; do on Linux? for more details. Now you will be able to capture video as normal user: raspivid -o vid.h264 Posted by Uli Köhler in Embedded, Linux ## How to enable SSH on Raspbian without a screen You can open the boot partition on the SD card (the FAT32 partition) and create an empty file named ssh in the root directory of that partition. Ensure that the file is names ssh and not ssh.txt ! If you are in the correct working directory in the command line, use touch ssh On recent Ubuntu version, this will switch to the correct directory and create the file (but you need to mount the directory manually e.g. using your file explorer: cd /media/$USER/boot && touch ssh

Don’t forget to unmount the boot drive before removing the SD card. Once you restart the Raspberry Pi with the modified SD card, SSH will be enabled without you having to attach a keyoard or screen to the Pi.

This approach was tested with the 2018-11-13 version of Raspbian and works with Raspberry Pi 1, Raspberry Pi 2 and Raspberry Pi 3.

Credits to Yahor for the original solution on StackOverflow!

Posted by Uli Köhler in Embedded, Linux

## Resistor power dissipation calculator

Use this online calculator to calculate the power dissipation in a purely resistive load. Continue reading →

Posted by Uli Köhler in Calculators, Electronics

Username: pi
Password: raspberry