reef-pi :: An opensource reef tank controller based on Raspberry Pi.

Bzar

Community Member
View Badges
Joined
Apr 11, 2019
Messages
32
Reaction score
66
Rating - 0%
0   0   0
Having some issues getting float switch to work. I've followed the circuit diagram here with the COM having a 10K and 1K on the Pin line. Then the NO straight to GND. But some reason it's just not picking up the switch on any pin. I've restarted, rewired, tried different pins, tested the switch, tried other switches, etc. Could it be impedance in the wires of my floats? Should I just use the pull_up resistors on the pi zero?

If I were to try that I was thinking of just making a python script to activate the resistors with a script like this then just use that pin on the inlet for the float?? Then I wouldn't need 3 wires to float also I guess?

#floatswitch1.py
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

#GPIO Pin of switch
floatPin1 = 21

GPIO.setup(floatPin1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
 

trackerit

Community Member
View Badges
Joined
Apr 11, 2019
Messages
71
Reaction score
137
Rating - 0%
0   0   0
Welcome to reef2reef. Can you try rebooting pi and see if the error persist? I just shared some details on why this may happen sometime

thanks for the welcome, I have reboot the rasberry and the problem continues, is this only for the raspberry pwm? If I put the PCA9685, will I have the same problem?

Apr 12 12:11:38 raspberrypi reef-pi[339]: 2019/04/12 12:11:38 Setting pwm driver: rpi pin: 0 value: 81
Apr 12 12:11:38 raspberrypi reef-pi[339]: 2019/04/12 12:11:38 ERROR: lighting-subsystem: Failed to set pwm value. Error: write /sys/class/pwm/pwmchip0/pwm0/duty_cycle: invalid argument
 

ChrisNH

Active Member
View Badges
Joined
Mar 21, 2019
Messages
305
Reaction score
254
Rating - 0%
0   0   0
I restarted the pi, log shows
Apr 12 17:03:20 reefpi reef-pi[314]: 2019/04/12 17:03:20 lighting-subsystem: Setting PWM value: 48 at channel: 0
Apr 12 17:03:20 reefpi reef-pi[314]: 2019/04/12 17:03:20 Setting pwm driver: rpi pin: 0 value: 48
Apr 12 17:03:20 reefpi reef-pi[314]: 2019/04/12 17:03:20 ERROR: lighting-subsystem: Failed to set pwm value. Error: write /sys/class/pwm/pwmchip0/pwm0/duty_cycle: invalid argument​

So no discernable change. If I edit and save the jack again I still get
{"error":"Failed to update. Error: write /sys/class/pwm/pwmchip0/pwm0/period: invalid argument"} | HTTP 500​
 

bishoptf

Valuable Member
View Badges
Joined
Jan 1, 2019
Messages
1,349
Reaction score
1,724
Location
Missouri
Rating - 0%
0   0   0
I restarted the pi, log shows
Apr 12 17:03:20 reefpi reef-pi[314]: 2019/04/12 17:03:20 lighting-subsystem: Setting PWM value: 48 at channel: 0
Apr 12 17:03:20 reefpi reef-pi[314]: 2019/04/12 17:03:20 Setting pwm driver: rpi pin: 0 value: 48
Apr 12 17:03:20 reefpi reef-pi[314]: 2019/04/12 17:03:20 ERROR: lighting-subsystem: Failed to set pwm value. Error: write /sys/class/pwm/pwmchip0/pwm0/duty_cycle: invalid argument​

So no discernable change. If I edit and save the jack again I still get
{"error":"Failed to update. Error: write /sys/class/pwm/pwmchip0/pwm0/period: invalid argument"} | HTTP 500​

Welcome! :)

Did you follow the initial setup instructions here - https://learn.adafruit.com/reef-pi-installation-and-configuration/raspberry-pi-configuration

Specifically this section:
Code:
reef-pi uses Raspberry Pi's hardware timers for PWM (used for LED dimming, DC 
motor control etc.). This allows reef-pi to use up to two PWM channels without any ancillary
electronics. This feature is only available in newer Linux kernels (4.9 and above). We have to
edit /boot/config.txt file and add this line at the end to enable (then reboot)

dtoverlay=pwm-2chan

Once you do that you need to reboot and see if that helps, you can control the frequency of the pi pwm from the configuration page.
 

bishoptf

Valuable Member
View Badges
Joined
Jan 1, 2019
Messages
1,349
Reaction score
1,724
Location
Missouri
Rating - 0%
0   0   0
Since my update went sideways, I took this opportunity to create a restoration process, it's not exactly step by step but its pretty close and should allow you to restore to a clean image of Raspbian and restore reef-pi to your last working configuration. If anyone see's any additional steps or clarification needed please let me know, I am still planning on working on some simple scripts to routinely backup the needed files for reef-pi restoration.

One note, this also has me disabling the user pi and disabling login, you can change or add to what I have here, this is just my rpi initial configuration.

Woot :) :)

Code:
Rasbian information Headless setup:

Pre-work:

*Download latest raspbian version that you want to use and install to SD card - https://www.raspberrypi.org/downloads/raspbian/

*WPA_Supplicant - file created in /boot

      ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
      update_config=1
      country=US

      network={
         ssid="War_Eagle_2g"
         scan_ssid=1
         psk="Insert-PSK"
         key_mgmt=WPA-PSK
      }

*Create empty file in /boot called "ssh" (enables SSH on first boot)

*SSH to pi
        username:pi
        password:raspberry
 ****Change password******(cmd passwd)

*adduser account (/home/"user")
*add new user to sudoers (cmd sudo usermod -aG sudo username)
*add new user to same groups as "pi" user
    (cmd display groups - pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi)
    (cmd usermod -a -G pi,adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,gpio,i2c,spi,username)
*disable pi user login (sudo vi /etc/passwd, change user pi to pi:x:1000:1000:,,,:/home/pi:/usr/sbin/nologin)
*change hostname (cmd hostname tankpi, sudo vi /etc/hosts, sudo vi /etc/hostname)
*set timezone (cmd raspi-config or sudo timedatectl set-timezone America/Chicago or America/<insert city>)
*Install reef-pi (cmd dpkg -i reef-pi-2.2-pi3.deb
                 (cmd sudo sudo systemctl stop reef-pi.service)
                 (cmd sudo mv /var/lib/reef-pi/reef-pi.db /var/lib/reef-pi/reef-pi.org)
                 (cmd sudo cp reef-pi.db /var/lib/reef-pi/.)
                 (cmd sudo systemctl start reef-pi.service)


Enjoy!
 
Last edited:

bishoptf

Valuable Member
View Badges
Joined
Jan 1, 2019
Messages
1,349
Reaction score
1,724
Location
Missouri
Rating - 0%
0   0   0
I restarted the pi, log shows
Apr 12 17:03:20 reefpi reef-pi[314]: 2019/04/12 17:03:20 lighting-subsystem: Setting PWM value: 48 at channel: 0
Apr 12 17:03:20 reefpi reef-pi[314]: 2019/04/12 17:03:20 Setting pwm driver: rpi pin: 0 value: 48
Apr 12 17:03:20 reefpi reef-pi[314]: 2019/04/12 17:03:20 ERROR: lighting-subsystem: Failed to set pwm value. Error: write /sys/class/pwm/pwmchip0/pwm0/duty_cycle: invalid argument​

So no discernable change. If I edit and save the jack again I still get
{"error":"Failed to update. Error: write /sys/class/pwm/pwmchip0/pwm0/period: invalid argument"} | HTTP 500​

I missed the above information, you stated that you re-flashed the rpi, is it using the latest raspbian version? Just thinking about what else it could be, I use the PWM to drive 2 of my lights, and that dtoverlay command only works with kernels 4.9 and above. I will see what else it could be but that error looks like PWM is not enabled.
 
OP
OP
Ranjib

Ranjib

7500 Club Member
View Badges
Joined
Apr 16, 2016
Messages
9,848
Reaction score
17,081
Location
Pleasant Hill, Concord
Rating - 0%
0   0   0
I missed the above information, you stated that you re-flashed the rpi, is it using the latest raspbian version? Just thinking about what else it could be, I use the PWM to drive 2 of my lights, and that dtoverlay command only works with kernels 4.9 and above. I will see what else it could be but that error looks like PWM is not enabled.
His dtoverlay configuration is already in place (else he'll get a different error, that /sys/class/pwm.. file wont be present). I suspect the pwm frequency is set to some bad values (check Configuration -> Settings -> pwm settings and set it to a higher value [say 1000]) , reboot and see what happens
 

Bzar

Community Member
View Badges
Joined
Apr 11, 2019
Messages
32
Reaction score
66
Rating - 0%
0   0   0
Having some issues getting float switch to work. I've followed the circuit diagram here with the COM having a 10K and 1K on the Pin line. Then the NO straight to GND. But some reason it's just not picking up the switch on any pin. I've restarted, rewired, tried different pins, tested the switch, tried other switches, etc.


So I took some time and figured out how to use regular float switches in a simple fashion using the built in pi resistors. This makes me happy because I don't have to have extra wiring and soldering tasks when adding a bunch of switches, and I don't have to pay for something I already bought. So to get regular float switches (or any switches for that matter) working safely you can do this...

Step A) create a python script to control the pull up resistance. From the terminal...

sudo nano switches.py

#switches.py
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)

ctrl+X > Y > <enter>

Step B) make the file executable...

sudo chmod 755 switches.py

Step C) make the script run at startup by adding a line just before "exit" in rc.local (note: the python start command must point to the directory from root /...

sudo nano /etc/rc.local

sudo python /home/pi/switches.py &

ctrl+X > Y > <enter>

Step D) Restart or Reboot

sudo reboot

Step E) Plug your float switch wires into the GPIO. One wire to Pi header connected Ground, and one to the GPIO you used in switches.py

Step F) Check to see if your script is running...

ps -aef | grep python

Step G) Designate those pins in Reef-Pi to inlets/ATO for your application.

Hope this helps, working for me here.
 

trackerit

Community Member
View Badges
Joined
Apr 11, 2019
Messages
71
Reaction score
137
Rating - 0%
0   0   0
His dtoverlay configuration is already in place (else he'll get a different error, that /sys/class/pwm.. file wont be present). I suspect the pwm frequency is set to some bad values (check Configuration -> Settings -> pwm settings and set it to a higher value [say 1000]) , reboot and see what happens
Hi, I have tried placing the frequency in 1000 I have rebooted the raspberry, and even I have turned it off, it does not work, you can look it in http://200.124.25.203 the credentials are by default
 

trackerit

Community Member
View Badges
Joined
Apr 11, 2019
Messages
71
Reaction score
137
Rating - 0%
0   0   0
hi again
uname -a show (Linux raspberrypi 4.14.98-v7 + # 1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l GNU / Linux) my version of the kernel is 4.14 )
and I have read that it must be greater than 4.9, but I have updated the kernel version and it tells me that the last one is 4.19. Could you help me to know what I'm doing wrong? update the kernel rpi-update
 
OP
OP
Ranjib

Ranjib

7500 Club Member
View Badges
Joined
Apr 16, 2016
Messages
9,848
Reaction score
17,081
Location
Pleasant Hill, Concord
Rating - 0%
0   0   0
hi again
uname -a show (Linux raspberrypi 4.14.98-v7 + # 1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l GNU / Linux) my version of the kernel is 4.14 )
and I have read that it must be greater than 4.9, but I have updated the kernel version and it tells me that the last one is 4.19. Could you help me to know what I'm doing wrong? update the kernel rpi-update
I don’t think there’s any issue with your pi or raspbian version, can you share a screenshot of you reef-pi configuration /settings page ?
 

trackerit

Community Member
View Badges
Joined
Apr 11, 2019
Messages
71
Reaction score
137
Rating - 0%
0   0   0
I don’t think there’s any issue with your pi or raspbian version, can you share a screenshot of you reef-pi configuration /settings page ?
I have reinstalled everything again and it doed not work
1555169841529.jpeg
1555169821656.jpeg


Sent from my MHA-L09 using REEF2REEF mobile app
 

bishoptf

Valuable Member
View Badges
Joined
Jan 1, 2019
Messages
1,349
Reaction score
1,724
Location
Missouri
Rating - 0%
0   0   0
Can you try yoursefl? I dont know what to do, i try all.. Http://200.124.25.203 user and password by default
I think exposing your server to the internet even briefly is a really bad idea, here is the section that he was referring to, you need to enable the lighting option from the configuration page, here is a screenshot.

Screenshot at 2019-04-13 11-21-36.jpg


Then you can go into connectors and add your jacks which then can be configured from the lighting section.

:)
 

trackerit

Community Member
View Badges
Joined
Apr 11, 2019
Messages
71
Reaction score
137
Rating - 0%
0   0   0
I think exposing your server to the internet even briefly is a really bad idea, here is the section that he was referring to, you need to enable the lighting option from the configuration page, here is a screenshot.

Screenshot at 2019-04-13 11-21-36.jpg


Then you can go into connectors and add your jacks which then can be configured from the lighting section.

:)
it's just for tests, so it does not matter if it's posted on the internet, the steps that I'm saying are obvious, and I've tried them before
 
OP
OP
Ranjib

Ranjib

7500 Club Member
View Badges
Joined
Apr 16, 2016
Messages
9,848
Reaction score
17,081
Location
Pleasant Hill, Concord
Rating - 0%
0   0   0
Can you try yoursefl? I dont know what to do, i try all.. Http://200.124.25.203 user and password by default
This is super unsafe, please dont open up your firewall like that :) .

I just browsed through your setup, it looks good. I created a jack , associated it with pi pwm pins (0,1), created a light (test light) , associated the light with the jack and set it to 50% intensity. Lets see if the error persist
 
OP
OP
Ranjib

Ranjib

7500 Club Member
View Badges
Joined
Apr 16, 2016
Messages
9,848
Reaction score
17,081
Location
Pleasant Hill, Concord
Rating - 0%
0   0   0
This is super unsafe, please dont open up your firewall like that :) .

I just browsed through your setup, it looks good. I created a jack , associated it with pi pwm pins (0,1), created a light (test light) , associated the light with the jack and set it to 50% intensity. Lets see if the error persist
I have also disabled the adafruit.io integration, as from the errors it appears you have reached the free account limit. I have triggered a reboot. Can you check if the pwm error is still there?
 
Back
Top