Skip to content

Commit 67360d2

Browse files
author
Thomas Preston
committed
Added auto-Windows support and Windows installation docs
1 parent 103f4c3 commit 67360d2

File tree

6 files changed

+168
-62
lines changed

6 files changed

+168
-62
lines changed

CHANGELOG

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
Change Log
22
==========
33

4+
v0.8.4
5+
------
6+
- Default serial port is set to blank on error and added 'requires' to
7+
setup.py
8+
- Added new installation docs.
9+
10+
v0.8.3
11+
------
12+
- Nicer error message for Windows/OSX.
13+
14+
v0.8.2
15+
------
16+
- More robust OS and serial port check.
17+
418
v0.8.1
519
------
620
- Figures out default serial port for Raspberry Pi 2 and below,

codebug_tether/core.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,55 @@
1+
from __future__ import print_function
12
import os
3+
import sys
4+
import glob
25
import time
36
import serial
47
import struct
58
from codebug_tether.i2c import *
69
from codebug_tether.serial_channel_device import SerialChannelDevice
710

811

9-
# setup default serial port (different on MacOS and >=Raspberry Pi 3)
10-
if os.uname().sysname == 'Darwin':
11-
# OSX
12-
DEFAULT_SERIAL_PORT = '/dev/tty.USBmodem'
12+
########################################################################
13+
# setup DEFAULT_SERIAL_PORT which is different on Windows, MacOS,
14+
# Raspberry Pi 2 and Raspberry Pi 3
15+
if sys.platform.startswith('win') or sys.platform.startswith('darwin'):
16+
# On Windows or OSX take the first serial port we can find
17+
def serial_ports():
18+
""" Lists serial port names
19+
20+
:raises EnvironmentError:
21+
On unsupported or unknown platforms
22+
:returns:
23+
A list of the serial ports available on the system
24+
"""
25+
if sys.platform.startswith('win'):
26+
ports = ['COM%s' % (i + 1) for i in range(256)]
27+
elif (sys.platform.startswith('linux') or
28+
sys.platform.startswith('cygwin')):
29+
# this excludes your current terminal "/dev/tty"
30+
ports = glob.glob('/dev/tty[A-Za-z0-9]*')
31+
elif sys.platform.startswith('darwin'):
32+
ports = glob.glob('/dev/tty.*')
33+
else:
34+
raise EnvironmentError('Unsupported platform')
35+
36+
result = []
37+
for port in ports:
38+
try:
39+
s = serial.Serial(port)
40+
s.close()
41+
result.append(port)
42+
except (OSError, serial.SerialException):
43+
pass
44+
return result
45+
# use the first one
46+
try:
47+
DEFAULT_SERIAL_PORT = serial_ports()[0]
48+
except IndexError:
49+
print('ERROR: Could not find any serial ports.', file=sys.stderr)
50+
DEFAULT_SERIAL_PORT = ''
1351
else:
14-
# assume we're on Raspberry Pi/Linux
52+
# otherwise assume we're on Raspberry Pi/Linux
1553
def get_rpi_revision():
1654
"""Returns the version number from the revision line."""
1755
for line in open("/proc/cpuinfo"):
@@ -20,13 +58,15 @@ def get_rpi_revision():
2058
return re.sub('Revision\t: ([a-z0-9]+)\n', r'\1', line)
2159

2260
rpi_revision = get_rpi_revision()
23-
if rpi_revision and rpi_revision != 'Beta' and int('0x'+rpi_revision, 16) >= 0xa02082:
61+
if (rpi_revision and
62+
(rpi_revision != 'Beta') and
63+
(int('0x'+rpi_revision, 16) >= 0xa02082)):
2464
# RPi 3 and above
2565
DEFAULT_SERIAL_PORT = '/dev/ttyS0'
2666
else:
2767
# RPi 2 and below
2868
DEFAULT_SERIAL_PORT = '/dev/ttyACM0'
29-
69+
########################################################################
3070

3171
IO_DIGITAL_OUTPUT = 0
3272
IO_DIGITAL_INPUT = 1

codebug_tether/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.8.1'
1+
__version__ = '0.8.4'

docs/conf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@
5050
#
5151
# The short X.Y version.
5252
# The short X.Y version.
53-
version = '0.8.1'
53+
# NOTE: this is the version of the firmware download too so don't change
54+
# this with minor changes in the software if the firmware hasn't changed!
55+
version = '0.8.0'
5456
# The full version, including alpha/beta/rc tags.
55-
release = '0.8.1'
57+
release = '0.8.0'
5658

5759
# The language for content autogenerated by Sphinx. Refer to documentation
5860
# for a list of supported languages.

docs/installation.rst

Lines changed: 101 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,134 @@
11
############
22
Installation
33
############
4-
You can use the ``codebug_tether`` Python 3 API by either:
54

6-
* Installing with ``pip``
7-
* Copying the ``codebug_tether`` module into your project directory.
5+
Setting up CodeBug
6+
==================
7+
In order to use CodeBug with codebug_tether you need to program CodeBug
8+
with ``codebug_tether.cbg`` (|firmwaredownload|).
89

9-
CodeBug Tether depends on pyserial.
10+
To do this, hold down button A and plug in CodeBug via USB --- it should
11+
appear as a USB drive --- then copy the ``codebug_tether.cbg`` file onto it.
12+
CodeBug is now ready to be used via serial USB. Press button B to exit
13+
programming mode.
1014

11-
It is reccomended that you install using virtual environments.
15+
.. note:: When CodeBug is connected to a computer via USB is should now
16+
appear as a serial device. To reprogram CodeBug: hold down
17+
button A and (re)plug it into a USB port.
1218

1319

14-
Setting up CodeBug
15-
------------------
16-
In order to communicate with CodeBug over Serial USB you need to program CodeBug with
17-
``codebug_tether.cbg`` (|firmwaredownload|).
18-
To do this, plug in CodeBug via USB while holding button A --- it should
19-
appear as a USB drive --- then copy onto it the ``codebug_tether.cbg`` file.
20-
CodeBug is now ready to be used via serial USB. Press button B to exit
21-
programming mode.
20+
Install codebug_tether on Windows
21+
=================================
22+
.. note:: These instructions are based on `The Hitchhikers Guide to Python: Installing Python on Windows <http://docs.python-guide.org/en/latest/starting/install/win/>`_
23+
24+
Install Python
25+
--------------
26+
Download and install the latest verson of Python 3 from `here <https://www.python.org/downloads/windows/>`_.
27+
Make sure you tick the *Add Python 3 to environment variables* checkbox.
28+
29+
Install codebug_tether
30+
----------------------
31+
To install codebug_tether, open up a command prompt and type::
32+
33+
pip install codebug_tether
34+
35+
To test it has worked, plug in CodeBug and open a Python shell by typing::
36+
37+
python
38+
39+
Your command prompt should have changed to::
40+
41+
>>> _
42+
43+
Now type::
44+
45+
>>> import codebug_tether
46+
>>> codebug = codebug_tether.CodeBug()
47+
>>> codebug.set_pixel(2, 2, 1)
48+
49+
The middle pixel on your CodeBug should light up.
50+
51+
52+
Install codebug_tether on OSX
53+
=============================
54+
.. note:: These instructions are based on `The Hitchhikers Guide to Python: Installing Python on Mac OS X <http://docs.python-guide.org/en/latest/starting/install/osx/>`_
2255

23-
When CodeBug is connected to a computer via USB is should now appear as a
24-
serial device (``/dev/ttyACM0`` on Linux).
56+
Install Python
57+
--------------
58+
Download and install `Xcode <https://developer.apple.com/xcode/download/>`_ (if you haven't already) and then enable the command line tools by running (in a terminal)::
2559

60+
xcode-select --install
2661

62+
Now install Homebrew (a package manager for OSX)::
2763

28-
Installing with ``pip``
29-
-----------------------
30-
.. warning:: Consider using virtual environments.
64+
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
3165

32-
Make sure ``pip`` is installed::
66+
The script will explain what changes it will make and prompt you before the installation begins. Once you’ve installed Homebrew, insert the Homebrew directory at the top of your **PATH** environment variable. You can do this by adding the following line at the bottom of your ~/.profile file::
3367

34-
sudo apt-get install python3-pip
68+
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
3569

36-
Install ``codebug_tether`` using ``pip``::
70+
Now, we can install Python 3::
3771

38-
sudo pip-3.2 install pyserial codebug_tether
72+
brew install python3
3973

74+
This will take a minute or two.
4075

41-
Installing with ``pip`` (with Virtual Environments)
42-
---------------------------------------------------
43-
.. note :: Generally, it's best to install packages into a
44-
`virtual environment <http://docs.python-guide.org/en/latest/dev/virtualenvs/>`_
45-
when using ``pip`` so that they remain project specific.
76+
Install codebug_tether
77+
----------------------
78+
To install codebug_tether, open up a terminal and type::
4679

47-
Install ``virtualenv``::
80+
pip install codebug_tether
4881

49-
sudo pip-3.2 install virtualenv
82+
To test it has worked, plug in CodeBug and open a Python shell by typing::
5083

51-
Move into your project and create the virtual environment::
84+
python
5285

53-
cd my_project_directory/
54-
virtualenv-3.2 venv
86+
Your command prompt should have changed to::
87+
88+
>>> _
89+
90+
Now type::
91+
92+
>>> import codebug_tether
93+
>>> codebug = codebug_tether.CodeBug()
94+
>>> codebug.set_pixel(2, 2, 1)
5595

56-
Activate the virtual environment::
96+
The middle pixel on your CodeBug should light up.
5797

58-
source venv/bin/activate
5998

60-
You should notice that your command prompt has changed. ``pip`` will now
61-
install all packages into the virtual environment instead of littering
62-
your system files::
99+
Install codebug_tether on Linux
100+
===============================
101+
Install Python
102+
--------------
103+
Python should already be installed but for good measure::
63104

64-
pip install pyserial codebug_tether
105+
sudo apt-get install python3
65106

66-
Now you can work on your application with ``codebug_tether``. Once
67-
you're done, deactivate the virtual environment::
107+
To install pip, securely download `get-pip.py <https://bootstrap.pypa.io/get-pip.py>`_.
68108

69-
deactivate
109+
Then run the following::
70110

71-
You will not be able to use packages installed in the virtual environment
72-
until you activate it again (`source venv/bin/activate`).
111+
python get-pip.py
73112

74113

75-
Using ``codebug_tether`` without installing
76-
-----------------------------------------------
77-
You may want to use ``codebug_tether`` without installing anything at
78-
all. You can just download and include the ``codebug_tether`` package
79-
in your project and start using it. The quickest way to do this is::
114+
Install codebug_tether
115+
----------------------
116+
To install codebug_tether, open up a terminal and type::
117+
118+
pip install codebug_tether
119+
120+
To test it has worked, plug in CodeBug and open a Python shell by typing::
121+
122+
python
123+
124+
Your command prompt should have changed to::
125+
126+
>>> _
127+
128+
Now type::
80129

81-
git clone https://github.com/codebugtools/codebug_tether.git
82-
cp -r codebug_tether/codebug_tether myproject/
83-
cd myproject/
84-
python3
85130
>>> import codebug_tether
131+
>>> codebug = codebug_tether.CodeBug()
132+
>>> codebug.set_pixel(2, 2, 1)
133+
134+
The middle pixel on your CodeBug should light up.

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def get_version():
2727
license='GPLv3+',
2828
url='https://github.com/codebugtools/codebug_tether',
2929
packages=['codebug_tether'],
30+
requires=['pyserial'],
3031
long_description=open('README.md').read() + open('CHANGELOG').read(),
3132
classifiers=[
3233
"License :: OSI Approved :: GNU Affero General Public License v3 or "

0 commit comments

Comments
 (0)