Retropie plug in USB speaker

pimg_20180211_171329-600

A detailed instructions of how to make this DIY retropie plug in usb speaker from Facelesstech:

The 2 down sides to my ZeroBoy build I did recently were that it didn’t have a build in battery power and that it didn’t have sound. I seen that the MintyPi was using a USB sound card to give their handheld a speaker by soldering a speaker to the 3.5mm jack. So I thought I could do the same to add sound to my ZeroBoy.

Check out the video after the break.

App note: LEDs – The future of horticultural lighting

an_wurth_ANO002a

LEDs used in a controlled environment greenhouse farms, an app note from Würth Elektronik. Link here (PDF)

Greenhouse farms may not be a new technology but with an every growing world population and the move towards sustainability, intensive yet highly efficient and standardized food production will increasingly become the norm in future years opening a potentially huge new agricultural sector that incorporates the latest technologies from the bioscience and engineering fields. But how can researchers and personnel from these separate fields understand the mutually dependent requirements of indoor greenhouses? Photosynthesis is the process that converts water and carbon dioxide into complex carbohydrates (i.e. sugars) and oxygen using energy from light. However, although the energy radiated by the sun that reaches the earth’s surface consists of the entire spectrum of visible light (and more), plants only utilize specific frequencies of light for photosynthesis. These frequencies are related to the absorption characteristics of different pigments that are present within organelles called chloroplasts that are responsible for different functions of photosynthesis.

Light emitting diodes are solid-state, light generating components that, have become and will continue to be one of the greatest drivers in the expansion of internal greenhouses due to their advantages over incandescent bulbs, fluorescent bulbs, high-pressure sodium lamps and mercury lamps. Their main advantage stems from their ability to generate specific wavelengths of light. To meet the requirements for Horticultural LED’s for Indoor-farming, Würth Elektronik offers the WL-SMDC SMD Mono-color Ceramic LED Waterclear series of LEDs. The WL-SMDC range has been expanded to include wavelengths of 450 nm (Deep Blue), 660 nm (Hyper Red) and 730 nm (Far Red), which have been selected to match the absorption spectra of photosynthetic pigments. In addition to the existing products in the range, a diverse range of combinations is possible that can be catered to the target cultivar.

App note: The behavior of electro-magnetic radiation of power inductors in power management

an_wurth_ANP047a

Application note form Würth Elektronik about EM radiation radiated from inductors in DC-DC converters. Link here (PDF)

This Application Note focuses on the Electro-Magnetic (EM) radiation behavior of power inductor(s) in DC-DC converters, which is dependent on several parameters such as ripple current, switching frequency, rise & fall time of a switching device, the core material and its permeability and suggests several design tips to mitigate these EMI effects.

ESP32 (31) – BLE, GAP

In my previous tutorials you learned how to use the wifi interface of the esp32 chip. Starting from this post, I’m going to explain you the second wireless technology the esp32 chip supports: bluetooth.

In particular, my tutorial will be about Bluetooth Low Energy (BLE), sometimes called also Bluetooth 4.0 or Bluetooth Smart:

ble-001

Bluetooth Low Energy

BLE is a technology to build personal wireless area networks (WPAN); that is it allows to put in communication different devices (computers, smartphones, smartwatches…) “close” to each other (a theoretical maximum distance of 100m). As the name suggests, version 4.0 of the Bluetooth standard was designed to reduce the power consumption of the devices connected to the network.

Devices are divided into two families:

  • central
  • peripheral

the first ones (central) are devices like PCs, tablets or smartphones with good processing power and memory. The second ones (peripheral) are instead sensors, tags… with less hardware resources and power. A central device can be connected to more peripheral devices at the same time, while it’s not true the opposite:

ble-002

BLE devices periodically report their presence by transmitting advertising packets. The advertising packet can contain up to 31 bytes of data and the transmission frequency can be chosen by the single device: reducing this frequency can indeed reduce energy consumption.

If a BLE device, after having received an avertising package, wants to obtain more information from the device that transmitted it, it can request a second packet of information (always for a maximum of 31 bytes), the scan response packet. The transmission of this second data package is optional:

ble-003

A BLE device can take advantage of advertising packages to send data in broadcast mode. In this case, this device is called a broadcaster, while the devices that receive the data are called observers.

What explained above is defined within a BLE specification called Generic Access Profile (GAP).

esp32

In this first tutorial you’ll learn how to develop a program that will periodically scan the air looking for BLE devices, that is a program which receives advertising packets and displays the data received in the serial console.

Before compiling a program which uses the Bluetooth controller, make sure (using menuconfig) that the controller is enabled (Component config -> Bluetooth):

ble-004

Start your program with the required header files:

#include "esp_bt.h"
#include "esp_bt_main.h"
#include "esp_gap_ble_api.h"

You also need to initialize the NVS partition, used by the Bluetooth driver:

ESP_ERROR_CHECK(nvs_flash_init());

the Bluetooth controller of the esp32 chip supports both the classic and the low energy mode. If one of this two modes is not required in your program, you can release the memory the framework normally allocates to manage it using the esp_bt_controller_mem_release() command. In this example you’re not going to use the classic mode, so:

ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));

Now you can configure (using the default settings) the controller in BLE mode:

esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
esp_bt_controller_init(&bt_cfg);
esp_bt_controller_enable(ESP_BT_MODE_BLE);

The esp-idf framework esp-idf includes the Bluedroid bluetooth stack. This library was developed by Broadcom and used by Android since version 4.2 Bluedroid is initialized and enabled with the following commands:

esp_bluedroid_init();
esp_bluedroid_enable();

Now you’re ready to start scanning…

GAP, events

In a similar way to what you learned about the wifi driver, the bluetooth driver also runs in a thread separate from our program and communicates with it via events. In order to receive such events, you have to implement a callback function. Whenever the bluetooth driver has to notify an event, it will call that function.

The prototype of the callback function is:

static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);

You tell the driver which callback function has to use with the esp_ble_gap_register_callback() method:

ESP_ERROR_CHECK(esp_ble_gap_register_callback(esp_gap_cb));

The Bluetooth driver handles several events, there are the ones related to the scan process:

ble-005

Before being able to start the scan process, you have to configure the scan parameters. The configuration is performed using the esp_ble_scan_params_t struct. It’s very important that the variable with the scan parameters is available during all the scan process; it’s therefore necessary to define it globally:

static esp_ble_scan_params_t ble_scan_params = {
  .scan_type              = BLE_SCAN_TYPE_ACTIVE,
  .own_addr_type          = BLE_ADDR_TYPE_PUBLIC,
  .scan_filter_policy     = BLE_SCAN_FILTER_ALLOW_ALL,
  .scan_interval          = 0x50,
  .scan_window            = 0x30
};

With the esp_ble_gap_set_scan_params() method you configure the scan process passing the struct defined above to the driver:

esp_ble_gap_set_scan_params(&ble_scan_params);

When the driver has finished the configuration, it calls the callback function with the event ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT. Depending on the event raised, the callback function also receives some parameters. The framework’s Programming Guide explains – for each event – the related parameters. For this event, it’s available the variable scan_param_cmpl that contains only the status parameter.

In the callback function you can use the switch statement to identify each event:

switch (event) {
  case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT:
  [...]
  break;

and check if the configuration was successful with:

if(param->scan_param_cmpl.status == ESP_BT_STATUS_SUCCESS)

If so, you can start the scan process:

esp_ble_gap_start_scanning(10);

The parameter is the scan duration (in seconds).

Once the scan process has started, the driver raises the ESP_GAP_BLE_SCAN_START_COMPLETE_EVT event. For this event too it’s possible to verify the correct execution by reading the status parameter (pay attention: the name of the variable which contains the parameter changes!):

case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
  if(param->scan_start_cmpl.status == ESP_BT_STATUS_SUCCESS)
    printf("Scan started\n\n");
  else 
    printf("Unable to start scan process");
  break;

GAP, scan process

During the scan process, for each advertising packet the chip receives the event ESP_GAP_BLE_SCAN_RESULT_EVT is raised.

This event contains some subevents. You can identify which subevent was raised reading the scan_rst.search_evt parameters. Two subevents are in particular interesting:

ble-006

the first tells you that a device was detected, while the second one that the scan process completed.

For each detected device, various information is available. For now let’s print its address in the console:

case ESP_GAP_BLE_SCAN_RESULT_EVT:
  if(param->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_RES_EVT) {
    printf("Device found: ADDR=");
    for(int i = 0; i < ESP_BD_ADDR_LEN; i++) {
      printf("%02X", param->scan_rst.bda[i]);
      if(i != ESP_BD_ADDR_LEN -1) printf(":");
    }

The address is an uint8_t array, whose size is defined by the ESP_BD_ADDR_LEN constant. The address is normally displayed in hex form, with the bytes separated by :

ble-007

Device list management

As explained above, the ESP_GAP_BLE_SCAN_RESULT_EVT event is raised everytime a device sends an advertising packet. This means that a single device will be detected multiple times during the scan process.

It’s therefore necessary to maintain a list of the known devices. In my Github repository you can find a test program that scans the network and prints all the detected devices.

You can verify if it works correctly comparing what the program detects with the BLE devices listed by a smartphone… for Android for example you can use the very good nRF Connect application by Nordic.

Here’s what my program detected:

ble-008

and here’s the nRF Connect’s screenshot:

ble-009

 

Optimizing the 5v to 170v Nixie tube power supply design (part 2)

p-img_5710-1-600

Mark Smith has a nice write-up on optimizing the 5v to 170v Nixie tube power supply:

Since this power supply is just a fun design for an upcoming Nixie tube clock project of mine, I have the time to achieve ESE. While in Part 1 I described the equations and simulations, in this Part 2, I collected experimental results to complete the design. In the process of finalizing the design, I was able to discover a couple of key design improvements and I’ll share these changes with you. The updated schematic, BOM, Kicad Layout, and design files are located at Github.

Via surfncircuits.

STM32F103 vs GD32F103 round 2: Blink a LED

p-blinkaled-1080x675-600

A follow-up to the STM32F103 vs GD32F103 round 1- Solderability post, Sjaak writes:

The defacto ‘hello world’ for microcontrollers is blink a LED at a steady rate. This is exactly what I’m going to do today. I made a small 5×5 development board, soldered it up and started programming. In this first example we not gonna use fancy IRQs or timers to blink at a steady rate, but we insert NOPsas delay. This would give an idea of the RAW performance of the chip. The used code is simple; set up the maximum available clock available and then toggle RA0 for ever.

More details at smdprutser.nl.

Teardown of an HP 8671A microwave frequency synthesizer

p-HP8671A-600

Kerry Wong did a teardown of an HP 8671A microwave frequency synthesizer:

I recently bought an HP 8671A microwave frequency synthesizer on eBay. This synthesizer can generate signals from 2GHz to 6.2GHz with an unleveled output of more than 8dBm. It is a nice complement to my HP 8642B signal generator and Wavetek 907 signal generator. Using these generators, I can now generate signals of pretty much any frequencies under the 12GHz range. A video of this teardown is linked towards the end of this post.

More details on his blog here.

Check out the video after the break.

App note: Understanding infrared diode power ratings

an_ttelectronics_ir_specs

App note from TT Electronics about infrared diode specs, how they vary from different manufacturers, and help clear things about infrared definition of parameters. Link here (PDF)

Infrared emitting diode power measurement is dependent upon a number of variables which must be precisely defined in order for design engineers to utilize data sheet information. Manufacturers differ not only in the techniques used in measuring power, but also in their interpretations of the definitions of the parameters which are measured. This application bulletin is intended to clarify this misunderstanding, especially for GaAs and GaAlAs solution grown epitaxial devices.