Tuesday, May 13, 2025

USB current/energy meter

$4.79 (+shipping and tax for $7.23 total) Shenzhen Rongbo Jiachuang Technology Co, before the tariff was imposed on the Chinese goods.


The device draws about 22mA by itself.  There is 0.2-Ohm resistance between the input and the output.  The current measurements seem to have about -10mA offset, which is a large error in the low current measurements; above 200mA, the measurement error is less than 5%.  It may have calibrated at around 0.5A, the common USB port current.

Fluke 87USB meter
0.0070.00
0.0310.02
0.0390.03
0.0630.05
0.0990.09
0.1420.13
0.2050.20
0.4670.47
0.9030.92
1.4381.47
2.1462.17

The voltage measurements have 30-40mV offset.  And there is some sort of data manipulation, the voltage measurements do not update consistently.

It is a good enough for casual USB power measurements.


Friday, May 9, 2025

MicroPython On STM32F429 Discovery

We try out MicroPython on STM32F429 Discovery kit.  We pull the MicroPython v1.25.0 source code from github.  

First `make -C mpy-cross` to build MicroPython cross compiler.

Then in ports/stm32, `make BOARD=STM32F429DISC submodules` to pull in libhydrogen, micropython-lib and stm32lib.  

We need the GNU compiler  arm-none-eabi-gcc; we use GCC version 13.3.1  from STM32CubeIDE 1.18.1.  `make BOARD=STM32F429DISC` to build.  The size of the firmware is about 320KB.  STM32F429 has 2MB Flash.

We use stlink to flash; we build stlink v1.8.0 from the source.   We need to specify the USB device ID, `export STLINK_DEVICE="0483:374b"` and `make BOARD=STM32F429DISC deploy-stlink` to download.  openocd can also be used.

Connect to the STLINK USB serial port with minicom -D /dev/ttyACM0

>>> MicroPython v1.25.0 on 2025-04-24; F429I-DISCO with STM32F429

Type "help()" for more information.

We can turn on the red LED with pyb.LED(1).on().

Connecting to the micro USB port, we get another serial device /dev/ttyACM1 and a storage device of 240KB.  There is one 112KB FAT partition on the storage device; the partition has the python scripts, 'boot.py' and 'main.py', which are executed at the start.  We can edit the files (like printing a message) and CTRL-D to restart.  We can the output.   Connecting to /dev/ttyAMC1, we also get a REPL console.  The output goes to both serial ports.

Next we want to do something with the 3-axis gyro (I3G4250D) and the 240x320 LCD (ILI9341).