First of all, let me say that I'm a noob at scripting, but eager to learn !
I want to use Raspi with PCA9685 on I2C bus for creating dimmer channels for LED PWM dimming.
I have succeeded in loading the Adafruit library and the test-script for PCA9685 is working.
Code: Select all
#!/usr/bin/python3
# This simple test outputs a 50% duty cycle PWM single on the 0th channel. Connect an LED and
# resistor in series to the pin to visualize duty cycle changes and its impact on brightness.
from board import SCL, SDA
import busio
# Import the PCA9685 module.
from adafruit_pca9685 import PCA9685
# Create the I2C bus interface.
i2c_bus = busio.I2C(SCL, SDA)
# Create a simple PCA9685 class instance.
pca = PCA9685(i2c_bus)
# Set the PWM frequency to 60hz.
pca.frequency = 2000
# Set the PWM duty cycle for channel zero to 50%. duty_cycle is 16 bits to match other PWM objects
# but the PCA9685 will only actually give 12 bits of resolution.
pca.channels[15].duty_cycle = 0xFFFF
So I wonder how to create DEVICE scripts (in Python, because the PCA9685 library is Python) for using these PWM channels as individual dimmer devices ?
I have device (LUA-)scripts for doing this exact thing with ESP-Easy on ESP8266 ...
Code: Select all
commandArray = {}
DomDevice = 'Badkamer-tv'
IP = '192.168.20.10'
if devicechanged[DomDevice] then
if(devicechanged[DomDevice]=='Off') then DomValue = 0;
print ("Turning off " .. DomDevice);
runcommand = "curl 'http://" .. IP .. "/led/0/" .. DomValue .. "'";
print (runcommand);
os.execute(runcommand);
return commandArray
else
DomValue = (otherdevices_svalues[DomDevice]);
CalcValue = DomValue * 3.3;
end
print ("Value received from Domoticz was " .. (DomValue) .." ");
print ("Dimming " .. (DomDevice) .. " to " .. (DomValue) .. " ");
runcommand = " curl 'http://" .. IP .. "/led/0/" .. CalcValue .. "'";
print (runcommand);
os.execute(runcommand);
end
return commandArray
Is there a way to "convert" these scripts into Python and tailor them towards the PCA9685 channels ?
(Then I could finally replace my Wifi-dimmers (not really stable) with wired dimmers ... after many years of frustration !)
Can some of you scripting geniusses help a beginning noob with this ?
Forever gratefull,
Pascal
Belgium