Raspberry Pi Lidar Visualization notes

Xiaomi lidar sensor pinout

I’ve tried matplotlib which has a very convenient polar coordinate mode, but the output looked very wrong, so there must be a few mistakes in here:

import matplotlib.pyplot as plt
import matplotlib.animation as animation
import serial
import numpy as np

com_port = "/dev/ttyACM0"
baudrate = 115200
ser = serial.Serial(com_port, baudrate)

fig = plt.figure(figsize=(4,4))
ax = fig.add_subplot(111, projection='polar')

data = np.zeros(360)
theta = np.linspace(0,360, num=360)
l,  = ax.plot([],[])

databuffer = ""

def update(i):
	global data, databuffer
	if (ser.inWaiting()>0):
		data_str = ser.read(ser.inWaiting()).decode('ascii')
		databuffer +=  data_str
		if ('A' in databuffer and 'B' in databuffer and 'C' in databuffer):
			databuffer = databuffer.split('A')[1]
			databuffer = databuffer.split('C')[0]
				(angle, distance) = databuffer.split('B')
			except Exception as e: print(e)

	l.set_data(theta, data )
	return l, 

ani = animation.FuncAnimation(fig, update, frames=360, interval=200, blit=True)

Super simple temperature controller

The idea is to use an adjustable voltage divider to set a desired temperature while a temperature dependent voltage divider provides feedback about the actual print bed temperature.  The first op-amp IC1B works as a comparator that turns on its output to 5V as soon as the non-inverting input pin sees a higher voltage than the inverting input pin. That output controls a simple constant current sink in which the mosfet Q1 can be the heater or the shunt resistor R1 can be replaced with higher resistance power resistors to become heaters. IC2 is just a voltage regulator that provides a stable supply voltage for the op-amps.

Smooth 3D printing timelapse by optimal frame selection

To process video files OpenCV has to be compiled with ffmpeg option. On Windows it was a bit of a fight until I found out about Anaconda: https://www.anaconda.com/download/

In the Anaconda prompt you can just execute

conda install -c menpo opencv3 ffmpeg

and satisfy the other requirements normally.

#!/usr/bin/env python

import numpy as np
import cv2
from skimage.measure import compare_ssim as ssim
import time

cap = cv2.VideoCapture('video.mp4')

ret,previous = cap.read()
best_frame = previous
number = 50
file = 0

	i = 0
	best_s = 0
	i += 1
	ret, frame = cap.read()
	s = ssim(frame, previous, multichannel=True)
	if(s > best_s):
		best_s = s
		best_frame = frame
	cv2.imwrite('folder/%d.png' % file,best_frame)
	file += 1
	previous = best_frame


A few ideas to improve performance in the future:

  • Simplify images before comparing them – This needs a run-time analysis to make sure that the simplifications actually improve speed. The idea is that it would be sufficient to look at a single channel image with half the size instead of RGB Full HD to measure similarity.
  • Make decisions more dynamic – When similarity is larger than a certain threshold and the frame is far enough away from the last, we can use that one right away instead of going through all the remaining candidates.
  • Implement the whole thing in C++ – the actual comparison that is taking a lot of time is done in python scikit-image. Python is a relatively abstract language that’s made for people who want to solve algorithmic problems instead of worrying about syntax. That’s why there are no type declarations, no pointer arithmetic, etc. but on the other hand is a bit slower!
  • Use multithreading – You could start one thread for every comparison and distribute them to CPU cores or even GPU! I am seeing about 15% CPU utilization when the script is running.

RT-ZL03 Rohde & Schwarz active logic probes for RTB2004 PCB photos

Bottom side
Top side

The most important components are the the 4 ADCMP562BRQ Dual High Speed Comparators which determine whether a signal is high or low. N5311 is an EN5311QI ENPIRION DC-DC CONVERTER. The 8-Pin SOIC seems to be Z8 Encore! XP F0823 Series 8-Bit microcontroller by Zilog, not sure what it does, but it seems a bit too powerful to just store a serial number or something like that.