Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Arduino/arduino.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,15 +496,15 @@ def dht(self, pin, module = 0):
except:
return None


def displayText(self, text, fontsize=1):
"""
Sets a string of text to be displayed on the connected SSD1306
Sets a string of text to be displayed on the connected SSD1306
display. It sends the command 'dst' to the Arduino.

Inputs:
text: A string, containing the characters to be displayed.
fontsize: A single integer value, adjusts the size of the
fontsize: A single integer value, adjusts the size of the
characters. Please only pass numbers between 1 and 9.
"""

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ print(board.EEPROM.read(location))
print('EEPROM size {size}'.format(size=board.EEPROM.size()))
```

**Screen**
Display text on an LCD screen.
Use the function displayText(text, fontSize = 1) to display a string on the screen.

**DHT**

- `Arduino.dht(pin, module)` reads sensor values from the DHT sensor connected at the specified pin.
Expand Down
2 changes: 2 additions & 0 deletions pypi_commands.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python3 setup.py sdist bdist_wheel
python3 -m twine upload dist/*
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="arduino-python3",
version="0.4",
version="0.5",
install_requires=['pyserial'],
author="Morten Kals",
author_email="morten@kals.no",
Expand Down
126 changes: 63 additions & 63 deletions sketches/prototype/prototype.ino
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ uint8_t readCapacitivePin(String data) {
else if (*pin & bitmask) { cycles = 16;}

// Discharge the pin again by setting it low and output
// It's important to leave the pins low if you want to
// It's important to leave the pins low if you want to
// be able to touch more than 1 sensor at a time - if
// the sensor is left pulled high, when you touch
// two sensors, your body will transfer the charge between
Expand Down Expand Up @@ -118,12 +118,12 @@ void Tone(String data){
delay(pause);
noTone(pin);
}
}
}

void ToneNo(String data){
int pin = Str2int(data);
noTone(pin);
}
}

void DigitalHandler(int mode, String data){
int pin = Str2int(data);
Expand Down Expand Up @@ -161,7 +161,7 @@ void ConfigurePinHandler(String data){
}
}

void shiftOutHandler(String data) {
void shiftOutHandler(String data) {
String sdata[4];
split(sdata, 4, data, '%');
int dataPin = sdata[0].toInt();
Expand Down Expand Up @@ -207,10 +207,10 @@ void SS_write(String data) {
char buffer[len];
data.toCharArray(buffer,len);
Serial.println("ss OK");
sserial->write(buffer);
sserial->write(buffer);
}
void SS_read(String data) {
char c = sserial->read();
char c = sserial->read();
Serial.println(c);
}

Expand All @@ -219,10 +219,10 @@ void pulseInHandler(String data){
long duration;
if(pin <=0){
pinMode(-pin, INPUT);
duration = pulseIn(-pin, LOW);
duration = pulseIn(-pin, LOW);
}else{
pinMode(pin, INPUT);
duration = pulseIn(pin, HIGH);
duration = pulseIn(pin, HIGH);
}
Serial.println(duration);
}
Expand All @@ -238,7 +238,7 @@ void pulseInSHandler(String data){
delayMicroseconds(5);
digitalWrite(-pin, HIGH);
pinMode(-pin, INPUT);
duration = pulseIn(-pin, LOW);
duration = pulseIn(-pin, LOW);
}else{
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
Expand All @@ -247,7 +247,7 @@ void pulseInSHandler(String data){
delayMicroseconds(5);
digitalWrite(pin, LOW);
pinMode(pin, INPUT);
duration = pulseIn(pin, HIGH);
duration = pulseIn(pin, HIGH);
}
Serial.println(duration);
}
Expand Down Expand Up @@ -315,8 +315,8 @@ void sizeEEPROM() {
void EEPROMHandler(int mode, String data) {
String sdata[2];
split(sdata, 2, data, '%');
if (mode == 0) {
EEPROM.write(Str2int(sdata[0]), Str2int(sdata[1]));
if (mode == 0) {
EEPROM.write(Str2int(sdata[0]), Str2int(sdata[1]));
} else {
Serial.println(EEPROM.read(Str2int(sdata[0])));
}
Expand All @@ -326,12 +326,12 @@ int dhtSensorPin = -1;
DHT dhtSensor(dhtSensorPin, DHT11);

void dht(String data) {

String sdata[2];
split(sdata, 2, data, '%');
int dataPin = sdata[0].toInt();
int sensorNumber = sdata[1].toInt();

int sensorType = DHT11; // assume DHT11 as default
if (sensorNumber == 1) {
sensorType = DHT12;
Expand All @@ -355,12 +355,12 @@ void dht(String data) {
float h = dhtSensor.readHumidity();
// Read temperature as Celsius (the default)
float t = dhtSensor.readTemperature();

if (isnan(h) || isnan(t)) {
Serial.println("0&0&0");
return;
}

float hic = dhtSensor.computeHeatIndex(t, h, false);
Serial.println(String(h) + "&" + String(t) + "&" + String(hic));
}
Expand All @@ -371,26 +371,26 @@ void dht(String data) {
// A large function to set up the display, clear it from previously, set a line(s) of text, and write it.
// TODO: I was unable to break this apart into different functions to play around with in Python, due to issues with variable scope. I will come back to this.
void displayText(String data) {

int screen_height = 32;
int screen_width = 128;

// The analog pin number connected to the reset pin of the screen (SDA).
int reset_pin = 4;

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins).
Adafruit_SSD1306 display(screen_width, screen_height, &Wire, 4);
Adafruit_SSD1306 display(screen_width, screen_height, &Wire, 4);

display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

// Clears previously displayed data and resets the cursor and text colour.
display.clearDisplay();
display.setCursor(0,0);
display.setTextColor(WHITE);

// The input data string contains the text to be written, along with %#,
// where # is the font size. This sets the font size by reading the last
// character of the input data (by default it is 1), and converting it
// The input data string contains the text to be written, along with %#,
// where # is the font size. This sets the font size by reading the last
// character of the input data (by default it is 1), and converting it
// to an int. Once that is done, the last two characters are deleted.
int font_size = data[data.length() - 1] - 48;
display.setTextSize(font_size);
Expand All @@ -414,64 +414,64 @@ void SerialParser(void) {
// separate command from associated data
String cmd = read_.substring(1,idx1);
String data = read_.substring(idx1+1,idx2);

// determine command sent
if (cmd == "dw") {
DigitalHandler(1, data);
DigitalHandler(1, data);
}
else if (cmd == "dr") {
DigitalHandler(0, data);
}
DigitalHandler(0, data);
}
else if (cmd == "aw") {
AnalogHandler(1, data);
}
AnalogHandler(1, data);
}
else if (cmd == "ar") {
AnalogHandler(0, data);
}
AnalogHandler(0, data);
}
else if (cmd == "pm") {
ConfigurePinHandler(data);
}
ConfigurePinHandler(data);
}
else if (cmd == "ps") {
pulseInSHandler(data);
}
pulseInSHandler(data);
}
else if (cmd == "pi") {
pulseInHandler(data);
}
pulseInHandler(data);
}
else if (cmd == "ss") {
SS_set(data);
SS_set(data);
}
else if (cmd == "sw") {
SS_write(data);
SS_write(data);
}
else if (cmd == "sr") {
SS_read(data);
}
SS_read(data);
}
else if (cmd == "sva") {
SV_add(data);
}
SV_add(data);
}
else if (cmd == "svr") {
SV_read(data);
}
SV_read(data);
}
else if (cmd == "svw") {
SV_write(data);
}
SV_write(data);
}
else if (cmd == "svwm") {
SV_write_ms(data);
}
SV_write_ms(data);
}
else if (cmd == "svd") {
SV_remove(data);
}
SV_remove(data);
}
else if (cmd == "version") {
Version();
Version();
}
else if (cmd == "to") {
Tone(data);
}
Tone(data);
}
else if (cmd == "nto") {
ToneNo(data);
}
ToneNo(data);
}
else if (cmd == "cap") {
readCapacitivePin(data);
readCapacitivePin(data);
}
else if (cmd == "so") {
shiftOutHandler(data);
Expand All @@ -480,12 +480,12 @@ void SerialParser(void) {
shiftInHandler(data);
}
else if (cmd == "eewr") {
EEPROMHandler(0, data);
}
EEPROMHandler(0, data);
}
else if (cmd == "eer") {
EEPROMHandler(1, data);
}
else if (cmd == "sz") {
EEPROMHandler(1, data);
}
else if (cmd == "sz") {
sizeEEPROM();
}
else if (cmd == "dht") {
Expand All @@ -498,7 +498,7 @@ void SerialParser(void) {
}

void setup() {
Serial.begin(115200);
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Expand Down
Loading