Pavle Popovic 2020/0494

Dependencies:   Adafruit_GFX 19E042PIM_MB_PINS

Files at this revision

API Documentation at this revision

Comitter:
pavle1
Date:
Mon Jan 17 16:05:55 2022 +0000
Commit message:
Pavle Popovic 2020/0494

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
19E042PIM_MB_PINS.lib Show annotated file Show diff for this revision Revisions of this file
Adafruit_GFX.lib Show annotated file Show diff for this revision Revisions of this file
CONTRIBUTING.md Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
main1.txt Show annotated file Show diff for this revision Revisions of this file
main2.txt Show annotated file Show diff for this revision Revisions of this file
main3.txt Show annotated file Show diff for this revision Revisions of this file
mbed-mqtt.lib Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
resources/official_armmbed_example_badge.png Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Mon Jan 17 16:05:55 2022 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/19E042PIM_MB_PINS.lib	Mon Jan 17 16:05:55 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/tzwell/code/19E042PIM_MB_PINS/#5722459a201f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Adafruit_GFX.lib	Mon Jan 17 16:05:55 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/jportela/code/Adafruit_GFX/#e97cd4d2a37b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CONTRIBUTING.md	Mon Jan 17 16:05:55 2022 +0000
@@ -0,0 +1,5 @@
+# Contributing to Mbed OS
+
+Mbed OS is an open-source, device software platform for the Internet of Things. Contributions are an important part of the platform, and our goal is to make it as simple as possible to become a contributor.
+
+To encourage productive collaboration, as well as robust, consistent and maintainable code, we have a set of guidelines for [contributing to Mbed OS](https://os.mbed.com/docs/mbed-os/latest/contributing/index.html).
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Mon Jan 17 16:05:55 2022 +0000
@@ -0,0 +1,64 @@
+![](./resources/official_armmbed_example_badge.png)
+# Blinky Mbed OS example
+
+The example project is part of the [Arm Mbed OS Official Examples](https://os.mbed.com/code/) and is the [getting started example for Mbed OS](https://os.mbed.com/docs/mbed-os/v5.14/quick-start/index.html). It contains an application that repeatedly blinks an LED on supported [Mbed boards](https://os.mbed.com/platforms/).
+
+You can build the project with all supported [Mbed OS build tools](https://os.mbed.com/docs/mbed-os/latest/tools/index.html). However, this example project specifically refers to the command-line interface tool [Arm Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
+(Note: To see a rendered example you can import into the Arm Online Compiler, please see our [import quick start](https://os.mbed.com/docs/mbed-os/latest/quick-start/online-with-the-online-compiler.html#importing-the-code).)
+
+1. [Install Mbed CLI](https://os.mbed.com/docs/mbed-os/latest/quick-start/offline-with-mbed-cli.html).
+
+1. Clone this repository on your system, and change the current directory to where the project was cloned:
+
+    ```bash
+    $ git clone git@github.com:armmbed/mbed-os-example-blinky && cd mbed-os-example-blinky
+    ```
+
+    Alternatively, you can download the example project with Arm Mbed CLI using the `import` subcommand:
+
+    ```bash
+    $ mbed import mbed-os-example-blinky && cd mbed-os-example-blinky
+    ```
+
+
+## Application functionality
+
+The `main()` function is the single thread in the application. It toggles the state of a digital output connected to an LED on the board.
+
+## Building and running
+
+1. Connect a USB cable between the USB port on the board and the host computer.
+2. <a name="build_cmd"></a> Run the following command to build the example project and program the microcontroller flash memory:
+    ```bash
+    $ mbed compile -m <TARGET> -t <TOOLCHAIN> --flash
+    ```
+The binary is located at `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-blinky.bin`.
+
+Alternatively, you can manually copy the binary to the board, which you mount on the host computer over USB.
+
+Depending on the target, you can build the example project with the `GCC_ARM`, `ARM` or `IAR` toolchain. After installing Arm Mbed CLI, run the command below to determine which toolchain supports your target:
+
+```bash
+$ mbed compile -S
+```
+
+## Expected output
+The LED on your target turns on and off every 500 milliseconds.
+
+
+## Troubleshooting
+If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
+
+## Related Links
+
+* [Mbed OS Stats API](https://os.mbed.com/docs/latest/apis/mbed-statistics.html).
+* [Mbed OS Configuration](https://os.mbed.com/docs/latest/reference/configuration.html).
+* [Mbed OS Serial Communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html).
+* [Mbed OS bare metal](https://os.mbed.com/docs/mbed-os/latest/reference/mbed-os-bare-metal.html).
+* [Mbed boards](https://os.mbed.com/platforms/).
+
+### License and contributions
+
+The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see contributing.md for more info.
+
+This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main1.txt	Mon Jan 17 16:05:55 2022 +0000
@@ -0,0 +1,53 @@
+#include "mbed.h"//uvoz biblioteka
+
+#define MBED_RAM_SIZE//definisanje direktiva
+
+DigitalOut led(LED1);
+BusOut display(PA_10,PA_9,PA_8,PB_10,PB_5,PB_4,PB_3,PA_5);//glavne promenljive
+DigitalOut SEL2(PC_7);
+DigitalOut SEL1(PB_6);
+DigitalIn SW1(PC_9);
+
+int main()
+{
+    int x=1;
+    int i=0;
+    while (true)
+    {
+        if(i<11)
+        {
+            if(!SW1)
+            {
+                if(x){
+                    i=i+1;
+                    x=0;
+                }  
+            }
+            else
+            {
+                x=1;
+            }
+            wait_us(500);
+            SEL1.write(1);
+            SEL2.write(1);
+            switch(i)
+            {
+               case 0:SEL2.write(0);display.write(0xC0);wait_us(500);SEL2.write(1);break;
+               case 1:SEL2.write(0);display.write(0xF9);wait_us(500);SEL2.write(1);break;
+               case 2:SEL2.write(0);display.write(0xA4);wait_us(500);SEL2.write(1);break;
+               case 3:SEL2.write(0);display.write(0xB0);wait_us(500);SEL2.write(1);break;
+               case 4:SEL2.write(0);display.write(0x99);wait_us(500);SEL2.write(1);break;
+               case 5:SEL2.write(0);display.write(0x92);wait_us(500);SEL2.write(1);break;
+               case 6:SEL2.write(0);display.write(0x82);wait_us(500);SEL2.write(1);break;
+               case 7:SEL2.write(0);display.write(0xF8);wait_us(500);SEL2.write(1);break;
+               case 8:SEL2.write(0);display.write(0x80);wait_us(500);SEL2.write(1);break;
+               case 9:SEL2.write(0);display.write(0x90);wait_us(500);SEL2.write(1);break; 
+               case 10:SEL1.write(0);display.write(0xF9);wait_us(500);SEL1.write(1);SEL2.write(0);display.write(0xC0);wait_us(500);SEL2.write(1);break;
+            }
+        }
+        else
+        {
+            i=0;
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main2.txt	Mon Jan 17 16:05:55 2022 +0000
@@ -0,0 +1,59 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2019 ARM Limited
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include "mbed.h"//uvoz biblioteka
+
+#define SCALER 4950//definisanje direktiva
+
+AnalogIn pot1(PA_0);//glavne promenljive
+AnalogIn pot2(PA_1);
+PwmOut buzz(PA_11);
+InterruptIn sw1(PC_9);
+BusOut display(PA_10,PA_9,PA_8,PB_10,PB_5,PB_4,PB_3,PA_5);
+DigitalOut SEL2(PC_7);
+DigitalOut SEL1(PB_6);
+
+void ISR_sw1(void);//pomocne funkcije
+
+int main()//glavna funkcija
+{
+    buzz.period_ms(1);
+    sw1.fall(&ISR_sw1);
+    while (true) {
+        buzz.period_us(pot2.read()*SCALER+50);
+        buzz.write(pot1.read());
+        wait_ms(1);
+    }
+}
+
+void ISR_sw1()//interrupt sub-routine
+{
+        int i=pot1.read()*100;
+        
+        int d;
+        d=i/10;
+        while(!sw1.read())
+        {
+                SEL1.write(1);
+                SEL2.write(0);
+                switch(d)
+                {
+                   case 0:display.write(0xC0);break;
+                   case 1:display.write(0xF9);break;
+                   case 2:display.write(0xA4);break;
+                   case 3:display.write(0xB0);break;
+                   case 4:display.write(0x99);break;
+                   case 5:display.write(0x92);break;
+                   case 6:display.write(0x82);break;
+                   case 7:display.write(0xF8);break;
+                   case 8:display.write(0x80);break;
+                   case 9:display.write(0x90);break;
+                }
+                wait_us(500);
+                SEL2.write(1);
+        }
+        
+        
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main3.txt	Mon Jan 17 16:05:55 2022 +0000
@@ -0,0 +1,160 @@
+
+
+#include "mbed.h"//uvoz biblioteka
+#include "mb_pins.h"
+#include "platform/mbed_thread.h"
+#include "MQTTClientMbedOs.h"
+
+
+
+#define BLINKING_RATE_MS                                                     250//definisanje direktiva
+#define VOLTAGE_SCALER                                                      3.3f
+#define YIELD_TIMEOUT_MS                                                    1000
+#define MAX_NETWORKS                                                          15
+#define PRINTF_DELAY_MS                                                       10
+
+
+AnalogIn pot1(MB_POT1);//glavne promenljive
+InterruptIn sw1(MB_SW1);
+DigitalOut led2(MB_LED2);
+WiFiInterface *wifi;
+TCPSocket socket;
+MQTTClient client(&socket);
+MQTT::Message message;
+
+char* topic = "pubim";
+char* topic_sub = "subpim";
+int arrivedcount = 0;
+int button_pressed=0;
+const char* hostname = "broker.hivemq.com";
+int port = 1883;
+const char *sec2str(nsapi_security_t sec)
+{
+    switch (sec) 
+    {
+        case NSAPI_SECURITY_NONE:
+            return "None";
+        case NSAPI_SECURITY_WEP:
+            return "WEP";
+        case NSAPI_SECURITY_WPA:
+            return "WPA";
+        case NSAPI_SECURITY_WPA2:
+            return "WPA2";
+        case NSAPI_SECURITY_WPA_WPA2:
+            return "WPA/WPA2";
+        case NSAPI_SECURITY_UNKNOWN:
+        default:
+            return "Unknown";
+    }
+}
+
+int scan_networks(WiFiInterface *wifi)//pomocna funkcija skeniranja
+{
+    printf("Scan:\n");
+    
+    int count = wifi->scan(NULL, 0);
+    if (count <= 0)
+    {
+        printf("scan() failed with return value: %d\n", count);
+        return 0;
+    }
+
+    count = count < MAX_NETWORKS ? count : MAX_NETWORKS;
+    
+    WiFiAccessPoint *ap = new WiFiAccessPoint[count];
+    count = wifi->scan(ap, count);
+    
+    if (count <= 0) 
+    {
+        printf("scan() failed with return value: %d\n", count);
+        return 0;
+    }
+    
+    for (int i = 0; i < count; i++) 
+    {
+        printf("Network: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\n", ap[i].get_ssid(),
+               sec2str(ap[i].get_security()), ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2],
+               ap[i].get_bssid()[3], ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel());
+        thread_sleep_for(PRINTF_DELAY_MS);
+    }
+    printf("%d networks available.\n", count);
+    
+    delete[] ap;
+    return count;
+}
+
+void messageArrived(MQTT::MessageData& md)//pomocna funkcija
+{
+    MQTT::Message &message = md.message;
+    //printf("Message arrived: qos %d, retained %d, dup %d, packetid %d\r\n", message.qos, message.retained, message.dup, message.id);
+    printf("Message from the browser: %.*s\r\n", message.payloadlen, (char*)message.payload);
+    ++arrivedcount;
+}
+
+void buttonFunction() {  //pomocna funkcija menjanje stanja dugmeta
+    
+    button_pressed=1;
+   
+}
+
+int main()//glavna funkcija
+{
+    sw1.fall(&buttonFunction); 
+    
+    wifi = WiFiInterface::get_default_instance();
+    if (!wifi) {
+        printf("ERROR: No WiFiInterface found.\n");
+        return -1;
+    }
+    
+    int count = scan_networks(wifi);
+    if (count == 0) {
+        printf("No WIFI APs found - can't continue further.\n");
+        return -1;
+    }
+    
+    printf("\nConnecting to %s...\n", MBED_CONF_APP_WIFI_SSID);
+    int ret = wifi->connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
+    if (ret != 0) {
+        printf("\nConnection error: %d\n", ret);
+        return -1;
+    }
+    
+    printf("Success\n\n");
+    printf("MAC: %s\n", wifi->get_mac_address());
+    printf("IP: %s\n", wifi->get_ip_address());
+    printf("Netmask: %s\n", wifi->get_netmask());
+    printf("Gateway: %s\n", wifi->get_gateway());
+    printf("RSSI: %d\n\n", wifi->get_rssi());   
+    
+    socket.open(wifi);
+    socket.connect(hostname, port);
+    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
+    data.MQTTVersion = 3;
+    data.clientID.cstring = "NUCLEO-L476RG-60";
+    
+    int rc = 0;
+    if ((rc = client.connect(data)) != 0)
+        printf("rc from MQTT connect is %d\r\n", rc);
+
+    if ((rc = client.subscribe(topic_sub, MQTT::QOS2, messageArrived)) != 0)
+        printf("rc from MQTT subscribe is %d\r\n", rc);
+      
+    while (true) {
+        led2 = !led2;
+        thread_sleep_for(BLINKING_RATE_MS);
+        if (button_pressed==1) {
+            button_pressed=0;      
+            char buf[100];
+            sprintf(buf, "V(POT1) = %1.2f\r\n", pot1*VOLTAGE_SCALER);
+            wait(5);
+            message.qos = MQTT::QOS0;
+            message.retained = false;
+            message.dup = false;
+            message.payload = (void*)buf;
+            message.payloadlen = strlen(buf)+1;
+            client.publish(topic, message);
+        }
+        client.yield(YIELD_TIMEOUT_MS);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-mqtt.lib	Mon Jan 17 16:05:55 2022 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-mqtt/#7fa219e87b3355e8a6fd281659697fe3a0c87630
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Mon Jan 17 16:05:55 2022 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#e4b81f67f939a0c0b11c147ce74aa367271e1279
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Mon Jan 17 16:05:55 2022 +0000
@@ -0,0 +1,25 @@
+{
+    "config": {
+        "wifi-ssid": {
+            "help": "WIFI SSID",
+            "value": "\"cvele97\""
+        },
+        "wifi-password": {
+            "help": "Wifi Password",
+            "value": "\"ekonomskitigar2022\""
+        }
+    },
+    "target_overrides": {
+        "*": {
+            "platform.stdio-convert-newlines": true
+        },
+        "NUCLEO_L476RG": {
+            "target.network-default-interface-type": "WIFI",
+            "esp8266.tx"                           : "PC_4",
+            "esp8266.rx"                           : "PC_5",
+            "esp8266.provide-default"              : true,
+            "drivers.uart-serial-rxbuf-size"       : 1024,
+            "drivers.uart-serial-txbuf-size"       : 1024
+        }
+    }    
+}
\ No newline at end of file
Binary file resources/official_armmbed_example_badge.png has changed