-1

I have django project set on my pc and copy of that project on Raspberry pi 3. I deploy changes through pyCharm to raspi. Raspberry is my server where I host my website. I wanted to play with led light through web app. In my app I've imported import RPI.GPIO as GPIO but after server run there was ImportError: No module named 'RPi'. I've managed to install only gpio on pc (No matching distribution found for RPi), but there is still ImportError : No module named 'gpio'. Here is my code in views.py

import gpio
LED_PIN = 18
def turnOn(request):
    gpio.setmode(gpio.BOARD)
    gpio.output(LED_PIN, 1)
    return HttpResponse('')

Is there any possibility to use RPi.GPIO in django on pc?

  • 2
    You cannot get RPi.GPIO on your pc, there are different io connections. However, if you deploy the code to your raspberry pi and run you can use RPi.GPIO. – Arnav Chawla Nov 10 '18 at 22:25

2 Answers2

1

RPi.GPIO is Raspberry-specific and you really cannot use it on your computer - it even has no GPIO ports. You should deploy your code to RPi and use it there.

Martin Urbanec
  • 426
  • 4
  • 11
0

I found a solution. With help of wiringPi and subprocess I could execute command.

def turnOn(request):
subprocess.call(['gpio', '-g', 'mode', '3', 'out'])
subprocess.call(['gpio', '-g', 'write', '3', '1'])
return HttpResponse('')