Embedded

How to install tailscale on Ubuntu

In order to instal tailscale, on any Ubuntu version, you can use the official tailscale install command:

sudo apt -y install curl apt-transport-https
curl -fsSL https://tailscale.com/install.sh | sh
Posted by Uli Köhler in Headscale, Raspberry Pi, VPN

Fullscreen camera view using libcamera-vid

libcamera-vid --width 1920 --height 1080 -f -t 10000000000

-t 10000000000 means to run for 10000000000 milliseconds (almost 4 months)

Posted by Uli Köhler in Audio/Video, Electronics, Raspberry Pi

How to fix raspistill ERROR: the system should be configured for the legacy camera stack

Problem:

While trying to capture an image using raspistill, you see the following error message

ERROR: the system should be configured for the legacy camera stack

and no image is being produced

Solution 1 (recommended): Use libcamera

Recent versions of Raspbian use libcamera instead of the broadcom legacy camera API. You can capture an image using libcamera-still similarly to raspistill:

libcamera-still -o test.jpg

Solution 2: Enable legacy camera API

If you absolutely need raspistill specifically to work, you can still enable the legacy camera API using rpi-config:

sudo raspi-config

Go to:

  • 3 Interface Config
  • I1 Legacy Camera

and choose Yes to enable the legacy camera API.

Posted by Uli Köhler in Audio/Video, Raspberry Pi

Raspberry Pi libcamera VLC livestreaming (1920×1080)

On the Pi, run

libcamera-vid -t 0 --width 1920 --height 1080 --codec h264 --inline --listen -o tcp://0.0.0.0:8888

On the client, run

vlc tcp/h264://192.168.1.185:8888/

where 192.168.1.185 is the IP address of the Raspberry Pi.

Posted by Uli Köhler in Audio/Video, Raspberry Pi

How to connect CHIP_PU pin on ESP32Sx

The CHIP_PU (Chip PowerUp) pin on ESP32 family processors such as the ESP32S2 is equivalent to the EN (enable) or ~RST pin on other microcontrollers.

When CHIP_PU is pulled high (i.e. to 3.3V), the ESP32 is enabled and will run the firmware.

When CHIP_PU is pulled low (i.e. to GND), the ESP32 is disabled and shut down and will not run the firmware.

In other words, in most applications you want to connect a 10kOhm resistor from CHIP_PU to 3.3V and – if needed – a reset button from the CHIP_PU pin to GNDYou can not operate the ESP32S2 without a pullup resistor . This is clearly stated in the ESP32S2 datasheet, section 2.2:

Note: Do not leave the CHIP_PU pin floating.

On the ESP32S2-WROOM-I module, the CHIP_PU is directly connected to the module’s EN pin wut

Posted by Uli Köhler in ESP8266/ESP32

How much RAM does the ESP32-C3 have?

The ESP32-C3 has 400 kBytes of integrated SRAM (16 kbytes cache).

Source: ESP32-C3 datasheet

Posted by Uli Köhler in ESP8266/ESP32

Teensy 4.x timer interrupt example using TimerTree

void myTimerInterrupt() {
  // TODO Your code goes here
  // The following functions may be useful here:
  // Timer3.start(); // Start counting & clear counter
  // Timer3.stop(); // => stop counting but do not clear counter
  // Timer3.restart(); // => clear counter
  // Timer3.resume(); // => Start, without clearing counter
}

void setup()
{
  Timer3.initialize(20000);
  Timer3.attachInterrupt(myTimerInterrupt);
  Timer3.start();
}

 

Posted by Uli Köhler in Arduino, Electronics, Embedded, Teensy

How to Arduino attachInterrupt() with both RISING and FALLING edge

You can use attachInterupt() with CHANGE to trigger on both RISING and FALLING flanks.

#define INTERRUPT_PIN 13 // Choose any pin with interrupt functionality here.

void myInterrupt() {
  // TODO Your code goes here.
}

void setup() {
  attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), myInterrupt, CHANGE);
}

 

Posted by Uli Köhler in Arduino, Embedded

Teensy 4.1 Arduino external interrupt (pin interrupt) minimal example

In setup(), use

attachInterrupt(digitalPinToInterrupt(23), myInterrupt, RISING);

to configure the interrupt on Teensy Pin 23 on the RISING edge.

Add this function, which will be called during the interrupt:

void myInterrupt() {
  // Your code goes here
}

 

Posted by Uli Köhler in Electronics, Teensy

How to fix st-flash ERROR common.c: stlink_flash_loader_run(0x8000000) failed! == -1

Problem:

While flashing an STM32 using st-flash using a command like

st-flash write build/firmware.bin 0x8000000

you see an error message like

2022-02-12T01:31:34 ERROR flash_loader.c: flash loader run error
2022-02-12T01:31:34 ERROR common.c: stlink_flash_loader_run(0x8000000) failed! == -1

See below for a full error log

Solution

Most likely your STM32 is locked (readout protection). Use OpenOCD to unlock it, see How to unlock STM32F0x using OpenOCD for an example. Adjust to your STM32 family as needed.

Full st-flash log

st-flash 1.6.1
2022-02-12T01:31:34 INFO common.c: F0xx small: 4 KiB SRAM, 16 KiB flash in at least 1 KiB pages.
file build/mom.bin md5 checksum: da211df7131de9de15f3b6c7a96176dd, stlink checksum: 0x000d0d03
2022-02-12T01:31:34 INFO common.c: Attempting to write 11108 (0x2b64) bytes to stm32 address: 134217728 (0x8000000)
2022-02-12T01:31:34 INFO common.c: Flash page at addr: 0x08000000 erased
2022-02-12T01:31:34 INFO common.c: Flash page at addr: 0x08000400 erased
2022-02-12T01:31:34 INFO common.c: Flash page at addr: 0x08000800 erased
2022-02-12T01:31:34 INFO common.c: Flash page at addr: 0x08000c00 erased
2022-02-12T01:31:34 INFO common.c: Flash page at addr: 0x08001000 erased
2022-02-12T01:31:34 INFO common.c: Flash page at addr: 0x08001400 erased
2022-02-12T01:31:34 INFO common.c: Flash page at addr: 0x08001800 erased
2022-02-12T01:31:34 INFO common.c: Flash page at addr: 0x08001c00 erased
2022-02-12T01:31:34 INFO common.c: Flash page at addr: 0x08002000 erased
2022-02-12T01:31:34 INFO common.c: Flash page at addr: 0x08002400 erased
2022-02-12T01:31:34 INFO common.c: Flash page at addr: 0x08002800 erased
2022-02-12T01:31:34 INFO common.c: Finished erasing 11 pages of 1024 (0x400) bytes
2022-02-12T01:31:34 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2022-02-12T01:31:34 INFO flash_loader.c: Successfully loaded flash loader in sram
2022-02-12T01:31:34 ERROR flash_loader.c: flash loader run error
2022-02-12T01:31:34 ERROR common.c: stlink_flash_loader_run(0x8000000) failed! == -1
stlink_fwrite_flash() == -1

 

Posted by Uli Köhler in STM32

How to flash .bin to STM32 using st-flash

You can use st-flash like this to flash a firmware file to the STM32:

st-flash write build/firmware.bin 0x8000000

 

Posted by Uli Köhler in STM32

How to lock STM32F0 using OpenOCD (readout protection)

openocd -f interface/stlink-v2.cfg -f target/stm32f0x.cfg -c "init" -c "halt" -c "stm32f1x lock 0" -c "reset halt" -c "exit"

This will activate flash readout protection level 1 which means you won’t be able to readout or re-write the flash. You can still perform a chip erase which will clear the readout protection – for example to flash a new firmware.

Posted by Uli Köhler in STM32

How to unlock STM32F0x using OpenOCD

openocd -f interface/stlink-v2.cfg -f target/stm32f0x.cfg -c "init" -c "halt" -c "stm32f1x unlock 0" -c "reset halt" -c "exit"

After that, you need to physically remove power from the device in order for the reset to take effect.

Note the stm32f1x is no typo. OpenOCD uses the same backend for STM32F1x and STM32F0x.

Example output:

Open On-Chip Debugger 0.11.0-rc2
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
WARNING: interface/stlink-v2.cfg is deprecated, please switch to interface/stlink.cfg
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 1000 kHz
Info : STLINK V2J24S4 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.296172
Info : stm32f0x.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : starting gdb server for stm32f0x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : device id = 0x10006444
Info : flash size = 16kbytes
stm32x unlocked.
INFO: a reset or power cycle is required for the new settings to take effect.

Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0xc1000000 pc: 0x080000c0 msp: 0x20000400

 

Posted by Uli Köhler in STM32

What pin pitch does the Raspberry Pi DSI display connector / cable have?

The Raspberry Pi DSI display connector (for example the DSI display cable that comes with the Raspberry Pi 7″ display) has a pin pitch of 1.0mm:

Posted by Uli Köhler in Raspberry Pi

How to install tailscale on Raspberry Pi

Just use the official install command from the tailscale website:

curl -fsSL https://tailscale.com/install.sh | sh

 

Posted by Uli Köhler in Headscale, Raspberry Pi, VPN

Which way to mount the Raspberry Pi DSI display cable for the Raspberry Pi 7″ display

First, mount the Raspberry Pi on top of the display PCB on the back of the display.

On the bottom (display) PCB, the silver contacts of the cable should be at the top (facing the Raspberry Pi):

On the Raspberry Pi, the silver contacts should face towards the USB connectors:

Overall, it should look like this:

Posted by Uli Köhler in Raspberry Pi

How to enable OctoPi WiFi connection on boot

First, install OctoPi to the SD card – for example, using rpi-imagerHow to install OctoPi using rpi-imager

Open the boot partition on the OctoPi SD card and create a file wpa_supplicant.conf there, with the following content:

country=de
update_config=1
ctrl_interface=/var/run/wpa_supplicant

network={   
   scan_ssid=1
   ssid="MyWifi"  
   psk="abc123abc"
}

Always set the correct country code at the top ! If you don’t set it correctly, it won’t work!

Set ssid to the name of the wireless network.

Set psk to the wifi password.

Posted by Uli Köhler in 3D printing, Raspberry Pi