Compare commits
13 Commits
pyinstalle
...
master
Author | SHA1 | Date |
---|---|---|
Holger Frey | 9d826d9b0e | 5 years ago |
Holger Frey | b32da8595d | 7 years ago |
Holger Frey | a5e323ec4a | 7 years ago |
Holger Frey | 85984ce239 | 7 years ago |
Holger Frey | 6216f034cc | 7 years ago |
Holger Frey | cd17e916af | 7 years ago |
Holger Frey | c5f6c197fc | 7 years ago |
Holger Frey | 961ea26682 | 7 years ago |
Holger Frey | 73228bbde9 | 7 years ago |
Holger Frey | 466e1bbb45 | 7 years ago |
Holger Frey | 33518cedc6 | 7 years ago |
Holger Frey | b0e121efcc | 7 years ago |
Holger Frey | 67deec5243 | 7 years ago |
14 changed files with 255 additions and 36 deletions
@ -0,0 +1,4 @@ |
|||||||
|
Version 0.1.0 (19.09.2017) |
||||||
|
========================== |
||||||
|
|
||||||
|
- first relase, including library and GUI application |
Before Width: | Height: | Size: 161 KiB |
@ -1,21 +1,72 @@ |
|||||||
# arduino-timetable |
arduino-timetable |
||||||
|
================= |
||||||
|
|
||||||
Module to send commands to an Arduino based on a time table. |
Module to send commands to an Arduino based on a time table. |
||||||
|
|
||||||
|
|
||||||
### Regarding Pyinstaller |
Regarding Pyinstaller |
||||||
|
--------------------- |
||||||
|
|
||||||
As of September 2017 the Pyinstaller version on PyPi is not ready for |
As of September 2017 the Pyinstaller version on PyPi is not ready for |
||||||
Python 3.6, the developementversion is needed: |
Python 3.6 and / or multiprocessing. I stopped trying to use Pyinstaller |
||||||
|
for distribution. The experiment is still available in the `pyinstaller` |
||||||
|
branch. |
||||||
|
|
||||||
~~~ |
|
||||||
pip install https://github.com/pyinstaller/pyinstaller/tarball/develop |
|
||||||
~~~ |
|
||||||
|
|
||||||
But I found out that Pyintaller and multiprocessing on windows don't mix well. |
Installation |
||||||
Even after some research and trying the [recipie from the pyinstaller wiki][1] |
------------ |
||||||
it just won't work. |
|
||||||
|
|
||||||
I will try to investigate further, if I find the time for it [...] |
As the only prerequisite, [Python (at least version 3.6)][python] must be |
||||||
|
installed. An added bonus points, if [git][git] is also available. |
||||||
|
|
||||||
[1]: https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Multiprocessing |
The installation should be performed in a python virtual environment. A virtual |
||||||
|
environment (short: venv) isolates your base python installation from the |
||||||
|
application and vice versa. This procedure is considered a standard procedure |
||||||
|
when working with python applications and scripts. |
||||||
|
|
||||||
|
1. Choose the desired installation path (e.g. a folder in your home directory) |
||||||
|
2. Create a python virtual environment with `python3 -m venv venv-ardunio-timetable` |
||||||
|
3. Activate the environment: |
||||||
|
- Posix: `source venv-ardunio-timetable/bin/activate` |
||||||
|
- Windows: `venv-ardunio-timetable\Scripts\activate.bat` |
||||||
|
4. [Download][download] the 'arduino-timetable' and unpack it or use git: |
||||||
|
`git clone https://git.cpi.imtek.uni-freiburg.de/holgi/arduino-timetable.git` |
||||||
|
5. Change to the new directory and install the software. I would recommend |
||||||
|
to install the software as a 'development version', so that changes can be |
||||||
|
made easily. Change to the folder where 'setup.py' is located and run |
||||||
|
`pip install -e .` |
||||||
|
|
||||||
|
As of Version 0.1.0, this will also install one GUI-like application called |
||||||
|
'magnetictrap'. It is located at the following paths: |
||||||
|
|
||||||
|
- Posix: `<path to virtual environment>/bin/magnetictrap` |
||||||
|
- Windows: `<path to virtual environment>\Scripts\magnetictrap.exe` |
||||||
|
|
||||||
|
Don't move this file around. If you want to have a shortcut on the desktop or |
||||||
|
somewhere else, please create a shortcut, alias or symbolic link - whatever it |
||||||
|
is called on your system. |
||||||
|
|
||||||
|
|
||||||
|
Updating |
||||||
|
-------- |
||||||
|
|
||||||
|
Find out if the installation was done using git: |
||||||
|
|
||||||
|
- Open a command line and activate the environment. |
||||||
|
- Change to the directory, where the 'setup.py' file of |
||||||
|
the package is located |
||||||
|
- Issue a `git status` command. If the result is something along the line |
||||||
|
`fatal: Not a git repository`, git was not used for the installation |
||||||
|
- Updating *with* git: |
||||||
|
- Issue a `git pull origin` command to update the package |
||||||
|
- Updating *without* git: |
||||||
|
- Delete the folder that contains the 'setup.py' file |
||||||
|
- [Download][download] the software again and unpack it |
||||||
|
- Change to the folder where 'setup.py' is located and run |
||||||
|
`pip install -e .` again to installe the applications |
||||||
|
- Good Luck |
||||||
|
|
||||||
|
|
||||||
|
[python]: https://www.python.org/ |
||||||
|
[git]: https://git-scm.com/ |
||||||
|
[download]: https://git.cpi.imtek.uni-freiburg.de/holgi/arduino-timetable/archive/master.tar.gz |
||||||
|
@ -0,0 +1,108 @@ |
|||||||
|
// include the servo library
|
||||||
|
#include <Servo.h> |
||||||
|
|
||||||
|
// create servo object to control a servo
|
||||||
|
Servo Servo_1; |
||||||
|
Servo Servo_2; |
||||||
|
|
||||||
|
// constants: input and output pins
|
||||||
|
const int SWITCH_PIN = 4; |
||||||
|
const int SERVO_1_PIN = 9; |
||||||
|
const int SERVO_2_PIN = 10; |
||||||
|
|
||||||
|
// constants: the trap can be open or close.
|
||||||
|
// easier to understand than HIGH or LOW
|
||||||
|
const int CLOSED = LOW; |
||||||
|
const int OPEN = HIGH; |
||||||
|
|
||||||
|
// constants: positions of servo end points and positioning delay in microseconds
|
||||||
|
const int SERVO_1_CLOSED = 7; |
||||||
|
const int SERVO_1_OPEN = 100; |
||||||
|
const int SERVO_2_CLOSED = 159; |
||||||
|
const int SERVO_2_OPEN = 64; |
||||||
|
const int SERVO_DELAY = 10; |
||||||
|
|
||||||
|
// variables
|
||||||
|
int switch_state = LOW; // the current state of the input pin
|
||||||
|
int trap_state = OPEN; // will a high switch state change the servo position
|
||||||
|
|
||||||
|
void setup() { |
||||||
|
// setup code here, run once after reset or power on:
|
||||||
|
|
||||||
|
// setting pins to input, and output
|
||||||
|
pinMode(SWITCH_PIN, INPUT); |
||||||
|
pinMode(LED_BUILTIN, OUTPUT); |
||||||
|
|
||||||
|
// initialize serial connection
|
||||||
|
Serial.begin(9600); |
||||||
|
|
||||||
|
// attach the servos
|
||||||
|
Servo_1.attach(SERVO_1_PIN); |
||||||
|
Servo_2.attach(SERVO_2_PIN); |
||||||
|
|
||||||
|
// moving servos to defined position
|
||||||
|
Servo_1.write(SERVO_1_OPEN); |
||||||
|
Servo_2.write(SERVO_2_OPEN); |
||||||
|
|
||||||
|
// read the current switch state
|
||||||
|
switch_state = digitalRead(SWITCH_PIN); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
void loop() { |
||||||
|
// main code, run repeatedly:
|
||||||
|
|
||||||
|
// MANUAL SWITCH STATE
|
||||||
|
// -------------------
|
||||||
|
|
||||||
|
// read the current state of the input
|
||||||
|
int current_switch_state = digitalRead(SWITCH_PIN); |
||||||
|
|
||||||
|
// change trap position if the switch state has changed
|
||||||
|
if (current_switch_state != switch_state) { |
||||||
|
|
||||||
|
// register the change
|
||||||
|
switch_state = current_switch_state; |
||||||
|
|
||||||
|
if (switch_state == HIGH) { |
||||||
|
// show that there is currently a input signal
|
||||||
|
// and close the trap
|
||||||
|
digitalWrite(LED_BUILTIN, HIGH); |
||||||
|
trap_state = close_trap(); |
||||||
|
} else { |
||||||
|
// show that there is currently no input signal
|
||||||
|
// and open the trap
|
||||||
|
digitalWrite(LED_BUILTIN, LOW); |
||||||
|
trap_state = open_trap(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
// COMMANDS SEND OVER USB
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
// read the incoming data
|
||||||
|
char inByte = Serial.read(); |
||||||
|
|
||||||
|
if (inByte == 'o') { |
||||||
|
// the open trap command was sent
|
||||||
|
trap_state = open_trap(); |
||||||
|
} else if (inByte == 'c') { |
||||||
|
// the close trap command was sent
|
||||||
|
trap_state = close_trap(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
int open_trap() { |
||||||
|
Servo_1.write(SERVO_1_OPEN); |
||||||
|
Servo_2.write(SERVO_2_OPEN); |
||||||
|
return OPEN; |
||||||
|
} |
||||||
|
|
||||||
|
int close_trap() { |
||||||
|
Servo_1.write(SERVO_1_CLOSED); |
||||||
|
Servo_2.write(SERVO_2_CLOSED); |
||||||
|
return CLOSED; |
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,41 @@ |
|||||||
|
/*
|
||||||
|
Reading a serial ASCII-encoded string. |
||||||
|
|
||||||
|
This sketch demonstrates the Serial parseInt() function. |
||||||
|
It looks for an ASCII string of comma-separated values. |
||||||
|
It parses them into ints, and uses those to fade an RGB LED. |
||||||
|
|
||||||
|
Circuit: Common-Cathode RGB LED wired like so: |
||||||
|
* Red anode: digital pin 3 |
||||||
|
* Green anode: digital pin 5 |
||||||
|
* Blue anode: digital pin 6 |
||||||
|
* Cathode : GND |
||||||
|
|
||||||
|
created 13 Apr 2012 |
||||||
|
by Tom Igoe |
||||||
|
|
||||||
|
modified 14 Mar 2016 |
||||||
|
by Arturo Guadalupi |
||||||
|
|
||||||
|
This example code is in the public domain. |
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
void setup() { |
||||||
|
// initialize serial:
|
||||||
|
Serial.begin(9600); |
||||||
|
// make the pins outputs:
|
||||||
|
pinMode(LED_BUILTIN, OUTPUT); |
||||||
|
digitalWrite(LED_BUILTIN, LOW); |
||||||
|
} |
||||||
|
|
||||||
|
void loop() { |
||||||
|
char inByte = Serial.read(); // read the incoming data
|
||||||
|
if (inByte=='o'){ |
||||||
|
digitalWrite(LED_BUILTIN, LOW); |
||||||
|
} else if (inByte=='c'){ |
||||||
|
digitalWrite(LED_BUILTIN, HIGH); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
After Width: | Height: | Size: 19 KiB |
@ -0,0 +1,17 @@ |
|||||||
|
import os |
||||||
|
|
||||||
|
from . import run_application |
||||||
|
|
||||||
|
def check_icon(icon_name): |
||||||
|
own_path = os.path.abspath(__file__) |
||||||
|
own_dir = os.path.dirname(own_path) |
||||||
|
icon_path = os.path.join(own_dir, 'appicons', icon_name) |
||||||
|
if os.path.isfile(icon_path): |
||||||
|
return icon_path |
||||||
|
return None |
||||||
|
|
||||||
|
|
||||||
|
def run_magnetic_trap(): |
||||||
|
arduino_commands = {'open': 'o', 'close': 'c'} |
||||||
|
icon = check_icon('Household-Mouse-Trap.ico') |
||||||
|
run_application(arduino_commands, "It's a trap!", icon=icon) |
@ -1,10 +0,0 @@ |
|||||||
pyinstaller ^ |
|
||||||
--noconfirm ^ |
|
||||||
--additional-hooks-dir=. ^ |
|
||||||
--hidden-import=packaging ^ |
|
||||||
--hidden-import=packaging.version ^ |
|
||||||
--hidden-import=packaging.specifiers ^ |
|
||||||
--hidden-import=packaging.requirements ^ |
|
||||||
--name MagneticTrap ^ |
|
||||||
--icon Household-Mouse-Trap.ico ^ |
|
||||||
run_magnetic_trap.py |
|
@ -1,9 +0,0 @@ |
|||||||
from arduino_timetable import run_application |
|
||||||
|
|
||||||
if __name__=='__main__': |
|
||||||
arduino_commands = {'open': 'o', 'close': 'c'} |
|
||||||
run_application( |
|
||||||
arduino_commands, |
|
||||||
"It's a trap!", |
|
||||||
icon='Household-Mouse-Trap.ico' |
|
||||||
) |
|
Loading…
Reference in new issue