Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Duet 3 SBC : SBC Temperature Sensor

    Scheduled Pinned Locked Moved
    General Discussion
    3
    12
    521
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Donpiundefined
      Donpi
      last edited by

      Hi all.

      I'am nearly done with my installation, thank everyone for the help.

      Nevertheless I still have questions 😛

      Actually I use this code to coul down the Duet :

      M308 S2 Y"drivers" A"DRIVERS" 
      M308 S3 Y"mcu-temp" A"MCU" 
      
      M950 F2 C"out9" Q100                        
      M106 P2 S1 H2:3 L0.15 X1 B2 T40:70
      

      I was wondering il there is a way to do the same for the SBC ?

      Bye
      Juan

      1 Reply Last reply Reply Quote 0
      • A Former User?
        A Former User
        last edited by A Former User

        afaik you'd have to run a script on the SBC to read out the temp and use some voodoo to control the fan from the Duet.

        simplest would be something like

        if [ $(cat /sys/class/thermal/thermal_zone0/temp) -lt 45000 ]; then echo M106 Pn S0 | sudo /opt/dsf/bin/CodeConsole ; else echo M106 Pn S1 | sudo /opt/dsf/bin/CodeConsole; fi;

        Donpiundefined 1 Reply Last reply Reply Quote 0
        • Donpiundefined
          Donpi @A Former User
          last edited by

          @bearer Hoo sorry I'am very new to Linux and all this.
          Can you explain me that like if I was totally stupid ?

          1 Reply Last reply Reply Quote 0
          • A Former User?
            A Former User
            last edited by A Former User

            I can try to explain it like I'm not stupid enough to assume everyone is a linux wizard instead..?

            The temperature is available on the pi, in a "file" called /sys/class/thermal/thermal_zone0/temp the value is in thousands degrees celcius, i.e. 40000 is 40°C.

            So reading from this file we can access the current temperature, cat /sys/class/thermal/thermal_zone0/temp will print the temp if you run it in a (ssh) shell.

            Lets say you use fan 3, so M106 P3 S1 will turn on the fan, and M106 P3 S0 will turn it off, from the shell we can send this to the duet by using the program /opt/dsf/bin/CodeConsole. This requires (or required at the time of writing) root access so lauch it by sudo /opt/dsf/bin/CodeConsole then you can type in M106 P3 S1 to turn on a fan.

            To simplify you can run the command echo M106 P3 S1 | sudo /opt/dsf/bin/CodeConsole that sends the text to the program all in one go.

            Putting it all together we can test the temperature value and send the command to turn on or off the fan as we please.

            if [ $(cat /sys/class/thermal/thermal_zone0/temp) -lt 45000 ]; then 
              echo M106 P3 S0 | sudo /opt/dsf/bin/CodeConsole; 
            else
              echo M106 P3 S1 | sudo /opt/dsf/bin/CodeConsole;
            fi;
            

            Is the same as I posted, but broken up in several lines to make it easier to read. We can then put it inside a loop and make this test over and over and over and over and over.

            #!/bin/bash
            while (true) do
              if [ $(cat /sys/class/thermal/thermal_zone0/temp) -lt 45000 ]; then 
                echo M106 P3 S0 | sudo /opt/dsf/bin/CodeConsole; 
              else
                echo M106 P3 S1 | sudo /opt/dsf/bin/CodeConsole;
              fi;
              sleep 5
            done
            

            Put that in a file called duetfan.sh, make it executable chmod +x duetfan.sh and run it with ./duetfan.sh

            I'll see if I can't find the time to make a systemd unit to make it run in the background and start/stop with DSF over the weekend, but hopefully that was a little clearer.

            edit changed the logic to test if the temperature is less than 45°C to turn the fan off - as this would turn the fan on if there is a unknown problem.

            Donpiundefined 1 Reply Last reply Reply Quote 2
            • Donpiundefined
              Donpi @A Former User
              last edited by

              @bearer Haha thank you verry mutch ⛏
              Everything is clear 🙂

              1 Reply Last reply Reply Quote 0
              • A Former User?
                A Former User
                last edited by

                I assumed you wanted to control a fan on the Duet?

                (You could in theory control a fan attached to the Pi but it would either require something like the fan shim or custom wiring and a transistor. Fan shim seems pretty neat in any case, but I don't have first hand experience with it)

                Donpiundefined 1 Reply Last reply Reply Quote 0
                • Donpiundefined
                  Donpi @A Former User
                  last edited by

                  @bearer Yes you are right my intent is to control the fan from the Duet.

                  My problem is that the PI has many difficulties to catch the wifi. And I noticed that moving it a little ( 3 or 4 cm ) does a great difflerence.
                  In my printer the Pi si in a case that make the wifi even harder to catch.
                  So I was in search of a solution outside of th pi to let it as free as possible.

                  But the Fan shim looks good ans small enougth.
                  Maybe I'll try it.

                  1 Reply Last reply Reply Quote 0
                  • A Former User?
                    A Former User
                    last edited by A Former User

                    figured the fan shim would have a systemd script handy, and boy did they. modified to suit and made the fan script parametric as well.

                    duetfan.sh

                    #!/bin/bash
                    DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
                    TEMP=45000
                    DELAY=5
                    FAN=-1
                    POSITIONAL_ARGS=()
                    USAGE="$0 --fan <n> --temp [n] --delay [n]" 
                    while [[ $# -gt 0 ]]; do
                        K="$1"
                        case $K in
                        -t|--temp)
                            TEMP="$2"
                            shift
                            shift
                            ;;
                        -d|--delay)
                            DELAY="$2"
                            shift
                            shift
                            ;;
                        -f|--fan)
                            FAN="$2"
                            shift
                            shift
                            ;;
                        *)
                            if [[ $1 == -* ]]; then
                                printf "Unrecognised option: $1\n";
                                printf "Usage: $USAGE\n";
                                exit 1
                            fi
                            POSITIONAL_ARGS+=("$1")
                            shift
                        esac
                    done
                     
                    set -- "${POSITIONAL_ARGS[@]}"
                    
                    if [ ! -z $FAN ] && [ $FAN -ge 0 ] && [ $FAN -le 8 ]; then
                      while (true); do
                        if [ $(cat /sys/class/thermal/thermal_zone0/temp) -lt $TEMP ]; then
                          echo M106 P${FAN} S0 | sudo /opt/dsf/bin/CodeConsole;
                        else
                          echo M106 P${FAN} S1 | sudo /opt/dsf/bin/CodeConsole;
                        fi;
                        sleep $DELAY
                      done
                    else
                      echo $USAGE
                    fi
                    

                    duetfansystemd.sh:

                    #!/bin/bash
                    DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
                    TEMP=45000
                    DELAY=5
                    FAN=-1
                    POSITIONAL_ARGS=()
                    SERVICE_PATH=/etc/systemd/system/duetfan.service
                    USAGE="sudo ./$0 --fan <n> --temp [n] --delay [n]"
                    while [[ $# -gt 0 ]]; do
                    	K="$1"
                    	case $K in
                    	-t|--temp)
                    		TEMP="$2"
                    		shift
                    		shift
                    		;;
                    	-d|--delay)
                    		DELAY="$2"
                    		shift
                    		shift
                    		;;
                        -f|--fan)
                            FAN="$2"
                            shift
                            shift
                            ;;
                    	*)
                    		if [[ $1 == -* ]]; then
                    			printf "Unrecognised option: $1\n";
                    			printf "Usage: $USAGE\n";
                    			exit 1
                    		fi
                    		POSITIONAL_ARGS+=("$1")
                    		shift
                    	esac
                    done
                     
                    set -- "${POSITIONAL_ARGS[@]}"
                    
                    if [ ! -z $FAN ] && [ $FAN -ge 0 ] && [ $FAN -le 8 ]; then
                     
                    cat << EOF
                    Setting up with:
                    Fan:              $FAN
                    Temp:             $TEMP mC
                    Delay:            $DELAY seconds
                    To change these options, run:
                    $USAGE
                    Or edit: $SERVICE_PATH
                    EOF
                     
                    read -r -d '' UNIT_FILE << EOF
                    [Unit]
                    Description=Duet Fan Service
                    After=multi-user.target
                    [Service]
                    Type=simple
                    WorkingDirectory=$(pwd)
                    ExecStart=$(pwd)/duetfan.sh $TEMP $DELAY
                    Restart=on-failure
                    [Install]
                    WantedBy=multi-user.target
                    EOF
                     
                    printf "\nInstalling service to: $SERVICE_PATH\n"
                    echo "$UNIT_FILE" > $SERVICE_PATH
                    systemctl daemon-reload
                    systemctl enable --no-pager duetfan.service
                    systemctl restart --no-pager duetfan.service
                    systemctl status --no-pager duetfan.service
                    
                    else
                      echo $USAGE
                    fi
                    

                    save content to files, chmod +x and sudo ./duetfansystemd.sh to install and start service.

                    Donpiundefined 1 Reply Last reply Reply Quote 1
                    • achrnundefined
                      achrn
                      last edited by

                      45C seems a little low.

                      The Pi is OK to 85C in teh SoC. It doesn't do any throttling at all until 60C, and only starts throttling seriously at 80C. I would expect 55C is still plenty margin for fans to come on, and avoids running fans unecesarily - even 60C might be adequate (since the first soft throttling still leaves the Pi running at about 85% of 'flat out').

                      A Former User? 1 Reply Last reply Reply Quote 0
                      • A Former User?
                        A Former User @achrn
                        last edited by

                        @achrn said in Duet 3 SBC : SBC Temperature Sensor:

                        45C seems a little low.

                        i suppose my "substandard" ambient temp is to blame for that as I have plenty margin to 45C, anyways, easy enough to change, and the cooler the better in any case.

                        1 Reply Last reply Reply Quote 0
                        • Donpiundefined
                          Donpi @A Former User
                          last edited by

                          @bearer Thank you very mutch.
                          Your script work perfectely.

                          1 Reply Last reply Reply Quote 0
                          • A Former User?
                            A Former User
                            last edited by

                            credit goes the fan shim crowd for the rather elegant systemd setup and happy to help with "interesting" ways to achieve things.

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post
                            Unless otherwise noted, all forum content is licensed under CC-BY-SA