Search code examples
pythoncdjangoembeddedopenwrt

Embedded C PWM dimmer to Django web app


I developed PWM Dimmer with MOSFET for 220V light in embedded C which work via GPIO pin and run on OpenWRT.

This is low-level code( with register access).

I have two push buttons over which I control brightness( connected on input GPIO pins, over which I can increase and decrease PWM frequency in program).

I want to implement two buttons or scroll in Django web application over which I control brightness, instead over GPIOs.

How i can embed this C program to Django web application and connect to web scroll or button?

Is there any way to interact between C program and Django web app, in my case web scroll or button, instead GPIOs?

Perhaps the best way is run to separate program to program which increase ferquency and program which decrease and run when button is pressed, but how i can implement with scroll?

I am a beginner.

Thank you very much.

This is the beginning of the code:

#define BCM2708_PERI_BASE 0x3F000000
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
#define PWM_BASE (BCM2708_PERI_BASE 0x20C000 +) /* PWM controller*/
#define CLOCK_BASE (BCM2708_PERI_BASE + 0x101000)

#define PWM_CTL 0
#define PWM_RNG1 4
#define PWM_DAT1 5

#define PWMCLK_CNTL 40
#define PWMCLK_DIV 41

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <fcntl.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>

...


Solution

  • Django is written in Python. You are using BCM2708, which sounds like Raspberry Pi 2.

    You can use Python library, that is already written for you, e.g. raspberry-gpio-python and there is already such functionality so no need to reinvent the wheel. Here is documentation about controlling PWM from Python.

    There are much more alternatives.

    You can also have a look at alternative implementation using Flask (not Django) on Raspberry Pi for controlling GPIO