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

How to skip SSL certificate verification during git clone

Problem:

When running git clone, you see an error message like

Cloning into 'MyProject'...
fatal: unable to access 'https://gitlab.mydomain.com/projects/MyProject.git': server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none

Solution:

The quick solution is to prepend

GIT_SSL_NO_VERIFY=true

to the git clone command, example:

GIT_SSL_NO_VERIFY=true https://gitlab.mydomain.com/projects/MyProject.git

Note that skipping SSL verification is a security risk, so the correct method of fixing this issue is appropriately updating the CA certificates (something like sudo apt install ca-certificates) but this is sometimes not feasibel since not any outdated computer can be updated easily.

Posted by Uli Köhler in git, Linux

Install Teensyduino on Debian

Don’t use the Arduino package offered through the Software App in Debian. Install the one offered by official site arduino.cc. The Teensyduino installer will not recognize the distribution package install.

Arduino Install:

  1. Get your flavor of the Arduino software: https://www.arduino.cc/en/Main/Software
  2. Download, extract and install. Be aware that the extraction location will be the application location.

Teensyduino Install:

  1. Go to: https://www.pjrc.com/teensy/td_download.html
  2. Download the Linux udev rules (link at the top of the download page) and copy the file to /etc/udev/rules.d.
    sudo cp 00-teensy.rules /etc/udev/rules.d/
  3. Download and extract one of Arduino’s Linux packages.
  4. Run the installer by adding execute permission and then execute it. chmod 755 TeensyduinoInstall.linux64
    ./TeensyduinoInstall.linux64
Posted by Tobias Gutmann in Arduino

How to fix tox AttributeError: module ‘virtualenv.create.via_global_ref.builtin.cpython.mac_os’ has no attribute ‘CPython2macOsArmFramework’

Problem:

While trying to run Python tests using tox, you see an error message like

GLOB sdist-make: /home/uli/dev/UliEngineering/setup.py
py37 create: /home/uli/dev/UliEngineering/.tox/py37
ERROR: InterpreterNotFound: python3.7
py38 create: /home/uli/dev/UliEngineering/.tox/py38
ERROR: invocation failed (exit code 1), logfile: /home/uli/dev/UliEngineering/.tox/py38/log/py38-0.log
========================================================================================= log start =========================================================================================
AttributeError: module 'virtualenv.create.via_global_ref.builtin.cpython.mac_os' has no attribute 'CPython2macOsArmFramework'

========================================================================================== log end ==========================================================================================
ERROR: InvocationError for command /usr/bin/python3 -m virtualenv --no-download --python /usr/bin/python3 py38 (exited with code 1)
__________________________________________________________________________________________ summary __________________________________________________________________________________________
ERROR:  py37: InterpreterNotFound: python3.7
ERROR:   py38: InvocationError for command /usr/bin/python3 -m virtualenv --no-download --python /usr/bin/python3 py38 (exited with code 1)

Solution:

This error occurs because two different and incompatible version of virtualenv are installed.

First, uninstall all versions using these commands:

First run as user (not as root) to uninstall any locally installed package in ~/.local:

pip3 uninstall virtualenv

Then, uninstall global packages

sudo pip3 uninstall virtualenv

Now uninstall the apt package on Debian/Ubuntu (uninstall using your package manager for other distros):

sudo apt purge python3-virtualenv

Now it’s time to install one version of virtualenv:

sudo pip3 install virtualenv

After that, you can try running tox again.

Posted by Uli Köhler in Python

Excel: How to replace formula cell by its value

TL;DR: Press F2, then F9 to replace a cell by its value.

Click on the formula cell (click once, no need to click twice):

Now press the F2 key to edit the cell:

Now press the F9 key to replace the cell by its value:

Posted by Uli Köhler in Allgemein

Create a numpy array of one datetime64 per day and mark the start of the month

startdate = np.datetime64('2022-01-01T00:00:00.000000')
 # 10000 days. This array contains 0 (Day 0), 1 (Day 1), etc
day_offsets = np.arange(10000, dtype=np.int64)
usec_per_day = int(1e6) * 86400 # 86.4k sec per day, 1e6 microseconds per second
# Compute microseconds offset from first day
usec_offsets = day_offsets * usec_per_day
# Compute timestamps
timestamps = startdate + usec_offsets

# Mark start of month in boolean array
is_start_of_month = np.zeros_like(timestamps, dtype=bool)
for index, timestamp in np.ndenumerate(timestamps):
    is_start_of_month[index[0]] = timestamp.astype(datetime).day == 1

Using this method, timestamps will be the start of each day

array(['2022-01-01T00:00:00.000000', '2022-01-02T00:00:00.000000',
       '2022-01-03T00:00:00.000000', ..., '2101-12-30T00:00:00.000000',
       '2101-12-31T00:00:00.000000', '2102-01-01T00:00:00.000000'],
      dtype='datetime64[us]')

 

Posted by Uli Köhler in Data science, Python

Pandas: How to apply numpy function to every column

You can use df.transform(func, axis=0) to apply a numpy function. This leverages the fact that numpy functions work with pandas Series objects.

Example based on How to create pandas time series DataFrame example dataset:

# Load pre-built time series example dataset
df = pd.read_csv("https://datasets.techoverflow.net/timeseries-example.csv", parse_dates=["Timestamp"])
df.set_index("Timestamp", inplace=True)

# np.square will be called individually for each column
new_df = df.transform(np.square, axis=0)

Output

Original time series:

Squared time series:

Full example code

import numpy as np
import pandas as pd
from matplotlib import pyplot as plt

# Load pre-built time series example dataset
df = pd.read_csv("https://datasets.techoverflow.net/timeseries-example.csv", parse_dates=["Timestamp"])
df.set_index("Timestamp", inplace=True)

# np.sqrt will be called individually for each column
new_df = df.transform(np.square, axis=0)

# Plot subsection of original DF for better visibility
df.iloc[:len(df)//2].plot()
plt.gcf().set_size_inches(10,5)
plt.savefig("Normal-Timeseries.svg")

# Plot subsection of transformed DF for better visibility
new_df.iloc[:len(df)//2].plot()
plt.gcf().set_size_inches(10,5)
plt.savefig("Square-Timeseries.svg")

 

Posted by Uli Köhler in pandas, Python
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPTPrivacy & Cookies Policy