Electronics

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

How to install OctoPi using rpi-imager

First open rpi-imager:

then select Choose OS

Sroll down to Other specific-purpose OS (do not click on Other general-purpose OS, even though it sounds similar!)

Click on Other specific-purpose OS:

Now click on 3D printing:

Click on OctoPi:

Now click on OctoPi (stable):

Now click on Choose Storage to select the SD card you want to write the image to:

Click on the correct device to select it – double check to make sure you have selected the correct device !

Now click Write to download the image and write it to the SD card:

and now grab a coffee since it will take a couple of minutes to write:

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

How long is the Raspberry Pi DSI display cable?

The DSI display cable that comes with the Raspberry Pi 7″ display is 10cm (100mm) long:

Posted by Uli Köhler in Raspberry Pi

How many pins does the Raspberry Pi display DSI cable have?

The Rasbperry Pi DSI connector / cable has 15 pins:

Posted by Uli Köhler in Raspberry Pi

How to enable Raspberry Pi (Raspbian) WiFi connection on boot

Open the boot partition on the Rasbian 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 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 Raspberry Pi

How to fix apt E: Unable to locate package rpi-imager

Problem:

While trying to install rpi-imager using

sudo apt install rpi-imager

you see this error message:

Reading package lists... Done
Building dependency tree       
Reading state information... Done

No apt package "rpi-imager", but there is a snap with that name.
Try "snap install rpi-imager"

E: Unable to locate package rpi-imager

Solution:

sudo apt -y install rpi-imager only works on Raspbian. On Ubuntu etc, you can install rpi-imager using

sudo snap install rpi-imager

Then start it using

rpi-imager

Posted by Uli Köhler in Linux, Raspberry Pi

LinuxCNC: How to get current position including offset using Python

In our previous example LinuxCNC: How to find current position using Python we showed how to use stat.actual_position to get the current position in machine coordinates using LinuxCNC’s Python API.

#!/usr/bin/env python2.7
import linuxcnc

stat = linuxcnc.stat()
stat.poll()
x,y,z,a,b,c,u,v,w = stat.actual_position

# NOTE: Ignore ABCUVW since not used for my machine
# Subtract G5x offset
xo,yo,zo,ao,bo,co,uo,vo,wo = stat.g5x_offset

x -= xo
y -= yo
z -= zo

# Subtract tool offset
xo,yo,zo,ao,bo,co,uo,vo,wo = stat.tool_offset

x -= xo
y -= yo
z -= zo

# Print offset coordinates
print(x,y,z)

 

Posted by Uli Köhler in LinuxCNC, Python

LinuxCNC: What attributes can you read from a linuxcnc.stat() object?

As shown in our previous example LinuxCNC: How to find current position using Python you can get an

These are the attributes of the object returned by linuxcnc.stat() for LinuxCNC 2.7:

acceleration
active_queue
actual_position
adaptive_feed_enabled
ain
angular_units
aout
axes
axis
axis_mask
block_delete
call_level
command
current_line
current_vel
cycle_time
debug
delay_left
din
distance_to_go
dout
dtg
echo_serial_number
enabled
estop
exec_state
feed_hold_enabled
feed_override_enabled
feedrate
file
flood
g5x_index
g5x_offset
g92_offset
gcodes
homed
id
inpos
input_timeout
interp_state
interpreter_errcode
joint_actual_position
joint_position
kinematics_type
limit
linear_units
lube
lube_level
max_acceleration
max_velocity
mcodes
mist
motion_line
motion_mode
motion_type
optional_stop
paused
pocket_prepped
poll
position
probe_tripped
probe_val
probed_position
probing
program_units
queue
queue_full
queued_mdi_commands
rapidrate
read_line
rotation_xy
settings
spindle_brake
spindle_direction
spindle_enabled
spindle_increasing
spindle_override_enabled
spindle_speed
spindlerate
state
task_mode
task_paused
task_state
tool_in_spindle
tool_offset
tool_table
velocity

You can find those out using

#!/usr/bin/env python2.7
import linuxcnc

stat = linuxcnc.stat()
stat.poll()
for entry in dir(stat):
    print(entry)

 

Posted by Uli Köhler in LinuxCNC, Python

LinuxCNC: How to find current position using Python

This will show the position in machine coordinates such as

#!/usr/bin/env python2.7
import linuxcnc

stat = linuxcnc.stat()
stat.poll()
print(stat.actual_position)

Example output:

(7.4023762662053105, 26.443582149595567, 297.289833343029, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

 

Posted by Uli Köhler in LinuxCNC, Python

LinuxCNC: Custom M-100 G-Code that logs time, parameters & filename to CSV

Place this file in e.g. linuxcnc/configs/myCNC/custom-mcode/M100

#!/usr/bin/env python2.7
# M100: write timestamp, parameters and gcode filename to linuxcnc/logM100.txt
import sys
import linuxcnc
from datetime import datetime
dt = datetime.now()

stat = linuxcnc.stat() # create a connection to the status channel
stat.poll()

with open("/home/cnc/linuxcnc/logM100.txt", "a") as outfile:
    outfile.write("{} | Args={} | Path={}\n".format(dt.isoformat(), ", ".join(sys.argv[1:]), stat.file))

and make executable using

chmod a+x ./linuxcnc/configs/myCNC/custom-mcodes/M100
Posted by Uli Köhler in LinuxCNC, Python

LinuxCNC: How to read current position in Python and log to CSV

Also see our post on how to just read the position especially if you don’t care about the CSV logging: LinuxCNC: How to find current position using Python

This script will log the position to CSV approximately every millisecond. The position will be logged in machine coordinates.

#!/usr/bin/env python2.7
import linuxcnc
import datetime
import time

stat = linuxcnc.stat()

with open("position-log.csv", "w") as outfile:
    while True:
       dt = datetime.datetime.now()
       stat.poll()
       x,y,z,a,b,c,u,v,w = stat.actual_position
       outfile.write("{},{:.4f},{:.4f},{:.4f}\n".format(dt.isoformat(), x, y, z))
       time.sleep(0.001)

 

Posted by Uli Köhler in LinuxCNC, Python

How to fix ESP32 A fatal error occurred: ESP32 ROM does not support function erase_flash.

Problem:

When running esptool erase_flash, you an error message like:

esptool.py v2.8
Found 1 serial ports
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP32
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
WARNING: Detected crystal freq 41.01MHz is quite different to normalized freq 40MHz. Unsupported crystal in use?
Crystal is 40MHz
MAC: 7c:9e:bd:f4:60:e0
Enabling default SPI flash mode...
Erasing flash (this may take a while)...

A fatal error occurred: ESP32 ROM does not support function erase_flash.

Solution:

You are likely using an outdated version of esptoolUse the esptool from GitHub:

git clone https://github.com/espressif/esptool.git

then run it using

cd esptool
python3 esptool.py erase_flash
Posted by Uli Köhler in Electronics, ESP8266/ESP32

How to parse linuxcnc.var using Python

with open("/home/cnc/linuxcnc/configs/myCNC/linuxcnc.var") as infile:
    lines = infile.readlines()
    splitted = [line.strip().partition("\t") for line in lines]
    linuxCNCVar = {int(splitResult[0]): float(splitResult[-1]) for splitResult in splitted}

Example output for linuxCNCVar:

{5161: 0.0,
 5162: 0.0,
 5163: 0.0,
 5164: 0.0,
 5165: 0.0,
 5166: 0.0,
 5167: 0.0,
 5168: 0.0,
 5169: 0.0,
 5181: 0.0,
 5182: 0.0,
 5183: 0.0,
 5184: 0.0,
 5185: 0.0,
 5186: 0.0,
 5187: 0.0,
 5188: 0.0,
 5189: 0.0,
 5210: 0.0,
 5211: 0.0,
 5212: 0.0,
 5213: 0.0,
 5214: 0.0,
 5215: 0.0,
 5216: 0.0,
 5217: 0.0,
 5218: 0.0,
 5219: 0.0,
 5220: 1.0,
 5221: 7.40119,
 5222: 13.549249,
 5223: 298.476583,
 5224: 0.0,
 5225: 0.0,
 5226: 0.0,
 5227: 0.0,
 5228: 0.0,
 5229: 0.0,
 5230: 0.0,
 5241: 36.868548,
 5242: 141.752329,
 5243: 207.563262,
 5244: 0.0,
 5245: 0.0,
 5246: 0.0,
 5247: 0.0,
 5248: 0.0,
 5249: 0.0,
 5250: 0.0,
 5261: 36.868548,
 5262: 145.029329,
 5263: 207.563262,
 5264: 0.0,
 5265: 0.0,
 5266: 0.0,
 5267: 0.0,
 5268: 0.0,
 5269: 0.0,
 5270: 0.0,
 5281: 36.89201,
 5282: 144.834924,
 5283: 207.935105,
 5284: 0.0,
 5285: 0.0,
 5286: 0.0,
 5287: 0.0,
 5288: 0.0,
 5289: 0.0,
 5290: 0.0,
 5301: 0.0,
 5302: 0.0,
 5303: 0.0,
 5304: 0.0,
 5305: 0.0,
 5306: 0.0,
 5307: 0.0,
 5308: 0.0,
 5309: 0.0,
 5310: 0.0,
 5321: 0.0,
 5322: 0.0,
 5323: 0.0,
 5324: 0.0,
 5325: 0.0,
 5326: 0.0,
 5327: 0.0,
 5328: 0.0,
 5329: 0.0,
 5330: 0.0,
 5341: 0.0,
 5342: 0.0,
 5343: 0.0,
 5344: 0.0,
 5345: 0.0,
 5346: 0.0,
 5347: 0.0,
 5348: 0.0,
 5349: 0.0,
 5350: 0.0,
 5361: 0.0,
 5362: 0.0,
 5363: 0.0,
 5364: 0.0,
 5365: 0.0,
 5366: 0.0,
 5367: 0.0,
 5368: 0.0,
 5369: 0.0,
 5370: 0.0,
 5381: 0.0,
 5382: 0.0,
 5383: 0.0,
 5384: 0.0,
 5385: 0.0,
 5386: 0.0,
 5387: 0.0,
 5388: 0.0,
 5389: 0.0,
 5390: 0.0}

 

Posted by Uli Köhler in LinuxCNC, Python

M12 connector: How much current / ampacity per contact?

Typical M12 connectors have an ampacity of around 4A per contact. For example, see the Phoenix SACC-M12FR-5PL 5-pin M12 connector

Posted by Uli Köhler in Electronics

How to make Tasmota report the sensor readings every 10 seconds

By default, Tasmota reports the sensor readings such as smart plug energy only every 5 minutes (300 seconds). In order to report them every 10 seconds, run this via the web UI console:

TelePeriod 10

 

Posted by Uli Köhler in Home-Assistant