Hi guys, long time lurker first time poster. I've run into a problem that I'm having difficulty finding a solution to.
I am trying to control 3 strips of LEDs, for the moment simply on/off, via a website hosted on a raspberry pi the arduino is connected to via usb. Now I have it all set up and working as far as I know, i can control the lights with python scripts like so
#!/bin/python
# -*- coding: utf-8 -*-
from time import sleep
import serial
ser = serial.Serial('/dev/ttyACM0', 9600)
ser.write('1')
So I thought i would try to build a simple site with 3 buttons on it to run the scripts which looks like
Which I have had working for another project, but on this one I'm not having it so easy.
So it is working to a degree, I can control the LED's via the webpage, but, there seems to be a delay of ~>10seconds from me pressing the button on the page to the light turning on. Then if I go to press another button for another light, any that were on before go off. Also if i reload the website they all go off.
Now I'm not sure where these symptoms could be originating from so any help would be greatly recieved.
PaulS:
How long does it take for the Pi to start Python and run the script?
What happens when the python script opens the serial port? Typically, that causes the Arduino to reset.
Ah OK now I start to see where I may be going wrong.
The approach I'm using is that that python script is only ran when called from the website. So I'm opening the serial port every time I press a button on the site, so the arduino resets every time I press a button.
So do I need to write a python program that runs on boot that generates the web page and sends commands from input off the site?? Is that the approach I should be looking at
So I'm opening the serial port every time I press a button on the site, so the arduino resets every time I press a button.
Yep.
So do I need to write a python program that runs on boot that generates the web page and sends commands from input off the site?? Is that the approach I should be looking at
If it were me, I'd get an Ethernet shield for the Arduino, and let it serve the page and respond directly to GET requests.
PaulS:
Yep.
If it were me, I'd get an Ethernet shield for the Arduino, and let it serve the page and respond directly to GET requests.
That was my initial thought to begin with, but I need to be able to edit and upload code to the arduino remotely as this system is tucked away in a hard to reach place, and the audio output capabilities of the raspberry. Plus learning to integrate the two could prove handy in the future
I have developed a few projects using the Python Bottle web framework to create a browser based GUI to control an Arduino that is connected to the server by the USB cable.
Thanks again robin2 I got it working. I used flask in the end because I found more documentation that was easier for me to understand, but wouldn't of got there without your help.
Thanks again