Install Argon One Case Script

Hi,

Beginner here…

If not in the right place, please move.

I followed THIS guide to turn a Raspberry Pi 4 into a webcam device I can give my parents so they can videocall with their granddaughter during this Corona crisis…

Works perfectly.

But the Pi4 runs pretty hot.
I have an Argon One case and even with the heatsinks, it gets pretty hot.
The case also has a controlable fan for which you need to install a script.
More info HERE on how to do that in Raspberry OS.

Since Raspberry OS wasn’t really working well for videocalling, I want to stick with BalenaOS.

But how can I install the script to control the fan?
I tried via the terminal in the BalenaCloud Dashboard, but curl https://download.argon40.com/argon1.sh | bash doesn’t work.

Any help?

thx.

Hey Dim - welcome to the forums and to balena!

It’s great to hear that balenaOS and this project is doing it’s job and keeping people connected during the pandemic.
The Pi4 will get warm, because it’s having to work pretty hard to decode the video stream from the call. This will be done in software, so the CPU will be earning it’s keep. Rest assured, though, the PI4 was designed to run hot, and will throttle itself to avoid damage. However adding a better case, and a fan, is a good idea nonetheless.

Now, onto your fan script.
The first thing that’s worth tell you, is that the services that run on a balena device (in this instance the ‘kiosk’ service that is running the browser window) are writeable, but only to their locally created filesystem layers, which only exist for the lifespan of the service. To put it another way, anything you change in the container whilst it’s running, will be reset when the container restarts. The container is recreated each time it starts up. So running the script you linked, even if it had worked, would only work until the service (or whole device) restarted. More details here.

In order to change one of the services permanently you actually need to change the dockerfile which creates it. If you’re up for some learning, this Dockerfile Masterclass would be a good read for you.
What you’ll then need to do is use the alternative method of deploying the code to the device (details here) which involves downloading the source code from Github and then using the balena CLI to push it to your balenaCloud application. And before you push it - you can make your changes. This is where you can add in a fan script - however there’s another issue:

Looking at the script you linked - it’s working in an odd way. Basically it is installing python, running Linux commands to write out some python code to the local filesystem and then setting it to run as a system service. This script isn’t going to work in a containerised application for a host of reasons.

What the python code is doing, if you were to get it installed, is set some pins on the Pi GPIO to control the fan. In order to do this yourself, you could add another service to the application starting with our Python-specific getting started guide and then look at what the script you linked is doing, and recreate the pertinent parts.

I appreciate you say you are a beginner, and that the above isn’t necessarily beginner level - but I’m afraid there isn’t an easy way to enable the fan on this case using balenaOS. Not yet.

Phil

2 Likes

Hi Phil,

thanks for the explanation.

I could probably learn how to add another service and change the dockerfile to control the fan, but I’m afraid the pandemic will be over by then… :slight_smile:

However, I checked the pre-installed board in the case, thinking I could maybe extend the wires of the fan to go to the outside GPIO pins. And act as a passive fan.
Apparently, it’s possible to set the fan to Always On on the board itself.
So I’ve changed that.
Now when the PI boots, the fan starts.
I’m going to try it like this for a while. If the noise of the fan starts to irritate, I’ll change it again.

Thx

Hey Dim,
Glad Phil’s explanation helped you out and hope the solution works for you. Let us know if you face any issues with it.

Vipul

1 Like

According to THIS thread, the fan is controlable with I2C commands.

But then I would need to enable I2c communication in the Dockerfile?
And then add a fan script. To have it booting to 50% speed for example.

Correct?

Hi, see here a forum post that explains how to set-up i2c for the rpi: Modprobe error when trying to enable i2c on rpi

1 Like

Yeah…sorry, but that didn’t really make me any wiser… :confused:
Again, beginner…

Need to do some more research.

In using balenaDASH, am I correct in assuming that “Deploy with Balena” (like in the tutorial) or getting the code from Github and using balenaCLI to push it to balenacloud and my device is the same?

If yes and if I want to set the fan speed to 50% for example, then I need to do the following, correct?
Download BalenaDash from Github, adapt dockerfile to upon boot, enable i2c, communicate a i2c command to set the fan speed to 50%, continue with the rest.

Now only need to figure out how to do that…
Like, how to set up and use balenaCLI, get code from Github, search for which file to change to enable i2c,…
All the basics. :slight_smile:

Hi there – in answer to your questions:

In using balenaDASH, am I correct in assuming that “Deploy with Balena” (like in the tutorial) or getting the code from Github and using balenaCLI to push it to balenacloud and my device is the same?

The end effect is the same; however, the “Deploy With Balena” button simplifies the process, as you don’t have to get the code from Github (“clone from Github” is the usual phrase) and use balenaCLI. The tradeoff is that the code you deploy is what’s already in the Github repo, rather than customized to meet your needs (in your case, to control the fan via i2c). To change the code, you will need to clone from Github, modify and deploy using the balenaCLI.

I need to do the following, correct? Download BalenaDash from Github, adapt dockerfile to upon boot, enable i2c, communicate a i2c command to set the fan speed to 50%, continue with the rest.

Yes, you’ve got the sequence generally correct. The link shared by Florin would come at the “enable i2c” step you described.

If you’re going through all of this for the first time, I would definitely suggest you go through our tutorials – they do an excellent job of taking you through deployment. For an introduction to working with git (“git clone” and so on), I’ll point you at Github’s Quickstart.

Give these a try and let us know how you get on!

All the best,
Hugh

1 Like

After reading the links and some more research, I’ve added io.balena.features.kernel-modules: '1' under labels in the docker-compose.yml

version: '2'
volumes:
  settings:
services:
  kiosk:
    restart: always
    build: ./kiosk
    privileged: true
    ports:
      - 8080:8080
    volumes:
      - 'settings:/usr/src/app/settings'
  scheduler:
    restart: always
    build: ./scheduler
    privileged: true
  wifi-connect:
    build: ./wifi-connect
    restart: always
    network_mode: host
    privileged: true
    labels:
      io.balena.features.dbus: '1'
      io.balena.features.firmware: '1'
      io.balena.features.kernel-modules: '1'
  photos:
    privileged: true
    restart: always
    build: ./photos
    ports:
      - "8888:8888"

Is that correct?

Next I would need to add modprobe i2c-dev in the dockerfile, but which one? The wifi-connect container one?

That looks like this:

FROM balenalib/%%BALENA_MACHINE_NAME%%

ENV INITSYSTEM on

RUN install_packages dnsmasq wireless-tools wget

WORKDIR /usr/src/app

RUN curl https://api.github.com/repos/balena-io/wifi-connect/releases/latest -s \

    | grep -hoP 'browser_download_url": "\K.*%%BALENA_ARCH%%\.tar\.gz' \

    | xargs -n1 curl -Ls \

    | tar -xvz -C /usr/src/app/

COPY ./start.sh .

CMD ["bash", "start.sh"]

Do I just put modprobe i2c-dev after CMD and before ["bash", "start.sh"] ? Can’t really find simple exact info on that…

Thanks beforehand for the help.
I understand that this must sound like “how much is 1+1” questions to you guys…

Hi. Just had a look at the containers in balena-dash and it looks like they should already have i2c-dev set-up. So in order to test your i2c fan, you could do a quick test manually from the dashboard. Just open a webterminal in either the photos or wifi-connect containers and run your i2cset commands from there to see if you can get the fan to start.

1 Like

Well bloody hell.
For some strange reason, I only tried i2cset -y 1 0x01a 0x64, which turns the fan fully on, in the Host OS terminal and Kiosk terminal. And got the result bash: i2cset: command not found

But it does work in Photos and Wifi-Connect.

Thanks.

I can control the fan with:

i2cset -y 1 0x01a 0x00 0
i2cset -y 1 0x01a 0x00 25
i2cset -y 1 0x01a 0x00 50
i2cset -y 1 0x01a 0x00 100

Or any other number.

Now, let’s say I want to have the fan at 50% upon start up.
Where exactly do I need to put i2cset -y 1 0x01a 0x00 50 ?
'Cause no clue… Photos or wifi-connect docker file?

Try putting it here after the export line

https://www.github.com/balenalabs/balena-dash/tree/master/wifi-connect%2Fstart.sh :

1 Like

Thx Phil.

I added i2cset -y 1 0x01a 0x00 50 after the export line, pushed it to the application and now the Pi boots up with the fan at 50%.
Stays around 40°C for ±2 hours of videocalling with Jitsi.

So works perfectly.

Thanks for the help everybody.

Hi. a newbie question.

I am trying to do this as well, but I will be running a node express service. Are there any tips to get this working?

Cheers,

Tim

Hello can you clarify what you want to do? You’d have balenaDash alongside another node express service?

Hi, yes sorry.

For example, I have the node “hello world” project running as a single service (https://github.com/balena-io-examples/balena-node-hello-world). I would like to now make sure the fan goes on etc. like described above. (for example just setting the i2cset)

Thanks in advance.

If the hello-world example is your base you need to load the i2c-dev kernel module using modprobe i2c-dev. Check our docs regarding this here https://www.balena.io/docs/learn/develop/hardware/i2c-and-spi/#i2c . Also if in the future to decide to add more services make sure you have io.balena.features.kernel-modules: ‘1’ in your docker-compose file under the service’s labels.

ok great, thank you for the quick support. I will try in the docker file method.

so once doing the the CMD modprobe i2c-dev && ["npm", "start"] for example, where do i now add after that the other commands e.g i2cset -y 1 0x01a 0x00 100 ? I ask because above they talk about adding it to a start.sh after the export line.

thanks!

Hi there – the simplest thing would be to amend your CMD line to include the commands you want to add:

CMD modprobe i2c-dev && i2cset -y 1 0x01a 0x00 100 && ["npm", "start"]

The double ampersands (&&) mean “only keep going if the last command succeeded”. In other words: if the modprobe command were to fail for some reason, i2cset and npm start would not run. You can add more commands as needed by adding them between the double ampersands:

CMD this && that && the other && something else && fourth thing && ...

After a while, though, this gets hard to read. One way around that is to break out the commands to a shell script, then have that as the CMD line. If you’re looking for help getting started in that, I would definitely recommend the Docker 101 tutorial.

All the best,
Hugh

Thanks Hugh, let me try it over the weekend and i will get back to you.