diff --git a/Arduino/arduino.py b/Arduino/arduino.py index 30bd6bf..c4828b2 100755 --- a/Arduino/arduino.py +++ b/Arduino/arduino.py @@ -96,7 +96,7 @@ def get_version(sr): class Arduino(object): - def __init__(self, baud=9600, port=None, timeout=2, sr=None): + def __init__(self, baud=115200, port=None, timeout=2, sr=None): """ Initializes serial communication with Arduino if no connection is given. Attempts to self-select COM port, if not specified. diff --git a/README.md b/README.md index 216aab1..ac18634 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ as possible to their Arduino programming language counterparts from Arduino import Arduino import time -board = Arduino('9600') #plugged in via USB, serial com at rate 9600 +board = Arduino('115200') #plugged in via USB, serial com at rate 115200 board.pinMode(13, "OUTPUT") while True: @@ -76,7 +76,7 @@ $ python tests/test_arduino.py Arduino. ```python -board = Arduino("9600") #Example +board = Arduino("115200") #Example ``` The device name / COM port of the connected Arduino will be auto-detected. @@ -84,17 +84,17 @@ If there are more than one Arduino boards connected, the desired COM port can be also be passed as an optional argument: ```python -board = Arduino("9600", port="COM3") #Windows example +board = Arduino("115200", port="COM3") #Windows example ``` ```python -board = Arduino("9600", port="/dev/tty.usbmodemfa141") #OSX example +board = Arduino("115200", port="/dev/tty.usbmodemfa141") #OSX example ``` A time-out for reading from the Arduino can also be specified as an optional argument: ```python -board = Arduino("9600", timeout=2) #Serial reading functions will +board = Arduino("115200", timeout=2) #Serial reading functions will #wait for no more than 2 seconds ``` @@ -192,6 +192,41 @@ print(board.EEPROM.read(location)) print('EEPROM size {size}'.format(size=board.EEPROM.size())) ``` +**DHT** +Read data from DHT temperature and humidity sensors based on the +Adafruit [DHT sensor library](https://github.com/adafruit/DHT-sensor-library). + +Pass as arguments the pin the sensor is connected to (as an integer) and the sensor type you are using as an integer (see list below). + +There are five sensors that work with this library: +- 0 = DHT 11 (blue cage, less accurate) +- 1 = DHT 12 +- 2 = DHT 21 +- 3 = DHT 22 (white cage) +- 4 = AM2301 + +The function returns an array of three elements: +1. humidity (in %) +2. temperature (in celcius) +3. heat index (in celcius) + +If there is an error with the reading (eg. the selected sensor is wrong) all values will return as zero. + +```python +#DHT sensor example +pin = 7 +sensorType = 0 + +data = board.dht(pin, sensorType) +[humidity, temperature, heatIndex] = data + +reply = "Humidity = " + str(humidity) + " % \t" +reply += "Temperature = " + str(temperature) + " ˙C \t" +reply += "Heat Index = " + str(heatIndex) + " ˙C" + +print(reply) +``` + **Misc** - `Arduino.close()` closes serial connection to the Arduino. diff --git a/examples.py b/examples.py index 21c6e0f..2da6906 100644 --- a/examples.py +++ b/examples.py @@ -73,4 +73,4 @@ def LCD(tx, baud, ssbaud, message, port=""): board.SoftwareSerial.write(" test ") if __name__ == "__main__": - Blink(13, '9600') + Blink(13, '115200') diff --git a/setup.py b/setup.py index 52fa795..5ed9934 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setuptools.setup( name="arduino-python3", - version="0.2", + version="0.3", install_requires=['pyserial'], author="Morten Kals", author_email="morten@kals.no", diff --git a/tests/test_arduino.py b/tests/test_arduino.py index 650b4c0..21e76e8 100644 --- a/tests/test_arduino.py +++ b/tests/test_arduino.py @@ -58,7 +58,7 @@ class ArduinoTestCase(unittest.TestCase): def setUp(self): from Arduino.arduino import Arduino - self.mock_serial = MockSerial(9600, '/dev/ttyACM0') + self.mock_serial = MockSerial(115200, '/dev/ttyACM0') self.board = Arduino(sr=self.mock_serial) diff --git a/tests/test_main.py b/tests/test_main.py index 0a12a66..9f414b4 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -31,7 +31,7 @@ class TestBasics(unittest.TestCase): board = None try: # This will trigger automatic port resolution. - board = Arduino(9600) + board = Arduino(115200) finally: if board: board.close() @@ -48,7 +48,7 @@ class TestBasics(unittest.TestCase): from Arduino import Arduino board = None try: - board = Arduino(9600, port=port) + board = Arduino(115200, port=port) finally: if board: board.close()