From 8c5070bff099410227d4dbafa660c2a32d04ed06 Mon Sep 17 00:00:00 2001 From: derekfc Date: Mon, 4 May 2015 16:55:52 -0400 Subject: [PATCH 1/4] Update GPIO.py --- anyio/arduino/GPIO.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/anyio/arduino/GPIO.py b/anyio/arduino/GPIO.py index 725f2e8..8f0c63a 100644 --- a/anyio/arduino/GPIO.py +++ b/anyio/arduino/GPIO.py @@ -8,7 +8,7 @@ USE_EMBEDDED_PYSERIAL = True MIN_PIN = 0 -MAX_PIN = 16 +MAX_PIN = 13 IN = 0 OUT = 1 @@ -19,7 +19,7 @@ # OS INTERFACE ========================================================= - +import time from .. import protocol from .. import adaptors import portscan @@ -62,7 +62,8 @@ s.close() s.port = PORT s.open() - +# Add time delay, as opening Serial will cause Arduino Uno to reset, requiring additional time to process. +time.sleep(3) instance = protocol.GPIOClient(adaptors.SerialAdaptor(s), DEBUG) From df5208d131296db76feac3ea7efec9ee25bf7b21 Mon Sep 17 00:00:00 2001 From: derekfc Date: Mon, 4 May 2015 20:04:57 -0400 Subject: [PATCH 2/4] Update serialutil.py for Arduino Uno to match Baud Updated serialutil.py to match the Baud rates utilized in other relevant settings (gpio.ino for Arduino, and anyio/arduino/GPIO.py) at 115200 for consistency on initial invocation. --- anyio/arduino/serial/serialutil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anyio/arduino/serial/serialutil.py b/anyio/arduino/serial/serialutil.py index f28ece4..4557a2e 100644 --- a/anyio/arduino/serial/serialutil.py +++ b/anyio/arduino/serial/serialutil.py @@ -237,7 +237,7 @@ def __init__(self, # can specify a device string, note # that this isn't portable anymore # port will be opened if one is specified - baudrate=9600, # baud rate + baudrate=115200, # baud rate bytesize=EIGHTBITS, # number of data bits parity=PARITY_NONE, # enable parity checking stopbits=STOPBITS_ONE, # number of stop bits From 93139cc48c669c573bbd2b1d2f1eb1c3276e799c Mon Sep 17 00:00:00 2001 From: derekfc Date: Mon, 4 May 2015 20:10:02 -0400 Subject: [PATCH 3/4] Update gpio.ino specifically for Arduino Uno 14 Pins As the Arduino Uno only has 14 digital pins, this adjusted version specific for Arduino Uno sets the appropriate MAX_PIN to 13 at line 74. --- anyio/arduino/firmware/gpio/gpio.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anyio/arduino/firmware/gpio/gpio.ino b/anyio/arduino/firmware/gpio/gpio.ino index c03d7ab..e237a92 100644 --- a/anyio/arduino/firmware/gpio/gpio.ino +++ b/anyio/arduino/firmware/gpio/gpio.ino @@ -71,7 +71,7 @@ */ #define MIN_PIN 0 -#define MAX_PIN 16 +#define MAX_PIN 13 /* Errors are sent back via the 'E' response. */ From ba7eddefd7ac635059740379d93a2583faf21e42 Mon Sep 17 00:00:00 2001 From: derekfc Date: Mon, 4 May 2015 20:45:06 -0400 Subject: [PATCH 4/4] Update README.md for specific notes on Arduino Uno branch Includes pin mapping suggestions for Arduino Uno, and general notes / suggestions about uploading with Arduino IDE, including matching Baud rates in Serial Monitor console. --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 032cd8a..359d3c4 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ The two are linked together by a serial port controlled by the pyserial library. Calls to the anyio.GPIO methods on the host computer will cause reads or writes to the GPIO pins on the arduino platform. +To use anyio with Arduino Uno, please see the detailed notes at the bottom of this README. + In this way, it is possible to write a hardware control program on any platform, that can easily be ported between different platforms @@ -196,3 +198,21 @@ https://github.com/sparkfun/SF32u4_boards/blob/master/driver/ProMicro.inf David Whale June 2014 +USE WITH ARDUINO UNO + +As Arduino Uno has a different digital pin structure, as well as a different way of processing Serial vs. the Pro Micro described above, modest additional / different code is required for stable, consistent performance (available via this branch). Without this code, LED's have displayed very faintly, and often when invoked via Python programs, anyio performance has failed or degraded materially. + +Note: If uploading gpio.ino code (accessible via anyio/arduino/firmware/gpio/gpio.ino) from Arduino IDE to the Arduino Uno, you _must_ set the Baud rate in Serial Console (available via the Tools/Serial Monitor menu) to 115200 to match that in the gpio.ino (as well as the complementary Python code settings) _before_ uploading the gpio.ino sketch to the Arduion Uno. + +The edits suggested in this branch were tested for appropriate Arduino Uno function with the suggested code in Chapter 5 of "Adventures in Minecraft" by David Whale and Martin O'Hanlon. + +When using the 7 Segment Display called for in Chapter 5 and subsequent chapters of "Adventures in Minecraft", a different pin mapping is required for the Arduino Uno relative to the numbering scheme / pin map on the Pro Micro (described in the book and included in its reference Python code). After comparing the Pin Out diagrams of the 2 devices, the following Pin Map is suggested for Arduino Uno, which functioned well in testing: + +LED_PINS = [9,8,4,5,6,10,11,3] # Use this for Arduino on PC/Mac + +Note: Comparable 7 Segment Mapping = [A,B,C,D,E,F,G,DP] +Reference the description in the book or the anyio/seg7.py program provided in the anyio directory via the Adventures in Minecraft companion website http://www.wiley.com/WileyCDA/Section/id-823690.html, which matches the order of the suggested pins above for the anode 7 segment display used in testing. + +The "LED_PINS ="... code line above can be substituted in the comparable programs suggested in Chapter 5, etc. in "Adventures in Minecraft", including testDisply.py, testDisplay2.py, and detonator.py. + +This branch reflects code changes that should result in a performant anyio directory usable with Arduino Uno for Adventures in Minecraft.