Repository navigation
[Bug] Edited code on PlatformIO produces print issues, even though Pybricks tools are used. #2791
Description
I decided to try PlatformIO as the editor for the current CityHub project, basically to create 7 smallish modules for 1600 lines of code, rather than one massive code block. Definitely worth the effort to switch across and gaining Source Control was also a bonus.
The Pybricks compiler and uploader were set-up and hooked into keyboard shortcuts. It has worked well for the past 3 months.
[Bug]
One bug found today is with the print statement and the use of end=''
It seems the print function print(".", end='') does not print the character immediately but buffers the print instead. The code was printing one "." every 250mS during a BLE scan but the code didn't show any dots until the final print(".") was executed.
I then ran this equivalent test program on the PybricksIDE and all was well.
print("A", end="")
wait(1000)
print("B", end="")
wait(1000)
print("C", end="")
wait(1000)
print("D")
The same code on the PlatformIO fails and the ABCD prints only after the third wait(1000), and not as each print is executed.
This is the compile.BAT file in PlatformIO
@echo off
cd /d "%~dp0micropython"
set MPY="%USERPROFILE%\.platformio\penv\Lib\site-packages\mpy_cross_v6\mpy-cross.exe"
if not exist mpy mkdir mpy
%MPY% main.py -s main.py -o mpy\main.mpy
%MPY% system.py -s system.py -o mpy\system.mpy
%MPY% radio.py -s radio.py -o mpy\radio.mpy
%MPY% ports.py -s ports.py -o mpy\ports.mpy
%MPY% flash.py -s flash.py -o mpy\flash.mpy
%MPY% decoder.py -s decoder.py -o mpy\decoder.mpy
%MPY% core.py -s core.py -o mpy\core.mpy
echo.
echo ==============================
echo MPY FILE SIZES
echo ==============================
dir /-C mpy\*.mpy
exit /b 0
This is the platform.ini
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:genericSTM32F413CG]
platform = ststm32
board = genericSTM32F413CG
framework = arduino
extensions.json
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
settings.json
{
"python-envs.defaultEnvManager": "ms-python.python:system",
"python.analysis.extraPaths": ["."],
"python.analysis.stubPath": "./pybricks",
"python.analysis.typeCheckingMode": "off",
"python.analysis.diagnosticSeverityOverrides": {
"reportMissingImports": "none",
"reportUndefinedVariable": "none",
"reportUnknownMemberType": "none",
"reportUnknownArgumentType": "none",
"reportUnknownParameterType": "none"
}
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Pybricks upload main.py",
"type": "shell",
"command": "C:\\Users\\Peter\\.platformio\\penv\\Scripts\\pybricksdev.exe",
"args": [
"run",
"ble",
"${workspaceFolder}/micropython/main.py"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$python"
},
{
"label": "Pybricks Compile Check",
"type": "shell",
"command": "${workspaceFolder}\\pybricks_compile_check.bat",
"problemMatcher": [],
"presentation": {
"reveal": "always",
"panel": "new",
"showReuseMessage": false,
"clear": true,
"close": false
}
}
]
}
I have done the usual reboot /new batteries etc but couldn't shake the issue. Hub memory is running around 880 bytes free.
Activity
dlech commentedon Aug 21, 2026
Does it make a difference if you set the
PYTHONUNBUFFERED=1environment variable when runningpybricksdev?toyotafj40 commentedon Aug 21, 2026
Hi David, I tried with PYTHONUNBUFFERED=1 but no joy.
I also found a similar 'non-compatibility' bug with the BLERadio and turning OFF the transmitter.
This works as expected in PybricksIDE.
The transmitter stops after sending the data.
This is the code on the PlatformIO
The transmitter does not stop after 200mS.
Here is the project folder for platformIO, for the original bug. You will need to edit the JSON pathnames after installing PlatformIO.
print_end_bug.zip