Make a simple Python flask web service to read and write Raspberry Pi GPIO.
Uses PiFace. must run as sudo, else library not found.
conda activate beepscore
sudo python3 ./pi_gpio_service/service_piface.py
e.g. use client browser or curl
http://10.0.0.4:5000/api/v1/ping/
e.g. use curl
http://10.0.0.4:5000/api/v1/gpio/end-phone-call/
Uses gpio pins, not PiFace
conda activate beepscore
python3 ./pi_gpio_service/service.py
e.g. use client browser or curl
http://10.0.0.4:5000/api/v1/ping/
http://10.0.0.4:5000/api/v1/gpio/status/
read pin status
http://10.0.0.4:5000/api/v1/gpio/<pin_number>/
e.g. use curl
write a pin value
http://10.0.0.4:5000/api/v1/gpio/<pin_number>/
http://10.0.0.4:5000/api/v1/gpio/set-all-outputs-high/
http://10.0.0.4:5000/api/v1/gpio/set-all-outputs-low/
http://10.0.0.4:5000/api/v1/gpio/end-phone-call/
http://beepscore.com/xcuitest-ios-app-phone-call/index.html
http://beepscore.com/using-raspberry-pi-to-end-iphone-phone-call/
Phoney is an iOS application to experiment with testing phone calls. https://github.com/beepscore/Phoney
http://mattrichardson.com/Raspberry-Pi-Flask/
https://github.com/CorrosiveKid/raspberrypi-gpio-api
http://randomnerdtutorials.com/raspberry-pi-web-server-using-flask-to-control-gpios/
https://www.raspberrypi.org/learning/python-web-server-with-flask/worksheet
https://github.com/beepscore/basic_flask https://www.raspberrypi.org/learning/python-web-server-with-flask/worksheet
Create anaconda environment
Activate anaconda environment
conda activate beepscore
Install flask
conda install -n beepscore flask
python app.py
pi console shows Running on http://0.0.0.0:5000
fing shows raspberry pi is on local network at 10.0.0.4
SKU: VET-PIFC2 https://vetco.net/products/piface-digital-2-relay-and-interface-hat-pi-face
https://www.element14.com/community/docs/DOC-69001/l/piface-digital-2-for-raspberry-pi
http://www.piface.org.uk/products/piface_digital/ http://www.piface.org.uk/assets/docs/PiFace-Digital2_getting-started.pdf http://www.piface.org.uk/guides/ http://www.piface.org.uk/guides/simple_web_control_with_piface_digital/getting_started_simple_web_control_piface_digital/
Ensure that no power is supplied to Raspberry Pi or PiFace Digital 2 boards when plugging or unplugging.
1 sets board address bit 0 2 sets board address bit 1 3 Connects PiFace digital 5v to raspberry pi 5v. SEE WARNING 4 Connects snubber diodes to 5v 5 Connects relay 0 6 Connects relay 1 7 connects 5v power to LEDs and relay coils
1 connects 1-2 (0) 2 connects 1-2 (0) 3 connected SEE WARNING 4 Connects snubber diodes to 5v 5 connected 6 connected 7 connected
1 connects 1-2 (0) 2 connects 1-2 (0) 3 connected SEE WARNING 4 Connects snubber diodes to 5v 5 connected 6 connected 7 connected
Power share jumper JP3 selects whether the PiFace Digital 2 shares the same power source as the Raspberry Pi. This supply can be either provided through the Raspberry Pi’s MicroUSB connector, or from an external supply provided through PiFace Digital 2’s 5V and GND power screw terminals. With the jumper connected, the Raspberry Pi and PiFace Digital 2 will share a single power supply. Disconnected, they will each need to be powered separately.
NEVER USE SEPARATE POWER SUPPLIES FOR BOTH THE RASPBERRY PI AND PIFACE DIGITAL 2 WHEN THIS JUMPER IS CONNECTED.
// TODO: disconnect to maximize isolation between pi and controlled device After disconnecting, connect separate 5v supply
Snubber diodes jumper JP4 connects the snubber diodes from the ULN2803A to 5V (snubber diodes protect the driving transistors from the high voltages that occur when a coil, e.g. a relay, turns off).
if the open-collectors are connected to a supply greater than 5v, these diodes must be disconnected by removing jp4 (else the diodes will conduct between the outputs and 5v).
ULN2803A darlington transistors eight npn array ==> use supply <= 5v, leave JP4 connected.
The SPI interface driver must be enabled using raspi-config.
sudo raspi-config
Board documentation says look in "Advanced". I think this is out of date. I found it under "Interfacing options".
pifacedigital-emulator
requires running X window
sudo apt-get install python3-pifacedigitalio
Apparently it was already installed. "python3-pifacedigitalio is already the newest version."
Package notes RPi.gpio library is not suitable for precise real time control. Linux may interrupt to garbage collect. For timing critical applications use a microcontroller like Arduino.
I think Raspbian comes with RPi.gpio But program didn't see it, maybe not visible within conda environment. miniconda didn't come with RPi.gpio.
with conda environment beepscore activated ran
pip install RPi.GPIO
with conda environment beepscore activated ran
conda install -c ericmjl ri.gpio
This installed an older version 0.5.11 2016-12-01
I tried running python ./pi_gpio_service/service.py
RuntimeError: No access to /dev/mem. Try running as root!
Current version 0.6.3 doesn't require root. https://raspberrypi.stackexchange.com/questions/40105/access-gpio-pins-without-root-no-access-to-dev-mem-try-running-as-root#40106 https://pypi.python.org/pypi/RPi.GPIO
conda list
conda remove rpi.gpio
http://beepscore.com/making-an-iphone-headphone-breakout-switch/index.html
http://www.blackcatsystems.com/ipad/iPad_iPhone_iPod_Touch_Microphone_Wiring.html
The iDevice needs to see a resistance in the neighborhood of 5k between the microphone conductor and ground. That tells it that a microphone has been plugged in. If it is a direct short, it thinks a headphone was plugged in. Open circuit means nothing was plugged in.
http://www.friendmichael.com/Blog/iphone-headphone-plug-pinouts.html