Skip to content

Commit 6c9d2d7

Browse files
committed
more tool programs in examples
fft... and plot... allow to visualize captured data from scope set_cal_out_freq.py allows to set the output frequency freely between 32 Hz and 100 kHz Signed-off-by: Martin <[email protected]>
1 parent 078dffd commit 6c9d2d7

16 files changed

+2207
-2049
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ nosetests.xml
3434

3535
# Other test results
3636
model*.conf
37+
*.csv
3738

3839
# Backups
3940
*~

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2022-02-05: Merge branch 'main' of github.com:Ho-Ro/Hantek6022API fix last commit [078dffd]
2+
2022-02-05: fix github workflow [0966f8b]
3+
2022-02-05: fix github workflow [5a50a99]
4+
2022-02-05: more github workflow setup [0c97913]
15
2022-02-05: fix github workflow [5324872]
26
2022-02-05: replace "checkinstall" by "python3-stdeb" in github workflow setup [46962d4]
37
2022-02-05: change debian build from "checkinstall" to "stdeb" tool [de61c32]
File renamed without changes.

MANIFEST.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ include PyHT6022/Firmware/*/*.ihex
88
# tool scripts
99
include examples/calibrate_6022.py
1010
include examples/capture_6022.py
11+
include examples/plot_from_capture_6022.py
12+
include examples/fft_from_capture_6022.py
13+
include examples/fft_ft_from_capture_6022.py
14+
include examples/set_cal_out_freq_6022.py
1115
include examples/upload_6022_firmware_from_hex.py
1216
include examples/upload_6022_firmware.py
1317
include fx2upload/fx2upload

Makefile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,26 @@ changelog:
3939

4040
# create a debian binary package
4141
.PHONY: deb
42-
deb: all changelog
42+
deb: all changelog distclean
4343
DEB_BUILD_OPTIONS=nocheck python setup.py --command-packages=stdeb.command bdist_deb
44+
ln `ls deb_dist/hantek6022api_*.deb | tail -1` .
4445

4546

4647
# create a debian source package
4748
.PHONY: dsc
48-
dsc: all changelog
49+
dsc: all changelog distclean
4950
DEB_BUILD_OPTIONS=nocheck python setup.py --command-packages=stdeb.command sdist_dsc
5051

5152

5253
.PHONY: debinstall
5354
debinstall: deb
54-
sudo dpkg -i `ls deb_dist/hantek6022api_*.deb | tail -1`
55+
sudo dpkg -i hantek6022api_*.deb
5556

5657

5758
# remove all compiler artefacts
5859
.PHONY: clean
5960
clean:
6061
-rm *~ .*~
61-
-rm -rf build/*
62-
-rm -rf dist/*
6362
( cd $(DSO6021) && make clean )
6463
( cd $(DSO6022BE) && make clean )
6564
( cd $(DSO6022BL) && make clean )
@@ -69,9 +68,9 @@ clean:
6968

7069
# remove all package build artefacts
7170
.PHONY: distclean
72-
distclean: clean
71+
distclean:
7372
python setup.py clean
74-
rm -rf *~ .*~ deb_dist dist *.tar.gz *.egg* build tmp
73+
-rm -rf *~ .*~ deb_dist dist *.tar.gz *.egg* *.deb build tmp
7574

7675

7776
# transfer the needed hex files to OpenHantek

PyHT6022/LibUsbScope.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -890,23 +890,34 @@ def set_ch2_voltage_range(self, range_index, timeout=0):
890890
def set_calibration_frequency(self, cal_freq, timeout=0):
891891
"""
892892
Set the frequency of the calibration output.
893-
:param cal_freq: The frequncy coded into one byte for the Oscilloscope object.
893+
:param cal_freq: 32 Hz <= cal_freq <= 100 kHz
894+
The frequency will be coded into one byte for the Oscilloscope object.
894895
0 -> 100 Hz (be compatible with sigrok FW)
895896
1..100 -> 1..100 kHz
896897
101..102 -> do not use
897898
103 -> 32 Hz (lowest possible calfreq due to 16bit HW counter)
898-
104..200 -> 40..1000 Hz ( calfreq = 10*(freq-100) )
899-
201..255 -> 100..5500 Hz ( calfreq = 100*(freq-200) )
899+
104..200 -> 40..1000 Hz, step = 10 Hz ( calfreq = 10*(freq-100) )
900+
201..255 -> 100..5500 Hz, step = 100 Hz ( calfreq = 100*(freq-200) )
900901
:param timeout: (OPTIONAL).
901902
:return: True if successful. This method may assert or raise various libusb errors if something went wrong.
902903
"""
904+
if cal_freq < 32 or cal_freq > 100000:
905+
return False
906+
907+
if cal_freq < 1000:
908+
cal_freq_byte = int(cal_freq / 10) + 100 # 103...199 -> 32...990 Hz
909+
elif cal_freq < 5600:
910+
cal_freq_byte = int(cal_freq / 100) + 200 # 201...255 -> 100...5500 Hz
911+
else:
912+
cal_freq_byte = ( cal_freq / 1000 ) # 1...100 -> 1...100 kHz
913+
903914
if not self.device_handle:
904915
assert self.open_handle()
905916

906917
bytes_written = self.device_handle.controlWrite(0x40, self.SET_CAL_FREQ_REQUEST,
907918
self.SET_CAL_FREQ_VALUE,
908919
self.SET_CAL_FREQ_INDEX,
909-
pack("B", cal_freq), timeout=timeout)
920+
pack("B", cal_freq_byte), timeout=timeout)
910921
assert bytes_written == 0x01
911922
return True
912923

README.md

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ This repo is based on the excellent work of [Robert](https://github.com/rpcope1/
88
and [Jochen](https://github.com/jhoenicke/Hantek6022API)
99
and focusses mainly on Hantek6022BE/BL under Linux (development system: debian buster).
1010

11-
__Hantek6022BE custom firmware is feature complete and usable for [OpenHantek6022](https://github.com/OpenHantek/OpenHantek6022)__
11+
## Hantek 6022 Firmware
1212

13-
__Hantek6022BL custom firmware is feature complete but not as intensively tested as the BE version__
13+
* __Hantek6022BE custom firmware is feature complete and usable for [OpenHantek6022](https://github.com/OpenHantek/OpenHantek6022)__
1414

15-
<img alt="Scope Visualisation Example" width="100%" src="HT6022BEBuiltInOscillator.png">
15+
* __Hantek6022BL custom firmware is feature complete but not as intensively tested as the BE version__
1616

17+
## Hantek 6022 Python API for Linux
1718

18-
Hantek 6022 Python API for Linux. This is a API for Python for the
19+
<img alt="Scope Visualisation Example" width="100%" src="plot_from_capture.png">
20+
21+
This is a API for Python for the
1922
ultra-cheap, reasonably usable (and hackable) 6022 DSO, with a libusb implementation via libusb1 for Linux.
2023

2124
The scope can be accessed by instantiating an oscilloscope object with the correct scopeid (always 0 for one scope
@@ -76,8 +79,9 @@ The installed programs can also be uninstalled cleanly with
7679

7780
sudo dpkg -P hantek6022api
7881

79-
With the device plugged in, run `upload_6022_firmware.py` (installed into `/usr/bin`) to bootstrap the scope for use.
80-
You can then write your own programs, or look at the current channel 1 scope trace via `python examples/scopevis.py`.
82+
With the device plugged in, run `upload_firmware_6022.py` once to bootstrap the scope for use.
83+
You can then look at the scope traces via `capture_6022.py -t 0.01 | plot_from_capture_6022.py`,
84+
or write your own programs - look at the programs in `examples` as a start.
8185

8286
## It even works under Windows
8387

@@ -99,17 +103,25 @@ You can then write your own programs, or look at the current channel 1 scope tra
99103
You can also use the `libusb-1.0.dll` file from the
100104
[libusb-1.0 version](https://github.com/OpenHantek/OpenHantek6022/blob/master/cmake/libusb-1.0.21-win.7z)
101105
that is provided by [OpenHantek6022](https://github.com/OpenHantek/OpenHantek6022).
102-
The `libusb-1.0.dll` file should be found in the PATH, e.g. it could be in the `python.exe` directory or together with the example programs in the same directory.
106+
The `libusb-1.0.dll` file should be found in the PATH, e.g. it could be in the `python.exe` directory
107+
or together with the example programs in the same directory.
103108

104109
YMMV, I checked it only with a bare-bones virtual Win7 install under Debian.
105110

106111
## Create calibration values for OpenHantek
107112

108-
As you can see in the trace above the scope has a quite big zero point error (the measured real signal switches between 0.0 V and 2.0 V) - also the gain is defined by resistors with 5% tolerance in the frontend - in best case by two resistors R27/17 & R31/21 in the chain (x1), in worst case by four resistors R27/17 & R31/21 & R32/23 & R18/19/22 in the chain (x2, x5, x10).
113+
<img alt="Uncalibrated scope data" width="50%" src="HT6022BE_uncalibrated.png">
114+
115+
As you can see in the trace above the scope has a quite big zero point error (the measured real signal
116+
switches between 0.0 V and 2.0 V) - also the gain is defined by resistors with 5% tolerance
117+
in the frontend - in best case by two resistors R27/17 & R31/21 in the chain (x1),
118+
in worst case by four resistors R27/17 & R31/21 & R32/23 & R18/19/22 in the chain (x2, x5, x10).
109119

110120
-> https://github.com/Ho-Ro/Hantek6022API/blob/master/hardware/6022BE_Frontend_with_pinout.jpg
111121

112-
In the end you can have a statistical gain tolerance of about 7%...10% -> RSS analysis (root sum square, square all tolerances, sum them up und calculate the root of this sum) gives an expected tolerance range:
122+
In the end you can have a statistical gain tolerance of about 7%...10% -> RSS analysis
123+
(root sum square, square all tolerances, sum them up und calculate the root of this sum)
124+
gives an expected tolerance range:
113125

114126
- sqrt( 2 * (5%)² ) = 1.4 * 5% = 7% for gain step x1
115127
- sqrt( 4 * (5%)² ) = 2 * 5% = 10% for all other gains
@@ -121,7 +133,7 @@ or `%APPDATA%\OpenHantek\modelDSO6022.ini` for Windows.
121133

122134
Step 2 uses the factory offset calibration values in eeprom.
123135
Out of the box only offset values are contained in eeprom,
124-
the program `calibrate_6022.py` (installed in `/usr/local/bin`) allows to update these values in case the offset has changed over time.
136+
the program `calibrate_6022.py` (installed in `/usr/bin`) allows to update these values in case the offset has changed over time.
125137

126138
Program to calibrate offset and gain of Hantek 6022BE/BL
127139
1. Measure offset at low and high speed for the four gain steps x10, x5, x2, x1
@@ -179,10 +191,10 @@ Requested Voltage | Applied Voltage | Comment
179191

180192
## Use the device as a data logger ##
181193

182-
The program `capture_6022.py` (also in `/usr/local/bin/`) allows to capture both channels over a long time.
194+
The program `capture_6022.py` (also in `/usr/bin/`) allows to capture both channels over a long time.
183195

184-
The 256 x downsampling option increases the SNR and effective resolution (8bit -> at least 12 bit) and allows very long time recording.
185-
The program uses the offset and gain calibration from EEPROM.
196+
The 256 x downsampling option increases the SNR and effective resolution (8bit -> at least 12 bit)
197+
and allows very long time recording. The program uses the offset and gain calibration from EEPROM.
186198
It writes the captured data into stdout or an outfile and calculates DC, AC and RMS of the data.
187199

188200
usage: capture_6022.py [-h] [-d DOWNSAMPLE] [-o OUTFILE] [-r RATE] [-t TIME]
@@ -200,6 +212,20 @@ It writes the captured data into stdout or an outfile and calculates DC, AC and
200212
-y CH2, --ch2 CH2 gain of channel 2 (1, 2, 5, 10, default: 1)
201213

202214

215+
The program `plot_from_capture_6022.py` takes the captured data (either from stdin
216+
or from a file named as 1st command line argument) and presents them as seen on top of this page.
217+
218+
usage: plot_from_capture_6022.py [-h] [-i INFILE] [-o OUTFILE] [-c CHANNELS] [-s]
219+
220+
optional arguments:
221+
-h, --help show this help message and exit
222+
-i INFILE, --infile INFILE
223+
read the data from INFILE
224+
-c CHANNELS, --channels CHANNELS
225+
show one (CH1) or two (CH1, CH2) channels, default: 2)
226+
-s, --spectrum display the spectrum of the samples
227+
228+
203229
## Other neat things you can do
204230

205231
While this scope isn't quite as poweful as your many-thousand dollar Tektronix or even your run of the mill Rigol 1102E,

examples/PyHT6022

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../PyHT6022

0 commit comments

Comments
 (0)