AboutServicesProjectsBlog
Projects
Hanging Plotter
First Steps - Pinning an idea down and checking assumptions
Post Print Iterations
ESP32 development in NixOS using VSCode
Spinning a Stepper
Android development on NixOS
Connecting an ESP32 to android with bluetooth
Using an ESP32 as a logic analyzer
Using an Arduino as a logic analyzer
Driving steppers with the RMT module
Using Nix to write rust on the esp32
Using a smooth stepper driver on the esp32 in rust
Translating an esp32+esp-idf bluetooth example to rust
Musings on packaging build system via splitting independent libraries

Using an ESP32 as a logic analyzer

7th article in Hanging Plotter
SoftwareEmbeddedEsp32
2020-3-31

Diagnosing stepper timing issues with another esp32

Unfortunately I have been running into issues with the stepper not rotating deterministically. Sometimes it will vibrate, sometimes it will spin clockwise, sometimes counterclockwise. This issue is related to synchronizing channels, which has been reported as a github issue

In order to approach this issue systematically I will use a logic analyzer. Since lead times are significant due to a current pandemic I will be utilizing another esp32 to capture data.

Logic Analysis?

Digital signals are a series of high/low values over time. The stepper driver requires synchronizing 4 digital channels over time in order to provide smooth movement. By capturing samples many times per second the precise times between high/low can be measured and compared.

Esp32 Sigrok

The github user Ebiroll has published the esp32_sigrok repo, which claims to be a sump compatible device which can interface with the sigrok software suite.

Installing pulseview on Nixos

Adding pulseview to shell.nix started with a core dump due to

$ pulseview
Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007fc63e821000 (most recent call first):
[1]    24318 abort (core dumped)  pulseview

Shell.nix includes setting PYTHONHOME, turns out that wasn't needed and by removing that value pulseview ran just fine

empty graphs and a menu bar with timing controls
Look at it go!

Setup

My initial desire is to set this device up to use USB rather than the default WIFI to capture, since this computer does not have a wireless card. I have edited app-config.h to resemble `

/// CHANGE CONFIGURATION HERE!!
#undef CONFIG_EXAMPLE_USE_TFT
#undef SUMP_OVER_UART
#define SUMP_OVER_UART 1
//#define  SCPI_ON_NETWORK 1
//#define  SUMP_ON_NETWORK 1
#undef  DEBUG_SUMP
//#define DEBUG_LOG_ENABLE 1
//#define OTA_RUN_SERVER 1

#define UART_TEST_OUTPUT 1
#define UART_OUTPUT_PIN 18
#define UART_RX_PIN 19

#define PULSE_PIN 17
#define RMT_PULSES 1
//#undef RMT_PULSES

#define RUN_IN_QEMU 0

Building

Using the previously configured environment I ran

$ idf.py build
...
cc1: some warnings being treated as errors
...
../main/ota_server.c:35:42: warning: passing argument 1 of 'ip4addr_ntoa' from incompatible pointer type [-Wincompatible-pointer-types]

To fix this I added the following to my shell setup:

export CFLAGS_COMPILE="-Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration"

Unfortunately two errors still stuck out:

../main/analog-testdata.c:250:13: error: implicit declaration of function 'i2s_write_bytes'; did you mean 'i2s_write_expand'? [-Werror=implicit-function-declaration]
...
../main/analog.c:187:5: error: implicit declaration of function 'esp_adc_cal_get_characteristics'; did you mean 'esp_adc_cal_characterize'? [-Werror=implicit-function-declaration]

I am using the v4.2 prerelease and according to some cursory searching esp_adc_cal_get_characteristics and i2s_write_bytes are deprecated.

-    esp_adc_cal_get_characteristics(V_REF, ADC_ATTEN_DB_0, ADC_WIDTH_BIT_12, &characteristics);
-
+    esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_0, ADC_WIDTH_BIT_12, V_REF, &characteristics);

+    size_t bytes_written;
-            i2s_write_bytes(EXAMPLE_I2S_NUM, (const char*) i2s_write_buff, i2s_wr_len, portMAX_DELAY);
+            i2s_write(EXAMPLE_I2S_NUM, (const char*) i2s_write_buff, i2s_wr_len, &bytes_written, portMAX_DELAY);

Without understanding exactly what is changing these look functionally similar and allows it to build

Locating

After building and executing sigrok-cli was run to scan for devices:

$ sigrok-cli -d ols:conn=/dev/ttyUSB0 -l 5 --scan
sr: [00:00.000000] log: libsigrok loglevel set to 5.
sr: [00:00.000016] backend: libsigrok 0.5.1/5:0:1 (rt: 0.5.1/5:0:1).
sr: [00:00.000036] backend: Libs: glib 2.62.5 (rt: 2.62.5/6205:5), libzip 1.6.0, libserialport 0.1.1/1:0:1 (rt: 0.1.1/1:0:1), libusb-1.0 1.0.23.11397 API 0x01000107, libftdi 1.4, librevisa 0.0.20130412.
sr: [00:00.000055] backend: Host: x86_64-pc-linux-gnu, little-endian.
sr: [00:00.000063] backend: SCPI backends: TCP, RPC, serial, VISA, USBTMC.
sr: [00:00.000067] backend: Firmware search paths:
sr: [00:00.000082] backend:  - /home/username/.local/share/sigrok-firmware
sr: [00:00.000088] backend:  - /nix/store/xbwknpb4165jvhw6sm8da3hnrg01jgb2-libsigrok-0.5.1/share/sigrok-firmware
sr: [00:00.000094] backend:  - /home/username/.nix-profile/share/sigrok-firmware
sr: [00:00.000101] backend:  - /etc/profiles/per-user/username/share/sigrok-firmware
sr: [00:00.000105] backend:  - /nix/var/nix/profiles/default/share/sigrok-firmware
sr: [00:00.000112] backend:  - /run/current-system/sw/share/sigrok-firmware
sr: [00:00.000130] backend: Sanity-checking all drivers.
sr: [00:00.000138] backend: Sanity-checking all input modules.
sr: [00:00.000143] backend: Sanity-checking all output modules.
sr: [00:00.000152] backend: Sanity-checking all transform modules.
srd: libsigrokdecode loglevel set to 5.
sr: [00:00.007146] hwdriver: sr_config_list(): key 2147418112 (NULL) sdi (nil) cg NULL -> [uint32 20000, 20001]
sr: [00:00.007156] openbench-logic-sniffer: Probing /dev/ttyUSB0.
sr: [00:00.007163] serial: Opening serial port '/dev/ttyUSB0' (flags 1).
sr: [00:00.007717] serial: Parsing parameters from "115200/8n1".
sr: [00:00.007757] serial: Setting serial parameters on port /dev/ttyUSB0.
sr: [00:00.007770] openbench-logic-sniffer: Sending cmd 0x00.
sr: [00:00.007784] serial: Wrote 1/1 bytes.
sr: [00:00.007788] serial: Draining serial port /dev/ttyUSB0.
sr: [00:00.007818] openbench-logic-sniffer: Sending cmd 0x00.
sr: [00:00.007838] serial: Wrote 1/1 bytes.
sr: [00:00.007843] serial: Draining serial port /dev/ttyUSB0.
sr: [00:00.007878] openbench-logic-sniffer: Sending cmd 0x00.
sr: [00:00.007889] serial: Wrote 1/1 bytes.
sr: [00:00.007893] serial: Draining serial port /dev/ttyUSB0.
sr: [00:00.007917] openbench-logic-sniffer: Sending cmd 0x00.
sr: [00:00.007927] serial: Wrote 1/1 bytes.
sr: [00:00.007929] serial: Draining serial port /dev/ttyUSB0.
sr: [00:00.007957] openbench-logic-sniffer: Sending cmd 0x00.
sr: [00:00.007967] serial: Wrote 1/1 bytes.
sr: [00:00.007972] serial: Draining serial port /dev/ttyUSB0.
sr: [00:00.008082] openbench-logic-sniffer: Sending cmd 0x02.
sr: [00:00.008092] serial: Wrote 1/1 bytes.
sr: [00:00.008097] serial: Draining serial port /dev/ttyUSB0.
sr: [00:00.018216] serial: Read 4/4 bytes.
sr: [00:00.018227] openbench-logic-sniffer: Sending cmd 0x04.
sr: [00:00.018240] serial: Wrote 1/1 bytes.
sr: [00:00.018246] serial: Draining serial port /dev/ttyUSB0.
sr: [00:00.028358] serial: Read 1/1 bytes.
sr: [00:00.028383] serial: Read 1/1 bytes.
sr: [00:00.028389] serial: Read 1/1 bytes.
sr: [00:00.028395] serial: Read 1/1 bytes.
sr: [00:00.028403] serial: Read 1/1 bytes.
sr: [00:00.028411] serial: Read 1/1 bytes.
sr: [00:00.028422] serial: Read 1/1 bytes.
sr: [00:00.028425] openbench-logic-sniffer: Got metadata key 0x01 value 'ESP32'.
sr: [00:00.028438] serial: Read 1/1 bytes.
sr: [00:00.028451] serial: Read 4/4 bytes.
sr: [00:00.028455] openbench-logic-sniffer: Got metadata key 0x20 value 0x00000008.
sr: [00:00.028470] serial: Read 1/1 bytes.
sr: [00:00.028480] serial: Read 4/4 bytes.
sr: [00:00.028484] openbench-logic-sniffer: Got metadata key 0x21 value 0x00002000.
sr: [00:00.028495] serial: Read 1/1 bytes.
sr: [00:00.028505] serial: Read 4/4 bytes.
sr: [00:00.028509] openbench-logic-sniffer: Got metadata key 0x23 value 0x00002710.
sr: [00:00.028519] serial: Read 1/1 bytes.
sr: [00:00.028530] serial: Read 1/1 bytes.
sr: [00:00.028534] openbench-logic-sniffer: Got metadata key 0x41 value 0x02.
sr: [00:00.028543] serial: Read 1/1 bytes.
sr: [00:00.028546] openbench-logic-sniffer: Got metadata key 0x00, metadata ends.
sr: [00:00.028549] openbench-logic-sniffer: Failed to set default samplerate (200000).
sr: [00:00.028555] serial: Closing serial port /dev/ttyUSB0.
sr: [00:00.028768] hwdriver: Scan found 1 devices (ols).
The following devices were found:
ols - ESP32 with 8 channels: 0 1 2 3 4 5 6 7
sr: [00:00.028796] hwdriver: Cleaning up all drivers.
sr: [00:00.028802] serial: Cannot close unopened serial port /dev/ttyUSB0.

Looks good to me!

Connecting

Let's try it out by selecting the connection dropdown and choosing the options

Choose the driver: Openbench Logic Sniffer (ols) Choose the interface: Serial Port /dev/ttyUSB0 Scan for devices Select the device: ESP32 with 8 channels

pulseview showing the option to connect to the esp32
So very gratifying to get things to communicate

Uh...

So it turns out I have one esp32 and one esp8266, and cannot logic analyze a device with itself. Time to use an alternative device!

PreviousNext
Featured Projects
GeneratorHandwheel Repair
Company Info
About UsContactAffiliate DisclosurePrivacy Policy
Specific Solutions LLC
Portland, OR