Grow Hat code problem with settings file

Hi all,

Please be gentle, first post of a newbie trying to get into all this stuff.

So to start, I have a Pi zero with a Grow Hat on it and a (don’t think it’s relevant but) UPS hat underneath (which is working great). This is destined for someone who is less geeky than me.

I’ve not done any Python programming before but I think I get the general idea.

I’m hoping to alter the existing program in a few ways but I’m stumbling over at the initial stages. I eventually managed to narrow down the problems I was having altering the code to the config file the GROW code uses.

I have noticed that simply copying the settings file /etc/default/grow to some directory and then back again, overwriting the original, causes everything to stop working properly (just one channel seems to operate after this). I’m just using a straight copy with the commands below;

sudo systemctl stop grow-monitor.service
sudo cp /etc/default/grow grow.backup
sudo cp grow.backup /etc/default/grow
sudo systemctl start grow-monitor.service

Is there anything wrong with this? Am I screwing up the settings file by doing this? Should I be using another command?

I’m just trying to backup the config file so I can revert to normal if my code tinkering causes problems.

Many thanks

If your just backing the file up, copying it to another folder, you only need the one copy command.
You don’t need to do the,
sudo cp grow.backup /etc/default/grow
I don’t know if that’s your issue, but its an unneeded step.

Hi, thanks for the response, but it’s not my issue.

The problem is that doing the above causes the whole system to fail, I was just using the commands to highlight the issue.

If I can’t copy the file to back it up and then restore it without ‘breaking’ it somehow, then there’s no point backing it up in the first place.

uninstalling and reinstalling from scratch is getting tiresome so I was backing up the main files to fix what I was breaking whilst altering the program.

OK, it gets weirder.

So, any change to that settings file in /etc/default/grow causes the following problem after restarting the grow-monitor service:

Only channel 1 pump operates, all other pumps stop operating, everything else seems normal. No changes to settings from the panel will alter the fact that pumps 2 and 3 no longer operate.

Uninstalling the entire program and then copying the original program back to /Pimoroni/grow-python/ and then altering the file that writes the original /etc/default/grow settings file ( /Pimoroni/grow-python/examples/settings.yml) in any way will cause the original fail scenario.

This makes no sense to me, I would expect to be able to alter any of the original setup parameters in the file that is setting up those parameters since that is how it is done in the first instance!

I’m getting really confused by this as my original problem was that I could not alter the monitor-grow.service program in any way without causing the initial fail scenario, and I was first thinking I had a faulty board. Eventually I traced the whole problem to altering the settings file, which I now need to fix before I can move on with altering the program to do what I want it to, as I have no confidence that things will work the way I expect them to.

I should add that I am only making changes that are allowable within the parameters of the grow-monitor python program.

Just to be clear, I have more than 25 years experience working in the mainframe world and this is my first try at mucking around in the Raspberry Pi and Python world.

Thanks all.

What editor are you using and what changes are you making?
Code tags are three ` at the top and three more at the end.

Hi, I’m using nano to edit the settings file, but I’ve found that just using cp to backup the settings.yml file also screws things up when I re-write the original file, which is pretty odd I thinks :(

The changes I am making are just altering the existing numerical parameters within their program confines.

Could I ask you what you mean by code tags in this context please?

I should add here that I am now (within the last few minutes) only needing to understand what is happening here to further my understanding of the Linux and Pi/Python world, since I have managed to make the alterations I need to the original program, without screwing things up totally :)

So, the grow-monitor.service starts with the following in the [service] section

ExecStart=/usr/bin/grow-monitor /etc/default/grow

grow-monitor being the python script which I have now successfully altered

etc/default/grow being the settings file it reads in order to keep any parameter changes you make from the input panel on the grow hat

changing the settings file in any way, including the original setup of this file, makes the grow hat fail by making only pump 1 work.

In python files indents etc are a big deal. If you use code tags when posting python code it will retain the formatting / indents etc. For example

def ledtemp():
    if sensor.get_sensor_data(): 
        t = 
        t = round(t)
    if t >= 41:                                        # Realy Hot 
        set_multiple_pixels(range(0,28), 255, 0, 0)    # Red
        M = (t - 68) * (-1)
        # R R R R R R R R R R R R R R R R R R R R R R R R R R R R
    elif t >= 13 and t <= 40:                          # Main
        set_multiple_pixels(range(0,11), 255, 0, 0)    # Red
        set_multiple_pixels(range(11,16), 255, 140, 0) # Orange
        set_multiple_pixels(range(16,28), 0, 255, 0)   # Green
        M = (40 - t)
        # R R R R R R R R R R R O O O O O G G G G G G G G G G G G
    elif t >= -15 and t <=12:                          # Cold 
        set_multiple_pixels(range(0,12), 255, 255, 0)  # Yellow
        set_multiple_pixels(range(12,28), 0, 0, 255)   # Blue
        M = (12 - t)
        # Y Y Y Y Y Y Y Y Y Y Y Y B B B B B B B B B B B B B B B B
    elif t < -15:                                      # Really cold
        set_multiple_pixels(range(0,28), 255, 255, 255)  # White
        M = ((t + 16) * (-1))
        # W W W W W W W W W W W W W W W W W W W W W W W W W W W W
    ledshim.set_pixel(M, 0, 0, 0)

thanks, sorry but I may be being a bit dense here, I was looking for the three ’ you mentioned, are the code tags the # comments in your example, how do they enforce the indents?

I’ve already fallen over the indents problem in a big heap on the floor from my original altering of the Python code :) but not sure how the tags are related here.

I appreciate your attempt to help my feeble brain understand

I don’t own a grow hat, just so you know. I have tinkered around with Enviro+ code and a tiny bit of config file edits with nano. Something like what your doing only mine was with the Plasma software. And to my VU meter on my Pirate Radio, on that I had to do some extra steps.

To increase the sensitivity on the Phat Beat VU Meter do the following:
cd Pimoroni/pivumeter
nano src/devices/phat-beat.c
Change line 88 to:
int bar = (meter_level * (meter_level / 8) / 131071.0f) * (brightness * (NUM_PIXELS/2));
Recompile the library:
sudo make
sudo make install
sudo reboot

ah roit, I see.

Thanks for your help, you have now peeked my interest in Pirate Radio, I’m easily distracted…

On my keyboard (English US) its the key right under the Esc key, and to the left of the 1 key. It has a ~ on top and the ` under it. You press it three times, past your code under it, then hit it three more times under your code. It will then put it in a code block.

ah, ooh, interesting.

Do you mean in nano?

I’m going to have to do a bit more research on that I think, as I’m using a MacBook terminal to ssh to my Pi, it doesn’t work the same.

I have been toying with the idea of doing this properly in an IDE, like visual studio, maybe that would help…

still don’t understand why an unedited file, written over itself screws up the whole program, hopefully the developers read these forums?

I have no idea why your having the issue your having? My skill level in Python is average maybe average+, and just barely above Noob in Linux.
I use the Thonny IDE for Python and Micro Python. I can use it to code for a Pi or a PICO. And I use nano for editing text files and system files.

I use Putty to SSH into my Motion Eye OS camera setups. I log in as root, so no need to use sudo. I actually get an error message if I use sudo.

When I post code here, I clip and past it from Thonny to my thread, then put the code tags around it. It depends on the forum software, some that I go to have a “code” button / option. This forum doesn’t and I had to be told how to do it by someone else. I think it was Phil @gadgetoid that clued me in. Hel @hel is also staff. Type @ in your post and you get who you can notify. Type @a and I will be in the list, click me and I get a notification e-mail with a link to that post in that thread that you @ me. I only do it when somebody is really stuck with a problem. Like you are now.

Thanks, much appreciated.

I shall have a play with Thonny and see what I come up with.

Ah, I see, the code tags you are referring to are the ones that format the text on


At least I think that’s what you meant…

Ahoy @confuserated !

I’ve not come across this issue while playing with Grow, as @alphanumeric says, if you could post the contents of your settings file that might be helpful (yes, the ``` is forum formatting!)

We’ve deliberately made it so that all the pumps don’t fire at once in the Grow monitor, as three pumps running at once can cause quite a bit of voltage drop - is it possible that the first one’s firing when the monitor restarts, and then it’s waiting for the auto watering delay time before the next watering?

Ahoy there yerself Hel,

Well, I can produce the problem easily enough without doing any edits.

If I cp the /etc/defaults/grow file to my home dir from a fresh install and then cp it back over the existing one, when I restart the grow-monitor service, only 1 channel works, the others no longer function. Which is odd methinks me hearty.

I will double check the process again myself later today, as I’m now doubting this makes any sense, but, as I’ve already done this, I’m sure it fail in the same way.

As an aside, I’ve run into timing issues already by extending the amount of time the pumps can run for to ten seconds, but that’s no problem since when the plant pot is full, it allows the other pumps to have their turn.

As I’m trying to add other functionality to the control panel, I don’t suppose there’s any documentation for how the program is structured is there? Or is this so simple to proper python programmers that it’s self explanatory?

Thanks, confuserated…