From 4bae244f426a39951f404af8f752f715a151f20e Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 25 Apr 2018 09:21:13 +0200 Subject: o Renaming arduino to assignments. --- arduino/01-blink-a-led/Makefile | 4 -- arduino/01-blink-a-led/blink-a-led.md | 39 ----------- arduino/01-blink-a-led/blink-a-led.pdf | Bin 703496 -> 0 bytes arduino/01-blink-a-led/schematic/assignment-1.fzz | Bin 21480 -> 0 bytes .../01-blink-a-led/schematic/assignment-1_bb.pdf | Bin 354599 -> 0 bytes .../schematic/assignment-1_schem.pdf | Bin 263607 -> 0 bytes .../solution/assignment-1/assignment-1.ino | 20 ------ arduino/Makefile | 5 -- arduino/Makefile.assignment | 8 --- arduino/client1/client1.ino | 71 --------------------- arduino/client1/config.h | 5 -- assignments/Makefile | 5 ++ assignments/Makefile.assignment | 8 +++ assignments/blink-a-led/Makefile | 4 ++ assignments/blink-a-led/blink-a-led.md | 39 +++++++++++ assignments/blink-a-led/blink-a-led.pdf | Bin 0 -> 703496 bytes assignments/blink-a-led/schematic/assignment-1.fzz | Bin 0 -> 21480 bytes .../blink-a-led/schematic/assignment-1_bb.pdf | Bin 0 -> 354599 bytes .../blink-a-led/schematic/assignment-1_schem.pdf | Bin 0 -> 263607 bytes .../solution/assignment-1/assignment-1.ino | 20 ++++++ assignments/client1/client1.ino | 71 +++++++++++++++++++++ 21 files changed, 147 insertions(+), 152 deletions(-) delete mode 100644 arduino/01-blink-a-led/Makefile delete mode 100644 arduino/01-blink-a-led/blink-a-led.md delete mode 100644 arduino/01-blink-a-led/blink-a-led.pdf delete mode 100644 arduino/01-blink-a-led/schematic/assignment-1.fzz delete mode 100644 arduino/01-blink-a-led/schematic/assignment-1_bb.pdf delete mode 100644 arduino/01-blink-a-led/schematic/assignment-1_schem.pdf delete mode 100644 arduino/01-blink-a-led/solution/assignment-1/assignment-1.ino delete mode 100644 arduino/Makefile delete mode 100644 arduino/Makefile.assignment delete mode 100644 arduino/client1/client1.ino delete mode 100644 arduino/client1/config.h create mode 100644 assignments/Makefile create mode 100644 assignments/Makefile.assignment create mode 100644 assignments/blink-a-led/Makefile create mode 100644 assignments/blink-a-led/blink-a-led.md create mode 100644 assignments/blink-a-led/blink-a-led.pdf create mode 100644 assignments/blink-a-led/schematic/assignment-1.fzz create mode 100644 assignments/blink-a-led/schematic/assignment-1_bb.pdf create mode 100644 assignments/blink-a-led/schematic/assignment-1_schem.pdf create mode 100644 assignments/blink-a-led/solution/assignment-1/assignment-1.ino create mode 100644 assignments/client1/client1.ino diff --git a/arduino/01-blink-a-led/Makefile b/arduino/01-blink-a-led/Makefile deleted file mode 100644 index b015ec1..0000000 --- a/arduino/01-blink-a-led/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -DIR=01-blink-a-led -A=blink-a-led - -include $(BASEDIR)/Makefile.assignment diff --git a/arduino/01-blink-a-led/blink-a-led.md b/arduino/01-blink-a-led/blink-a-led.md deleted file mode 100644 index f4b3fa1..0000000 --- a/arduino/01-blink-a-led/blink-a-led.md +++ /dev/null @@ -1,39 +0,0 @@ -# Assignment: Blink a led - - -## Goal - -Check that your local environment is working properly. - -## Step 1 - -Create this schematic: - -![](schematic/assignment-1_schem.pdf) - -![](schematic/assignment-1_bb.pdf) - -The colors on the wires used does not matter. The resistors -orientation is not important, but the LED's orientation is important. - -## Step 2 - -Implement `setup()` and `loop()`. In `setup()` configure the LED pin and blink the LED in `loop()`. - -Use these functions: - -~~~ .c++ - -Serial.begin(115200); -Serial.println(string); - -pinMode(pin, mode); -digitalWrite(pin, state); // HIGH or LOW -delay(); - -~~~ - -## Tips - -* It is useful to print a startup message just to see when the - application has started. diff --git a/arduino/01-blink-a-led/blink-a-led.pdf b/arduino/01-blink-a-led/blink-a-led.pdf deleted file mode 100644 index de719fd..0000000 Binary files a/arduino/01-blink-a-led/blink-a-led.pdf and /dev/null differ diff --git a/arduino/01-blink-a-led/schematic/assignment-1.fzz b/arduino/01-blink-a-led/schematic/assignment-1.fzz deleted file mode 100644 index da3ad5b..0000000 Binary files a/arduino/01-blink-a-led/schematic/assignment-1.fzz and /dev/null differ diff --git a/arduino/01-blink-a-led/schematic/assignment-1_bb.pdf b/arduino/01-blink-a-led/schematic/assignment-1_bb.pdf deleted file mode 100644 index 0995ece..0000000 Binary files a/arduino/01-blink-a-led/schematic/assignment-1_bb.pdf and /dev/null differ diff --git a/arduino/01-blink-a-led/schematic/assignment-1_schem.pdf b/arduino/01-blink-a-led/schematic/assignment-1_schem.pdf deleted file mode 100644 index a5241b2..0000000 Binary files a/arduino/01-blink-a-led/schematic/assignment-1_schem.pdf and /dev/null differ diff --git a/arduino/01-blink-a-led/solution/assignment-1/assignment-1.ino b/arduino/01-blink-a-led/solution/assignment-1/assignment-1.ino deleted file mode 100644 index 5b72892..0000000 --- a/arduino/01-blink-a-led/solution/assignment-1/assignment-1.ino +++ /dev/null @@ -1,20 +0,0 @@ -const int LED_PIN = D0; - -void setup() { - Serial.begin(115200); - Serial.println(); - Serial.println(); - Serial.println("Hello world!"); - pinMode(LED_PIN, OUTPUT); -} - -void loop() { - digitalWrite(LED_PIN, HIGH); - Serial.println("HIGH"); - delay(1000); - - digitalWrite(LED_PIN, LOW); - Serial.println("LOW"); - delay(1000); -} - diff --git a/arduino/Makefile b/arduino/Makefile deleted file mode 100644 index c7ae828..0000000 --- a/arduino/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -AS=01-blink-a-led - -BASEDIR=$(CURDIR) - -include $(patsubst %,%/Makefile,$(AS)) diff --git a/arduino/Makefile.assignment b/arduino/Makefile.assignment deleted file mode 100644 index d05662f..0000000 --- a/arduino/Makefile.assignment +++ /dev/null @@ -1,8 +0,0 @@ -all: $(DIR)/$(A).pdf - -$(DIR)/$(A).pdf: $(DIR)/$(A).md - @echo pandoc $(A).md - @cd $(DIR); pandoc $(patsubst $(DIR)/%,%,$<) -o $(patsubst $(DIR)/%,%,$@) - -clean: - @rm -f $(DIR)/$(A).pdf diff --git a/arduino/client1/client1.ino b/arduino/client1/client1.ino deleted file mode 100644 index 39eabfe..0000000 --- a/arduino/client1/client1.ino +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include - -#include "config.h" - -WiFiUDP Udp; -unsigned int localUdpPort = 5006; -IPAddress host_ip(192, 168, 10, 151); -unsigned int host_port = 5005; - -const int out_buf_len_start = 100; -const int out_buf_len_increment = 100; -const int out_buf_len_max = 2200; - -char buf[out_buf_len_max]; -int out_buf_len; - -static const char alphabet[] = "abcdefghijklmnopqrstuvxyz"; - -unsigned long time_start, time_end; - -void setup() { - Serial.begin(115200); - - Serial.printf("Connecting to %s ", wifi_ssid); - WiFi.begin(wifi_ssid, wifi_password); - while (WiFi.status() != WL_CONNECTED) { - delay(500); - Serial.print("."); - } - Serial.println(" connected"); - - Udp.begin(localUdpPort); - time_start = millis(); - out_buf_len = out_buf_len_start; -} - -void loop() { - - if (millis() > (time_start + 1000)) { - for (int i = 0; i < out_buf_len; i++) { - buf[i] = alphabet[i % sizeof(alphabet) - 1]; - } - out_buf_len += out_buf_len_increment; - if (out_buf_len > out_buf_len_max) { - out_buf_len = out_buf_len_start; - } - Serial.printf("Sending %d bytes to %s:%d\n", out_buf_len, host_ip.toString().c_str(), host_port); - Udp.beginPacket(host_ip, host_port); - Udp.write(buf, out_buf_len); - time_start = millis(); - auto ok = Udp.endPacket(); - - if (!ok) { - Serial.printf("Could not send packet with size %d\n", out_buf_len); - } - } - - int len = Udp.parsePacket(); - if (len) { - time_end = millis(); - Serial.printf("RX %s:%d: size=%d\n", Udp.remoteIP().toString().c_str(), Udp.remotePort(), len); - int len = Udp.read(buf, sizeof(buf)); - Serial.printf("len=%d\n"); - if (len > 0) { - buf[len] = 0; - } - Serial.printf("RTT: %d ms. Payload:%s\n", int(time_end - time_start), buf); - } -} - diff --git a/arduino/client1/config.h b/arduino/client1/config.h deleted file mode 100644 index ea9affe..0000000 --- a/arduino/client1/config.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -const char wifi_ssid[] = "***REMOVED***"; -const char wifi_password[] = "***REMOVED***"; - diff --git a/assignments/Makefile b/assignments/Makefile new file mode 100644 index 0000000..c7ae828 --- /dev/null +++ b/assignments/Makefile @@ -0,0 +1,5 @@ +AS=01-blink-a-led + +BASEDIR=$(CURDIR) + +include $(patsubst %,%/Makefile,$(AS)) diff --git a/assignments/Makefile.assignment b/assignments/Makefile.assignment new file mode 100644 index 0000000..d05662f --- /dev/null +++ b/assignments/Makefile.assignment @@ -0,0 +1,8 @@ +all: $(DIR)/$(A).pdf + +$(DIR)/$(A).pdf: $(DIR)/$(A).md + @echo pandoc $(A).md + @cd $(DIR); pandoc $(patsubst $(DIR)/%,%,$<) -o $(patsubst $(DIR)/%,%,$@) + +clean: + @rm -f $(DIR)/$(A).pdf diff --git a/assignments/blink-a-led/Makefile b/assignments/blink-a-led/Makefile new file mode 100644 index 0000000..b015ec1 --- /dev/null +++ b/assignments/blink-a-led/Makefile @@ -0,0 +1,4 @@ +DIR=01-blink-a-led +A=blink-a-led + +include $(BASEDIR)/Makefile.assignment diff --git a/assignments/blink-a-led/blink-a-led.md b/assignments/blink-a-led/blink-a-led.md new file mode 100644 index 0000000..f4b3fa1 --- /dev/null +++ b/assignments/blink-a-led/blink-a-led.md @@ -0,0 +1,39 @@ +# Assignment: Blink a led + + +## Goal + +Check that your local environment is working properly. + +## Step 1 + +Create this schematic: + +![](schematic/assignment-1_schem.pdf) + +![](schematic/assignment-1_bb.pdf) + +The colors on the wires used does not matter. The resistors +orientation is not important, but the LED's orientation is important. + +## Step 2 + +Implement `setup()` and `loop()`. In `setup()` configure the LED pin and blink the LED in `loop()`. + +Use these functions: + +~~~ .c++ + +Serial.begin(115200); +Serial.println(string); + +pinMode(pin, mode); +digitalWrite(pin, state); // HIGH or LOW +delay(); + +~~~ + +## Tips + +* It is useful to print a startup message just to see when the + application has started. diff --git a/assignments/blink-a-led/blink-a-led.pdf b/assignments/blink-a-led/blink-a-led.pdf new file mode 100644 index 0000000..de719fd Binary files /dev/null and b/assignments/blink-a-led/blink-a-led.pdf differ diff --git a/assignments/blink-a-led/schematic/assignment-1.fzz b/assignments/blink-a-led/schematic/assignment-1.fzz new file mode 100644 index 0000000..da3ad5b Binary files /dev/null and b/assignments/blink-a-led/schematic/assignment-1.fzz differ diff --git a/assignments/blink-a-led/schematic/assignment-1_bb.pdf b/assignments/blink-a-led/schematic/assignment-1_bb.pdf new file mode 100644 index 0000000..0995ece Binary files /dev/null and b/assignments/blink-a-led/schematic/assignment-1_bb.pdf differ diff --git a/assignments/blink-a-led/schematic/assignment-1_schem.pdf b/assignments/blink-a-led/schematic/assignment-1_schem.pdf new file mode 100644 index 0000000..a5241b2 Binary files /dev/null and b/assignments/blink-a-led/schematic/assignment-1_schem.pdf differ diff --git a/assignments/blink-a-led/solution/assignment-1/assignment-1.ino b/assignments/blink-a-led/solution/assignment-1/assignment-1.ino new file mode 100644 index 0000000..5b72892 --- /dev/null +++ b/assignments/blink-a-led/solution/assignment-1/assignment-1.ino @@ -0,0 +1,20 @@ +const int LED_PIN = D0; + +void setup() { + Serial.begin(115200); + Serial.println(); + Serial.println(); + Serial.println("Hello world!"); + pinMode(LED_PIN, OUTPUT); +} + +void loop() { + digitalWrite(LED_PIN, HIGH); + Serial.println("HIGH"); + delay(1000); + + digitalWrite(LED_PIN, LOW); + Serial.println("LOW"); + delay(1000); +} + diff --git a/assignments/client1/client1.ino b/assignments/client1/client1.ino new file mode 100644 index 0000000..39eabfe --- /dev/null +++ b/assignments/client1/client1.ino @@ -0,0 +1,71 @@ +#include +#include + +#include "config.h" + +WiFiUDP Udp; +unsigned int localUdpPort = 5006; +IPAddress host_ip(192, 168, 10, 151); +unsigned int host_port = 5005; + +const int out_buf_len_start = 100; +const int out_buf_len_increment = 100; +const int out_buf_len_max = 2200; + +char buf[out_buf_len_max]; +int out_buf_len; + +static const char alphabet[] = "abcdefghijklmnopqrstuvxyz"; + +unsigned long time_start, time_end; + +void setup() { + Serial.begin(115200); + + Serial.printf("Connecting to %s ", wifi_ssid); + WiFi.begin(wifi_ssid, wifi_password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(" connected"); + + Udp.begin(localUdpPort); + time_start = millis(); + out_buf_len = out_buf_len_start; +} + +void loop() { + + if (millis() > (time_start + 1000)) { + for (int i = 0; i < out_buf_len; i++) { + buf[i] = alphabet[i % sizeof(alphabet) - 1]; + } + out_buf_len += out_buf_len_increment; + if (out_buf_len > out_buf_len_max) { + out_buf_len = out_buf_len_start; + } + Serial.printf("Sending %d bytes to %s:%d\n", out_buf_len, host_ip.toString().c_str(), host_port); + Udp.beginPacket(host_ip, host_port); + Udp.write(buf, out_buf_len); + time_start = millis(); + auto ok = Udp.endPacket(); + + if (!ok) { + Serial.printf("Could not send packet with size %d\n", out_buf_len); + } + } + + int len = Udp.parsePacket(); + if (len) { + time_end = millis(); + Serial.printf("RX %s:%d: size=%d\n", Udp.remoteIP().toString().c_str(), Udp.remotePort(), len); + int len = Udp.read(buf, sizeof(buf)); + Serial.printf("len=%d\n"); + if (len > 0) { + buf[len] = 0; + } + Serial.printf("RTT: %d ms. Payload:%s\n", int(time_end - time_start), buf); + } +} + -- cgit v1.2.3