Skip to content

Conversation

jt-helsinki
Copy link
Contributor

When setting up the PiZero some of the documetation was a little out of date or unclear.

  • Fixed small spelling mistakes caught by codespell
  • Updated thge README.md with some formatting and spelling
  • Added Rapberry Pi OS setup instructions
  • Moved the install.sh script to /scripts to keep all shell scripts together
  • Renamed install.sh --> install_service.sh to make it clear what it does. It was a bit unclear before.
  • Created an initial_install.sh script to simplify the initial device setup. This should make setting up the Pi a bit easier as there are some issues with PyQt.
  • Documentation updates to reflect some of these changes.

@jt-helsinki jt-helsinki force-pushed the Setup-scripts branch 2 times, most recently from 57a62c7 to 81d3113 Compare June 1, 2025 05:54
@jt-helsinki
Copy link
Contributor Author

If I lint the project, I get MANY warnings/errors. So this check fails.

@hishizuka
Copy link
Owner

hishizuka commented Jun 2, 2025

Hi, @jt-helsinki
Thank you for your PR very much.

  • As you can see from my repository, the document images are not included to increase the repository size. I will upload the images on my end, so please let me substitute that URL.
  • I would like to correct the description of the Raspberry Pi Zero and Raspberry Pi Zero W as I will continue to include them in our support. Indeed, we recommend a 64-bit OS when using the Raspberry Pi Zero 2 W.
  • Thank you for creating the install command. This has been an inferior task for many years. I have not tried it yet, but I have one request and one question.
    • Please do not delete the install command from "software_installation.md". It is used as a reference for installing on SBCs other than the Raspberry Pi OS (Radxa, etc.).
    • Why install WireringPi? I have not used it explicitly until now. But, I did not know it was forked and updated. What are you using it for?

@hishizuka
Copy link
Owner

Can I modify it directly to your PR?

@jt-helsinki
Copy link
Contributor Author

jt-helsinki commented Jun 2, 2025

@hishizuka yes, please modify directly as you see fit. 👍

do not delete the install command from "software_installation.md"

+1 Please check now. Have put it back. Can you please check for correctness?

WireringPi

Good question. I was getting an error at some point but I think that was left over from that. I've removed those lines.

@jt-helsinki jt-helsinki force-pushed the Setup-scripts branch 2 times, most recently from be232de to 920e77d Compare June 2, 2025 09:53
* Fixed small spelling mistakes caught by codespell
* Updated thge README.md with some formatting and spelling
* Added Rapberry Pi OS setup instructions
* Moved the install.sh script to /scripts to keep all shell scripts together
* Renamed install.sh --> install_service.sh to make it clear what it does
* Created an initial_install.sh script to simplify the initial device setup
hishizuka and others added 2 commits June 2, 2025 20:59
delete a lot of spaces.
modify Stargazers.
Update initial_setup.sh with new libs and conditional libraries
@hishizuka
Copy link
Owner

hishizuka commented Jun 3, 2025

Hi, @jt-helsinki

  • .gitignore
    • Is “temp” in necessary? Why not "/tmp"? I don't use it and don't feel the need to add it.
  • scripts/initial_setup.sh
    • “# remove default directories for pi user.” Don't do this. I do not want to accept complaints of data being erased. Imagine that there are many people using this in different environments.
    • It is not appropriate to run all commands with root privileges. Only necessary commands should be followed by sudo.
    • Do not assume that the last wait time is also 10 seconds. The initial startup will take several minutes as the cython compilation runs. Perhaps you should create a boot option for the initial setup.

@hishizuka
Copy link
Owner

I also noticed that the req folder has not been updated at all. I will probably delete it. As it is now, it is wrong.
I'll fix it later, since you gave me the framework for the installation.

* wait for application to start
* removed directory deleting
* updated prompt functionality. Fixed quit bug
* renamed USER_HOME and USER variables to PI_USER_HOME and PI_USER
* small formatting issues
@jt-helsinki
Copy link
Contributor Author

Thanks for reviewing this. I think this is a starter for you (or others) to modify as you see fit. I don't know the software well enough to give a definitive script. I've created this based on my own setup which is from a clean Raspberry Pi Zero 2 W. There is quite a bit involved with setting up and a lot of docs to read through so hopefully this makes it easier.

.gitignore

Even if this is not used it would be very nice to have a working scratch folder that is ignored. I don't want to risk checking in this directory. Yes, renaming to tmp is a good idea.

If I do this on my own fork and then branch and PR to the main repo, the entry will come across. It's just easier if it's in the main repo.

“# remove default directories for pi user.”

Yes, removed that.

root privileges.

Yes, I agree that's confusing. I've used:

USER_HOME="$(eval echo "~$SUDO_USER")"
USER="$SUDO_USER"
...
sudo -u "$USER" "$USER_HOME/.venv/bin/pip3" install git+https://github.com/hishizuka/openant.git`

This should run the pip command as pi user and home as /home/pi. I have renamed the USER_HOME and USER variables to PI_USER_HOME and PI_USER to make this clearer in the script.

Do not assume that the last wait time is also 10 seconds.

Right! Have changed this to wait for the Drawing components: log output. This is right near the end. Added a 10s wait on top of this. To allow any extra output to finish. I think that should be sufficient. What do you think?

req folder

These files do get the application installed as is even if they are wrong. Can this be left for now and updated later?

@hishizuka
Copy link
Owner

Thank you for your comment.
I will try and fix the setup script here as well.
Please be patient.

@hishizuka
Copy link
Owner

hishizuka commented Jun 9, 2025

Hi,

Yes, renaming to tmp is a good idea.

Sorry, I meant to say /tmp, not $HOME/pizero_bikecomputer/tmp.
If you are placing temporarily, use modules/test_code.

@jt-helsinki
Copy link
Contributor Author

jt-helsinki commented Jun 9, 2025

If you are placing temporarily, use modules/test_code.

tmp/ is not for application code. In my case, I have scripts which are specific to my own workflow that you will 100% not want in the repository. tmp/ would be a better way for this.

@hishizuka
Copy link
Owner

Hi,

have you looked at .gitignore?
modules/test_code is already included in .gitignore.

This directory is already used to contain programs and scripts that you don't want to publish, as you point out.

Think of it as tmp/ that you want to add renamed modules/test_code.

I do not want more directories with duplicate roles.
Someone who sees the code will point it out in the future and I will have to answer responsibly.

@jt-helsinki
Copy link
Contributor Author

OK, fair enough. I will remove.

@hishizuka
Copy link
Owner

hishizuka commented Jun 9, 2025

Sorry, I don't want to create something like the req directory, where someone who is not me commits work at the time and increases my maintenance.
Please understand.

I will delete req dir as it contains a lot of inappropriate content.

@jt-helsinki
Copy link
Contributor Author

Yes, sure. I have been receiving an error that _exec() is not a function. Apparently this has been renamed to exec(). That upgrade fixes that (in my environment) but if it's not right then yes, please remove.

@hishizuka
Copy link
Owner

Yes, qasync was forced to modify gui_pyqt.py when it moved up from that version, so if you put in the old qasync before the modification, as in this case, it will naturally not start.

Fixed versions have advantages and disadvantages, but I believe it will work for the worse in this project.

I think it would be better to run the installation script you provided, which is what we intend to do. Please wait a little longer.

@hishizuka
Copy link
Owner

hishizuka commented Jun 10, 2025

Hi, @jt-helsinki

I have made significant modifications to initial_setup.sh. There are still a few parts missing.

  • I want to split a script and change the order of processing.
    • Install packages with apt.
    • Create a python virtual environment and activate it.
    • Install packages with pip.
    • Modify config.txt , activate the services.
    • Reboot.
    • Run the program on a trial run.
  • The last thing to do is to run the trial, but do not kill it. This is because the various configuration files will not be written out until config.quit() is executed. Add a runtime option for the first startup, or start with the --headless option, and when 'Drawing components:' is detected, send q to the standard input and execute config.quit().

@jt-helsinki
Copy link
Contributor Author

jt-helsinki commented Jun 10, 2025

@hishizuka This looks good and is a nice improvement.

I ran the script on a fresh Raspian install on pi zereo 2 WH. Selected "y" for all components to install.

Would it be worth reducing the verbosity of the warnings? These look like errors but not really. This might throw the users off. I don't think it shoud be swallow the messages but maybe there is a switch to change the log level? It's not a big deal but might be worth considering.

The script ran nicely until the end where the error was ./scripts/initial_setup.sh: line 198: INPUT_PIPE: unbound variable. See below.

🔧 Starting pizero_bikecomputer.py in headless mode for verification...
########## INITIALIZE START ##########
Raspberry Pi Zero 2 W Rev 1.0(), serial:3B67E28B
Initialize modules:
config import : 1.632 sec
config init : 0.029 sec
display import: 0.013 sec
display init : 0.000 sec
import gui : 4.555 sec
import logger : 0.166 sec
total : 6.395 sec
########## INITIALIZE END ##########
Qt version: 6.4.2 (PyQt6)
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting mmh3
Downloading mmh3-5.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (102 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 102.6/102.6 kB 600.7 kB/s eta 0:00:00
Installing collected packages: mmh3
Successfully installed mmh3-5.1.0
In file included from /home/pi/.pyxbld/temp.linux-aarch64-cpython-311/pyrex/modules/logger/cython/logger_fit.cpp:762:
modules/logger/cython/logger_fit_c.hpp:68:12: warning: ‘int parse_single_str(void*, int, char**, char**)’ declared ‘static’ but never defined [-Wunused-function]
68 | static int parse_single_str(void user_data, int argc, char argv, char azColName);
| ^~~~~~~~~~~~~~~~
modules/logger/cython/logger_fit_c.hpp:69:12: warning: ‘int parse_single_num(void
, int, char
, char
)’ declared ‘static’ but never defined [-Wunused-function]
69 | static int parse_single_num(void user_data, int argc, char argv, char azColName);
| ^~~~~~~~~~~~~~~~
modules/logger/cython/logger_fit_c.hpp:76:12: warning: ‘int parse_records_message_num_18_19(void
, int, char
, char
)’ declared ‘static’ but never defined [-Wunused-function]
76 | static int parse_records_message_num_18_19(void user_data, int argc, char argv, char azColName);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
modules/logger/cython/logger_fit_c.hpp:77:12: warning: ‘int parse_records_message_num_20(void
, int, char
, char
)’ declared ‘static’ but never defined [-Wunused-function]
77 | static int parse_records_message_num_20(void user_data, int argc, char argv, char azColName);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
modules/logger/cython/logger_fit_c.hpp:38:15: warning: ‘epoch_datetime_sec’ defined but not used [-Wunused-variable]
38 | static time_t epoch_datetime_sec;
| ^~~~~~~~~~~~~~~~~~
modules/logger/cython/logger_fit_c.hpp:20:26: warning: ‘local_message_num’ defined but not used [-Wunused-variable]
20 | static int message_num, local_message_num;
| ^~~~~~~~~~~~~~~~~
modules/logger/cython/logger_fit_c.hpp:20:13: warning: ‘message_num’ defined but not used [-Wunused-variable]
20 | static int message_num, local_message_num;
| ^~~~~~~~~~~
/home/pi/pizero_bikecomputer/modules/logger/cython/logger_fit_c.cpp:279:12: warning: ‘int parse_single_str(void
, int, char
, char
)’ defined but not used [-Wunused-function]
279 | static int parse_single_str(void *user_data, int argc, char **argv, char **azColName) {
| ^~~~~~~~~~~~~~~~
detected sensor modules:
GPS (GPSD/GPS3)
ANT
GPIO
I2C
detected ANT+ sensors
SCAN
SEARCH
detected I2c sensors:
[sensor] Initialize:
ANT+ : 1.476 sec
I2C : 0.467 sec
total: 1.944 sec
Drawing components:
misc : 0.059 sec
import: 1.247 sec
menu : 2.151 sec
main : 9.193 sec
total : 12.651 sec
delay init: 178.706 sec
ℹ️ 'Drawing components:' detected. Waiting 10s...
./scripts/initial_setup.sh: line 198: INPUT_PIPE: unbound variable

@jt-helsinki
Copy link
Contributor Author

@hishizuka Yes, this fix worked on my mac. Very nice.

It would be nice to prompt for the virutalenv at the start of the script so that there is no user interaction half way through. This way, the script can be left to run and I can come back after it's finished.

@hishizuka
Copy link
Owner

There are still a few parts missing. "❌" needs to be corrected. Do you have an idea?

  • I want to split a script and change the order of processing.
    • ⭕️Install packages with apt.
    • ⭕️Create a python virtual environment and activate it.
    • ⭕️Install packages with pip.
    • ⭕️Modify config.txt , activate the services.
    • ❌Reboot.
    • ❌Run the program on a trial run.
  • ❌The last thing to do is to run the trial, but do not kill it. This is because the various configuration files will not be written out until config.quit() is executed. Add a runtime option for the first startup, or start with the --headless option, and when 'Drawing components:' is detected, send q\n to the standard input and execute config.quit(). INPUT_PIPE is my trial and error mark. I removed it.
  • (new) The cython warnings are another issue, you need to fix logger_fit_c.hpp.

@jt-helsinki
Copy link
Contributor Author

jt-helsinki commented Jun 10, 2025

but do not kill it.

Possibly have a switch on the command line to --quit-on-start? OR --write-state-on-startup? This way you could kill the process and still have the files?

I think the reboot won't be possible unless you have a Virtual machine.

For the trial run, if the script is already starting the app, that might be enough?

@hishizuka
Copy link
Owner

Hi, @jt-helsinki

Like homebrew, it can be installed with a single command after ssh login. It can also be re-run later.

Now all I need to do is to incorporate it into /boot/firstrun.sh and it will be perfect. Any good ideas on how to make this work?

Stopping and restarting the program at the end of the script has not yet been improved.

@jt-helsinki
Copy link
Contributor Author

jt-helsinki commented Jun 13, 2025

I've just installed on a fresh system (new Raspian image) and it's a very smooth running script. Startup after install was no issue.

Some ideas for possible solutions:

  1. a command line switch which turns on the generation of the config files at start up time. I don't see how you will do this otherwise.
  2. write the config files if they don't exists when you try read them in at startup. That would be totally transparent to the user and script so it might be the best way.
  3. Write a "startup status" file and keep writing the status to this file. The script reads the file and when the file gets to "done" the program can kill it.
  4. An http endpoint that is enabled with a command line switch. If you call the endpoint the program will exit.
  5. Signal handlers which listen for kill -2 <pid> and do a final clean up. I think. you are already doing this so you can run kill -2 and tha should work right? Need the clean up code.

Option 5 is probably best as it seems this is already in the code base and would require minimal changes. Is this workable?

@hishizuka
Copy link
Owner

Hi @jt-helsinki ,
I modified software_installation.md.
Sorry, but it is not appropriate to devote a large percentage of the execution by VNC to the first part of the process, so I have revised the position.

Can the added png files be deleted? Also, can the changes in reqs/full.txt be deleted?
If the above can be accomplished, I will merge.

If there is a time delay, I will import directly into master.

@hishizuka
Copy link
Owner

I have merged.
The Raspberry Pi setup is lacking in content and will be added soon.

@hishizuka hishizuka closed this Jun 21, 2025
@jt-helsinki jt-helsinki deleted the Setup-scripts branch June 24, 2025 06:01
@jt-helsinki
Copy link
Contributor Author

@hishizuka sorry for the delay coming back on this. I have been on a small break. :)

I tried doing this against the instructions. This is working very nicely. I think the message "✅ pizero_bikecomputer initial setup completed successfully! Please reboot." is a good way to solve the problem of the initial startup however the config files are not written. Not sure if this is really a big issue.

The "install_service.sh" script is missing from the docs. I suspect this is run after the inital reboot? Should I add instructions for this in?

In another PR, would it be worth trying to support Raspian without the desktop environment? This would reduce the OS footprint and there is a lot of stuff which gets updated which is not needed.

@hishizuka
Copy link
Owner

hishizuka commented Jun 25, 2025

Hi @jt-helsinki
All but the service was modified.
Services will be integrated in due time.

Edit:
merged. I will think some more about what should be an automatic reboot.

The Raspberry Pi installation documentation will come much later, as there are many details to be added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants