Compare commits

...

13 Commits

Author SHA1 Message Date
Holger Frey 9d826d9b0e moving to gittea needs a push 5 years ago
Holger Frey b32da8595d fixed minor typo in readme 7 years ago
Holger Frey a5e323ec4a Added installation and update section to readme 7 years ago
Holger Frey 85984ce239 version bump to 0.1.0 7 years ago
Holger Frey 6216f034cc added Arduino test programm 7 years ago
Holger Frey cd17e916af Added Arduino programm for magnetic trap 7 years ago
Holger Frey c5f6c197fc added arduino_timetable_env to .gitignore 7 years ago
Holger Frey 961ea26682 Modified Icon for magnetic trap app 7 years ago
Holger Frey 73228bbde9 specified width on message panel displaying scheduled commands 7 years ago
Holger Frey 466e1bbb45 start directory for file chooser is ~/Desktop 7 years ago
Holger Frey 33518cedc6 after parsing a time table, the result is sorted by the time 7 years ago
Holger Frey b0e121efcc added apps module 7 years ago
Holger Frey 67deec5243 removed Pyinstaller code 7 years ago
  1. 2
      .gitignore
  2. 4
      CHANGES.txt
  3. BIN
      Household-Mouse-Trap.ico
  4. 71
      README.md
  5. 108
      arduino_scripts/Servo-Magnetic-Trap/Servo-Magnetic-Trap.ino
  6. 41
      arduino_scripts/Test-Arduino-Timetable/Test-Arduino-Timetable.ino
  7. 2
      arduino_timetable/__init__.py
  8. BIN
      arduino_timetable/appicons/Household-Mouse-Trap.ico
  9. 17
      arduino_timetable/apps.py
  10. 8
      arduino_timetable/gui.py
  11. 4
      arduino_timetable/timetable.py
  12. 10
      pyinstaller_make.bat
  13. 9
      run_magnetic_trap.py
  14. 13
      setup.py

2
.gitignore vendored

@ -9,6 +9,7 @@ __pycache__/ @@ -9,6 +9,7 @@ __pycache__/
# Distribution / packaging
.Python
arduino_timetable_env/
env/
build/
develop-eggs/
@ -57,4 +58,3 @@ docs/_build/ @@ -57,4 +58,3 @@ docs/_build/
# PyBuilder
target/

4
CHANGES.txt

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
Version 0.1.0 (19.09.2017)
==========================
- first relase, including library and GUI application

BIN
Household-Mouse-Trap.ico

Binary file not shown.

Before

Width:  |  Height:  |  Size: 161 KiB

71
README.md

@ -1,13 +1,72 @@ @@ -1,13 +1,72 @@
# arduino-timetable
arduino-timetable
=================
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
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
~~~
Installation
------------
As the only prerequisite, [Python (at least version 3.6)][python] must be
installed. An added bonus points, if [git][git] is also available.
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

108
arduino_scripts/Servo-Magnetic-Trap/Servo-Magnetic-Trap.ino

@ -0,0 +1,108 @@ @@ -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;
}

41
arduino_scripts/Test-Arduino-Timetable/Test-Arduino-Timetable.ino

@ -0,0 +1,41 @@ @@ -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);
}
}

2
arduino_timetable/__init__.py

@ -10,4 +10,4 @@ from .timetable import ( @@ -10,4 +10,4 @@ from .timetable import (
TimedCommands
)
__version__ = '0.0.1'
__version__ = '0.1.0'

BIN
arduino_timetable/appicons/Household-Mouse-Trap.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

17
arduino_timetable/apps.py

@ -0,0 +1,17 @@ @@ -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)

8
arduino_timetable/gui.py

@ -129,7 +129,11 @@ class ParsedCommandsPanel(tk.Frame): @@ -129,7 +129,11 @@ class ParsedCommandsPanel(tk.Frame):
self._parent = parent
self.label = tk.Label(self)
self.label.pack(fill=tk.X, pady=5, padx=5)
self.messages = tk.Message(self, text='', font=("Courier", 8))
self.messages = tk.Message(self,
text='',
font=("Courier", 8),
width=250
)
self.messages.pack(fill=tk.X, pady=5, padx=5)
self.pack(side=tk.TOP, fill=tk.X)
@ -275,7 +279,7 @@ class Application(tk.Frame): @@ -275,7 +279,7 @@ class Application(tk.Frame):
''' selecting a new excel file with scheduled_commands '''
# open the file selection dialog
opts = {
'initialdir': '~/',
'initialdir': '~/Desktop',
'filetypes': [('Excel Files', '.xlsx')],
'multiple': False}
excel_file = tk.filedialog.askopenfilename(**opts)

4
arduino_timetable/timetable.py

@ -74,7 +74,7 @@ def parse_time_table(timetable, available_commands=None): @@ -74,7 +74,7 @@ def parse_time_table(timetable, available_commands=None):
# add a ScheduledCommand to the resulting list
tc = ScheduledCommand(delta, raw_command, cmd)
timed_commands.append(tc)
return timed_commands
return sorted(timed_commands, key=lambda tc: tc.delta)
def parse_excel_file(path, available_commands=None):
@ -122,7 +122,7 @@ def parse_excel_file(path, available_commands=None): @@ -122,7 +122,7 @@ def parse_excel_file(path, available_commands=None):
# add a ScheduledCommand to the resulting list
tc = ScheduledCommand(delta, raw_command, cmd)
timed_commands.append(tc)
return timed_commands
return sorted(timed_commands, key=lambda tc: tc.delta)
def parse_time_cell(excel_cell):

10
pyinstaller_make.bat

@ -1,10 +0,0 @@ @@ -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

9
run_magnetic_trap.py

@ -1,9 +0,0 @@ @@ -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'
)

13
setup.py

@ -117,4 +117,17 @@ setup( @@ -117,4 +117,17 @@ setup(
# 'test': ['pytest'],
# },
# if and what non python files be included?
include_package_data=True,
package_data={
'arduino_timetable': ['appicons/*.ico'],
},
# defining entry points, escpecially console script:
entry_points={
'console_scripts': [
'magnetictrap = arduino_timetable.apps:run_magnetic_trap',
],
},
)

Loading…
Cancel
Save