{"id":6258,"date":"2026-03-24T20:35:23","date_gmt":"2026-03-24T19:35:23","guid":{"rendered":"https:\/\/arduino.net.pl\/?p=6258"},"modified":"2026-03-24T23:16:04","modified_gmt":"2026-03-24T22:16:04","slug":"offline-voice-recognition-sensor-dfrobot","status":"publish","type":"post","link":"https:\/\/arduino.net.pl\/index.php\/offline-voice-recognition-sensor-dfrobot\/","title":{"rendered":"Offline Voice Recognition Sensor DFRobot"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/dfimg.dfrobot.com\/nobody\/wiki\/4f868c5f5b2b9ae909271b3865939655.png\" alt=\"https:\/\/dfimg.dfrobot.com\/nobody\/wiki\/4f868c5f5b2b9ae909271b3865939655.png\"\/><\/figure>\n\n\n\n<p>Zasilanie 3,3V &#8211; 5V<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Obs\u0142uga modu\u0142u<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Uczenie  dodatkowej frazy wybudzaj\u0105cej<\/h3>\n\n\n\n<p>Aby nauczy\u0107 modu\u0142 nowej frazy wybudzaj\u0105cej (zawsze aktywne pozostaje &#8222;<strong>Hello Robot!<\/strong>&#8222;) nale\u017cy po wywo\u0142aniu standardowym wyg\u0142osi\u0107 fraz\u0119: <strong>Learning wake word<\/strong>&#8222;. Nast\u0119pnie poda\u0107 nowe sformu\u0142owanie wybudzaj\u0105ce. Ja poda\u0142em <strong>Hello Jane. <\/strong>Trzeba to zrobi\u0107 trzykrotnie s\u0142uchaj\u0105c polece\u0144.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Kod dla Arduino z bibliotek\u0105 DFRobot_DF2301QG v1.0<br><\/h2>\n\n\n\n<p>Wed\u0142ug AI lepszym wyborem w przypadku DF2301QG jest j\u0119zyk Arduino. Mamy stabiln\u0105 bibliotek\u0119 dla po\u0142\u0105czenia I2C. Nale\u017cy pami\u0119ta\u0107, by ustawi\u0107 <strong>Communication Mode Select<\/strong> w module w tej w\u0142a\u015bnie pozycji.<\/p>\n\n\n\n<p>Biblioteka Arduino:&nbsp; <a title=\"\" href=\"https:\/\/github.com\/DFRobot\/DFRobot_DF2301Q\">https:\/\/github.com\/DFRobot\/DFRobot_DF2301Q<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Poni\u017cej kod na mikrokontroler ESP32 po\u0142\u0105czony przez I2C z modu\u0142em <strong>DF2301QG v1.0<\/strong>. \u0141\u0105czy si\u0119 z serwerem MQTT i wysy\u0142a ID us\u0142yszanych komendy na <strong>mqtt_topic<\/strong>.<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; light: false; title: Kod:; toolbar: true; notranslate\" title=\"Kod:\">\n\/\/ Hello Robot!\n\n#include &lt;WiFi.h&gt;\n#include &lt;PubSubClient.h&gt;\n#include &lt;DFRobot_DF2301Q.h&gt;\n#include &lt;Wire.h&gt;\n#include &quot;config.h&quot;\n\n\/\/ ================= USTAWIENIA WI-FI =================\nconst char* ssid = WIFI_SSID;\nconst char* password = WIFI_PASSWORD;\n\n\/\/ ================= USTAWIENIA MQTT =================\nconst char* mqtt_server = MQTT_SERVER;      \nconst int mqtt_port = MQTT_PORT;            \nconst char* mqtt_topic = MQTT_TOPIC_VOICE;  \nconst char* mqtt_client_id = MQTT_CLIENT;\n\n\/\/ Piny I2C dla ESP32\n#define I2C_SDA 21\n#define I2C_SCL 22\n\n\/\/ Inicjalizacja obiekt\u00f3w\nWiFiClient espClient;\nPubSubClient client(espClient);\nDFRobot_DF2301Q_I2C asr;\n\n\/\/ Zmienne do op\u00f3\u017anie\u0144\nunsigned long lastReconnectAttempt = 0;\nunsigned long lastVoiceCheck = 0;\n\nvoid printProgramInfo() {\n  while (!Serial) { ; }\n  Serial.println();\n  Serial.println(&quot;-----------------------------&quot;);\n  Serial.println(&quot;--- Informacje o programie ---&quot;);\n  Serial.print(&quot;Nazwa programu: &quot;);\n  Serial.println(__FILE__);\n  Serial.print(&quot;Data kompilacji: &quot;);\n  Serial.print(__DATE__); \n  Serial.print(&quot; &quot;); \n  Serial.println(__TIME__); \n  Serial.println(&quot;-----------------------------&quot;);\n}\n\n\/\/ Funkcja \u0142\u0105cz\u0105ca z Wi-Fi\nvoid setup_wifi() {\n  delay(10);\n  Serial.println();\n  Serial.print(&quot;\u0141\u0105czenie z sieci\u0105 Wi-Fi: &quot;);\n  Serial.println(ssid);\n\n  WiFi.mode(WIFI_STA);\n  WiFi.setAutoReconnect(true); \n  WiFi.persistent(true);\n  \n  WiFi.begin(ssid, password);\n\n  while (WiFi.status() != WL_CONNECTED) {\n    delay(500);\n    Serial.print(&quot;.&quot;);\n  }\n\n  Serial.println(&quot;\\nPo\u0142\u0105czono z Wi-Fi!&quot;);\n  Serial.print(&quot;Adres IP: &quot;);\n  Serial.println(WiFi.localIP());\n}\n\n\/\/ Funkcja MQTT\nboolean reconnectMQTT() {\n  Serial.print(&quot;Pr\u00f3ba po\u0142\u0105czenia z MQTT...&quot;);\n  if (client.connect(mqtt_client_id)) {\n    Serial.println(&quot; Po\u0142\u0105czono z Mosquitto!&quot;);\n    return true;\n  } else {\n    Serial.print(&quot; B\u0142\u0105d, rc=&quot;);\n    Serial.print(client.state());\n    Serial.println(&quot; - kolejna pr\u00f3ba za 5 sekund.&quot;);\n    return false;\n  }\n}\n\nvoid setup() {\n  Serial.begin(115200);\n  printProgramInfo();\n  \n  Wire.begin(I2C_SDA, I2C_SCL);\n\n  setup_wifi();\n  client.setServer(mqtt_server, mqtt_port);\n\n  Serial.println(&quot;Inicjalizacja modu\u0142u DF2301Q...&quot;);\n  if (!(asr.begin())) {\n    Serial.println(&quot;B\u0142\u0105d komunikacji z modu\u0142em DF2301Q. Sprawd\u017a po\u0142\u0105czenia I2C!&quot;);\n    while (1) { yield(); }  \n  }\n  Serial.println(&quot;Modu\u0142 mowy zainicjowany pomy\u015blnie.&quot;);\n\n  asr.setVolume(7);     \n  asr.setMuteMode(0);   \n  asr.setWakeTime(20);  \n}\n\nvoid loop() {\n  \/\/ 1. Sprawdzanie Wi-Fi\n  if (WiFi.status() == WL_CONNECTED) {\n    \/\/ 2. Obs\u0142uga MQTT (tylko je\u015bli jest Wi-Fi)\n    if (!client.connected()) {\n      unsigned long now = millis();\n      if (now - lastReconnectAttempt &gt; 5000) {\n        lastReconnectAttempt = now;\n        reconnectMQTT();\n      }\n    } else {\n      client.loop(); \/\/ Podtrzymanie komunikacji z Mosquitto\n    }\n  }\n\n  \/\/ 3. Odczyt komendy z czujnika mowy (ZAWSZE, NAWET BEZ MQTT!)\n  \/\/ Zwi\u0119kszony interwa\u0142 z 50ms na 250ms dla stabilno\u015bci szyny I2C\n  unsigned long currentMillis = millis();\n  if (currentMillis - lastVoiceCheck &gt;= 250) {\n    lastVoiceCheck = currentMillis;\n    \n    uint8_t CMDID = asr.getCMDID();\n\n    \/\/ Dodano zabezpieczenie przed kodem b\u0142\u0119du I2C (255)\n    if (CMDID != 0 &amp;&amp; CMDID != 98 &amp;&amp; CMDID != 255) {\n      Serial.print(&quot;&amp;#x2705; Rozpoznano komend\u0119 o ID: &quot;);\n      Serial.println(CMDID);\n\n      \/\/ 4. Publikacja MQTT - wysy\u0142amy tylko wtedy, gdy serwer faktycznie nas s\u0142ucha\n      if (client.connected()) {\n        char payload&#x5B;10];\n        itoa(CMDID, payload, 10);\n        \n        if (client.publish(mqtt_topic, payload, false)) {\n          Serial.println(&quot;  -&gt; Wys\u0142ano do MQTT pomy\u015blnie.&quot;);\n        } else {\n          Serial.println(&quot;  -&gt; B\u0142\u0105d wysy\u0142ania do MQTT.&quot;);\n        }\n      } else {\n        Serial.println(&quot;  -&gt; &amp;#x26a0;&amp;#xfe0f; Brak po\u0142\u0105czenia z MQTT! Komenda us\u0142yszana, ale nie wys\u0142ana.&quot;);\n      }\n    }\n  }\n}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">Tabela komend z ID  (PDF)<\/h3>\n\n\n\n<div class=\"wp-block-embedpress-embedpress-pdf\"><div id=\"ep-gutenberg-content-d41d8cd98f00b204e9800998ecf8427e\" class=\"ep-gutenberg-content\"><div class=\"embedpress-document-embed ep-doc-embedpress-pdf-1774381316062   ep-fixed-width\" style=\"width:600px;height:600px;max-width:100%\" id=\"ep-doc-undefined\" data-source-id=\"source-undefined\" data-embed-type=\"PDF\"><div class=\"ep-embed-content-wraper\"><div class=\"position-right-wraper gutenberg-pdf-wraper\"><div class=\"main-content-wraper\"><iframe title=\"DF2301Q Komendy\" powered_by=\"1\" style=\"height:600px;width:600px;max-width:100%\" class=\"embedpress-embed-document-pdf embedpress-pdf-1774381316062\" data-emid=\"embedpress-pdf-1774381316062\" data-viewer-style=\"modern\" src=\"https:\/\/arduino.net.pl\/wp-admin\/admin-ajax.php?action=get_viewer&amp;scrolling=-1&amp;selection_tool=0&amp;spreads=0&amp;file=https%3A%2F%2Farduino.net.pl%2Fwp-content%2Fuploads%2F2026%2F03%2FDF2301Q-Komendy.pdf#key=dGhlbWVNb2RlPWRlZmF1bHQmcHJlc2VudGF0aW9uPXRydWUmbGF6eUxvYWQ9ZmFsc2UmcG9zaXRpb249dG9wJmZsaXBib29rX3Rvb2xiYXJfcG9zaXRpb249Ym90dG9tJmRvd25sb2FkPXRydWUmdG9vbGJhcj10cnVlJmNvcHlfdGV4dD10cnVlJmFkZF90ZXh0PXRydWUmZHJhdz1mYWxzZSZkb2NfZGV0YWlscz10cnVlJmRvY19yb3RhdGlvbj10cnVlJmFkZF9pbWFnZT10cnVlJnpvb21faW49dHJ1ZSZ6b29tX291dD10cnVlJmZpdF92aWV3PXRydWUmYm9va21hcms9dHJ1ZSZzZWxlY3Rpb25fdG9vbD0wJnNjcm9sbGluZz0tMSZzcHJlYWRzPTA=\"><\/iframe><\/div><p class=\"embedpress-el-powered\">Powered By EmbedPress<\/p><\/div><\/div><\/div><\/div><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>&#8230;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Flow dla Node-RED w\u0142\u0105czaj\u0105cy i wy\u0142\u0105czaj\u0105cy \u015bwiat\u0142o (komenda 103, 104) podpi\u0119te do odbiornika na &#8222;topic&#8221;: &#8222;d1mini\/urzadzenie1\/set&#8221; ON, OFF<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; light: false; title: Kod:; toolbar: true; notranslate\" title=\"Kod:\">\n&#x5B;\n    {\n        &quot;id&quot;: &quot;750214f6e6c63297&quot;,\n        &quot;type&quot;: &quot;tab&quot;,\n        &quot;label&quot;: &quot;Flow 3&quot;,\n        &quot;disabled&quot;: false,\n        &quot;info&quot;: &quot;&quot;,\n        &quot;env&quot;: &#x5B;]\n    },\n    {\n        &quot;id&quot;: &quot;s1&quot;,\n        &quot;type&quot;: &quot;switch&quot;,\n        &quot;z&quot;: &quot;750214f6e6c63297&quot;,\n        &quot;name&quot;: &quot;Wyb\u00f3r ID&quot;,\n        &quot;property&quot;: &quot;payload&quot;,\n        &quot;propertyType&quot;: &quot;msg&quot;,\n        &quot;rules&quot;: &#x5B;\n            {\n                &quot;t&quot;: &quot;eq&quot;,\n                &quot;v&quot;: &quot;103&quot;,\n                &quot;vt&quot;: &quot;num&quot;\n            },\n            {\n                &quot;t&quot;: &quot;eq&quot;,\n                &quot;v&quot;: &quot;104&quot;,\n                &quot;vt&quot;: &quot;num&quot;\n            }\n        ],\n        &quot;checkall&quot;: &quot;true&quot;,\n        &quot;repair&quot;: false,\n        &quot;outputs&quot;: 2,\n        &quot;x&quot;: 360,\n        &quot;y&quot;: 140,\n        &quot;wires&quot;: &#x5B;\n            &#x5B;\n                &quot;c1&quot;\n            ],\n            &#x5B;\n                &quot;c2&quot;\n            ]\n        ]\n    },\n    {\n        &quot;id&quot;: &quot;c1&quot;,\n        &quot;type&quot;: &quot;change&quot;,\n        &quot;z&quot;: &quot;750214f6e6c63297&quot;,\n        &quot;name&quot;: &quot;Zamie\u0144 na ON&quot;,\n        &quot;rules&quot;: &#x5B;\n            {\n                &quot;t&quot;: &quot;set&quot;,\n                &quot;p&quot;: &quot;payload&quot;,\n                &quot;pt&quot;: &quot;msg&quot;,\n                &quot;to&quot;: &quot;OFF&quot;,\n                &quot;tot&quot;: &quot;str&quot;\n            }\n        ],\n        &quot;action&quot;: &quot;&quot;,\n        &quot;property&quot;: &quot;&quot;,\n        &quot;from&quot;: &quot;&quot;,\n        &quot;to&quot;: &quot;&quot;,\n        &quot;reg&quot;: false,\n        &quot;x&quot;: 560,\n        &quot;y&quot;: 120,\n        &quot;wires&quot;: &#x5B;\n            &#x5B;\n                &quot;m1&quot;\n            ]\n        ]\n    },\n    {\n        &quot;id&quot;: &quot;c2&quot;,\n        &quot;type&quot;: &quot;change&quot;,\n        &quot;z&quot;: &quot;750214f6e6c63297&quot;,\n        &quot;name&quot;: &quot;Zamie\u0144 na OFF&quot;,\n        &quot;rules&quot;: &#x5B;\n            {\n                &quot;t&quot;: &quot;set&quot;,\n                &quot;p&quot;: &quot;payload&quot;,\n                &quot;pt&quot;: &quot;msg&quot;,\n                &quot;to&quot;: &quot;ON&quot;,\n                &quot;tot&quot;: &quot;str&quot;\n            }\n        ],\n        &quot;action&quot;: &quot;&quot;,\n        &quot;property&quot;: &quot;&quot;,\n        &quot;from&quot;: &quot;&quot;,\n        &quot;to&quot;: &quot;&quot;,\n        &quot;reg&quot;: false,\n        &quot;x&quot;: 560,\n        &quot;y&quot;: 160,\n        &quot;wires&quot;: &#x5B;\n            &#x5B;\n                &quot;m1&quot;\n            ]\n        ]\n    },\n    {\n        &quot;id&quot;: &quot;m1&quot;,\n        &quot;type&quot;: &quot;mqtt out&quot;,\n        &quot;z&quot;: &quot;750214f6e6c63297&quot;,\n        &quot;name&quot;: &quot;&quot;,\n        &quot;topic&quot;: &quot;d1mini\/urzadzenie1\/set&quot;,\n        &quot;qos&quot;: &quot;1&quot;,\n        &quot;retain&quot;: &quot;&quot;,\n        &quot;respTopic&quot;: &quot;&quot;,\n        &quot;contentType&quot;: &quot;&quot;,\n        &quot;userProps&quot;: &quot;&quot;,\n        &quot;correl&quot;: &quot;&quot;,\n        &quot;expiry&quot;: &quot;&quot;,\n        &quot;broker&quot;: &quot;be57f5ae9b4c6eb4&quot;,\n        &quot;x&quot;: 810,\n        &quot;y&quot;: 140,\n        &quot;wires&quot;: &#x5B;]\n    },\n    {\n        &quot;id&quot;: &quot;31c29f1ad59174b1&quot;,\n        &quot;type&quot;: &quot;mqtt in&quot;,\n        &quot;z&quot;: &quot;750214f6e6c63297&quot;,\n        &quot;name&quot;: &quot;G\u0142os ESP32&quot;,\n        &quot;topic&quot;: &quot;home\/voice1\/commands&quot;,\n        &quot;qos&quot;: &quot;1&quot;,\n        &quot;datatype&quot;: &quot;auto-detect&quot;,\n        &quot;broker&quot;: &quot;be57f5ae9b4c6eb4&quot;,\n        &quot;nl&quot;: false,\n        &quot;rap&quot;: false,\n        &quot;inputs&quot;: 0,\n        &quot;x&quot;: 190,\n        &quot;y&quot;: 140,\n        &quot;wires&quot;: &#x5B;\n            &#x5B;\n                &quot;s1&quot;,\n                &quot;ea3cb018ea7ed788&quot;\n            ]\n        ]\n    },\n    {\n        &quot;id&quot;: &quot;ea3cb018ea7ed788&quot;,\n        &quot;type&quot;: &quot;debug&quot;,\n        &quot;z&quot;: &quot;750214f6e6c63297&quot;,\n        &quot;name&quot;: &quot;debug 2&quot;,\n        &quot;active&quot;: true,\n        &quot;tosidebar&quot;: true,\n        &quot;console&quot;: false,\n        &quot;tostatus&quot;: false,\n        &quot;complete&quot;: &quot;false&quot;,\n        &quot;statusVal&quot;: &quot;&quot;,\n        &quot;statusType&quot;: &quot;auto&quot;,\n        &quot;x&quot;: 320,\n        &quot;y&quot;: 240,\n        &quot;wires&quot;: &#x5B;]\n    },\n    {\n        &quot;id&quot;: &quot;be57f5ae9b4c6eb4&quot;,\n        &quot;type&quot;: &quot;mqtt-broker&quot;,\n        &quot;name&quot;: &quot;&quot;,\n        &quot;broker&quot;: &quot;localhost&quot;,\n        &quot;port&quot;: 1883,\n        &quot;clientid&quot;: &quot;&quot;,\n        &quot;autoConnect&quot;: true,\n        &quot;usetls&quot;: false,\n        &quot;protocolVersion&quot;: 4,\n        &quot;keepalive&quot;: 60,\n        &quot;cleansession&quot;: true,\n        &quot;autoUnsubscribe&quot;: true,\n        &quot;birthTopic&quot;: &quot;&quot;,\n        &quot;birthQos&quot;: &quot;0&quot;,\n        &quot;birthRetain&quot;: &quot;false&quot;,\n        &quot;birthPayload&quot;: &quot;&quot;,\n        &quot;birthMsg&quot;: {},\n        &quot;closeTopic&quot;: &quot;&quot;,\n        &quot;closeQos&quot;: &quot;0&quot;,\n        &quot;closeRetain&quot;: &quot;false&quot;,\n        &quot;closePayload&quot;: &quot;&quot;,\n        &quot;closeMsg&quot;: {},\n        &quot;willTopic&quot;: &quot;&quot;,\n        &quot;willQos&quot;: &quot;0&quot;,\n        &quot;willRetain&quot;: &quot;false&quot;,\n        &quot;willPayload&quot;: &quot;&quot;,\n        &quot;willMsg&quot;: {},\n        &quot;userProps&quot;: &quot;&quot;,\n        &quot;sessionExpiry&quot;: &quot;&quot;\n    }\n]\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">MICROPYTHON<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">Biblioteka MicroPython<\/h3>\n\n\n\n<p>Biblioteka lekko zmodyfikowana. W oryginalnej by\u0142 b\u0142\u0105d w metodzie <strong>get_cmdid()<\/strong>. Poprawiony przez <em><strong>Chat GPT<\/strong><\/em>.<br>Uwaga! Kody nie dzia\u0142aj\u0105 dla ESP8266. Prawdopodobnie problem tkwi w bibliotece I2C. Mo\u017ce trzeba u\u017cy\u0107 softI2C? Sprawdz\u0119.<br>Wszystko dobrze dzia\u0142a na ESP32.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; light: false; title: Kod:; toolbar: true; notranslate\" title=\"Kod:\">\nfrom micropython import const\nfrom machine import I2C, Pin\nfrom utime import sleep\n\n\nDF2301Q_I2C_ADDR = const(0x64)\n\n\nclass DFRobot_DF2301Q_I2C:\n    &quot;&quot;&quot;\n    MicroPython class for communication with the DF2301Q from DFRobot via I2C\n    &quot;&quot;&quot;\n\n    DF2301Q_I2C_REG_CMDID = const(0x02)\n    DF2301Q_I2C_REG_PLAY_CMDID = const(0x03)\n    DF2301Q_I2C_REG_SET_MUTE = const(0x04)\n    DF2301Q_I2C_REG_SET_VOLUME = const(0x05)\n    DF2301Q_I2C_REG_WAKE_TIME = const(0x06)\n    DF2301Q_I2C_8BIT_RANGE = const(0xFF)\n    DF2301Q_I2C_PLAY_CMDID_DURATION = const(1)\n\n    def __init__(self, sda, scl, i2c_addr=DF2301Q_I2C_ADDR, i2c_bus=0):\n        &quot;&quot;&quot;\n        Initialize the DF2301Q I2C communication\n        :param sda: I2C SDA pin\n        :param scl: I2C SCL pin\n        :param i2c_addr: I2C address\n        :param i2c_bus: I2C bus number\n        &quot;&quot;&quot;\n        self._addr = i2c_addr\n\n        try:\n            self._i2c = I2C(i2c_bus, sda=Pin(sda), scl=Pin(scl))\n        except Exception as err:\n            print(f&#039;Could not initialize i2c! bus: {i2c_bus}, sda: {sda}, scl: {scl}, error: {err}&#039;)\n\n    def _write_reg(self, reg, data) -&gt; None:\n        &quot;&quot;&quot;\n        Writes data to the I2C register\n        :param reg: register address\n        :param data: data to write\n        :return: None\n        &quot;&quot;&quot;\n        if isinstance(data, int):\n            data = &#x5B;data]\n\n        try:\n            self._i2c.writeto_mem(self._addr, reg, bytearray(data))\n        except Exception as err:\n            print(f&#039;Write issue: {err}&#039;)\n\n    def _read_reg(self, reg, length) -&gt; bytes:\n        &quot;&quot;&quot;\n        Reads data from the I2C register\n        :param reg: register address\n        :param length: number of bytes to read\n        :return: bytes\n        &quot;&quot;&quot;\n        try:\n            result = self._i2c.readfrom_mem(self._addr, reg, length)\n        except Exception as err:\n            print(f&#039;Read issue: {err}&#039;)\n            result = bytearray(length)\n\n        return result\n\n    def get_cmdid(self) -&gt; int:\n        &quot;&quot;&quot;\n        Returns the current command id\n        :return: int\n        &quot;&quot;&quot;\n        data = self._read_reg(self.DF2301Q_I2C_REG_CMDID, 1)\n        return int(data&#x5B;0])\n\n    def get_wake_time(self) -&gt; int:\n        &quot;&quot;&quot;\n        Returns the current wake-up duration\n        :return: int\n        &quot;&quot;&quot;\n        data = self._read_reg(self.DF2301Q_I2C_REG_WAKE_TIME, 1)\n        return int(data&#x5B;0])\n\n    def play_by_cmdid(self, cmdid: int) -&gt; None:\n        &quot;&quot;&quot;\n        Play the current command words by command id\n        :param cmdid: command words as integer\n        :return: None\n        &quot;&quot;&quot;\n        self._write_reg(self.DF2301Q_I2C_REG_PLAY_CMDID, int(cmdid))\n        sleep(self.DF2301Q_I2C_PLAY_CMDID_DURATION)\n\n    def set_wake_time(self, wake_time: int) -&gt; None:\n        &quot;&quot;&quot;\n        Set the wake-up duration of the device\n        :param wake_time: integer between 0 and 255\n        :return: None\n        &quot;&quot;&quot;\n        wake_up_time = int(wake_time) &amp; self.DF2301Q_I2C_8BIT_RANGE\n        self._write_reg(self.DF2301Q_I2C_REG_WAKE_TIME, wake_up_time)\n\n    def set_volume(self, vol: int) -&gt; None:\n        &quot;&quot;&quot;\n        Set the volume of the device\n        :param vol: integer between 1 and 7\n        :return: None\n        &quot;&quot;&quot;\n        self._write_reg(self.DF2301Q_I2C_REG_SET_VOLUME, int(vol))\n\n    def set_mute_mode(self, mode) -&gt; None:\n        &quot;&quot;&quot;\n        Set the mute mode of the device\n        :param mode: integer 0 for off, 1 for on\n        :return: None\n        &quot;&quot;&quot;\n        self._write_reg(self.DF2301Q_I2C_REG_SET_MUTE, int(bool(mode)))\n\n\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Kod programu wy\u015bwietlaj\u0105cego na konsoli numery komend g\u0142osowych<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; light: false; title: Kod:; toolbar: true; notranslate\" title=\"Kod:\">\nfrom DFRobot_DF2301Q_I2C import DFRobot_DF2301Q_I2C\nfrom micropython import const\nfrom utime import sleep\n\n\nSDA_PIN = const(21)\nSCL_PIN = const(22)\nSLEEP_SECONDS = const(3)\n\n\ndef setup(sensor) -&gt; None:\n    &quot;&quot;&quot;\n    Set up the DFRobot DF2301Q sensor\n    :param sensor: instance of DFRobot_DF2301Q_I2C\n    :return: None\n    &quot;&quot;&quot;\n    sensor.set_volume(5)\n    sensor.set_mute_mode(0)\n    sensor.set_wake_time(20)\n\n\ndef get_cmd_id(sensor) -&gt; int:\n    &quot;&quot;&quot;\n    Get the command id from the DF2301Q sensor\n    :param sensor: instance of DFRobot_DF2301Q_I2C\n    :return: int\n    &quot;&quot;&quot;\n    command_id = sensor.get_cmdid()\n    return command_id if command_id != 0 else None\n\n\nif __name__ == &quot;__main__&quot;:\n    try:\n        voice_sensor = DFRobot_DF2301Q_I2C(sda=SDA_PIN, scl=SCL_PIN)\n        setup(sensor=voice_sensor)\n\n        print(&#039;Speak your commands:&#039;)\n\n        while True:\n            cmd_id = get_cmd_id(sensor=voice_sensor)\n\n            if cmd_id is not None:\n                print(f&#039;COMMAND ID: {cmd_id}&#039;)\n\n            sleep(SLEEP_SECONDS)\n    except Exception as e:\n        print(f&#039;Initialization error: {e}&#039;)\n\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">LINKI<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Oficjalna biblioteka Arduino:\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/DFRobot\/DFRobot_DF2301Q\">https:\/\/github.com\/DFRobot\/DFRobot_DF2301Q<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Dokumentacja:\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/wiki.dfrobot.com\/SKU_SEN0539-EN_Gravity_Voice_Recognition_Module_I2C_UART\" title=\"\">https:\/\/wiki.dfrobot.com\/SKU_SEN0539-EN_Gravity_Voice_Recognition_Module_I2C_UART<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Biblioteka MicroPython (<strong>uwaga, b\u0142\u0105d!<\/strong>):\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/Lupin3000\/Micropython-I2C-DF2301Q\" title=\"\">https:\/\/github.com\/Lupin3000\/Micropython-I2C-DF2301Q<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>NerdCave, MicroPython\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/nerdcave.xyz\/docs\/tutorials\/gravity-offline-language-learning-voice-recognition-sensor\/\" title=\"\">https:\/\/nerdcave.xyz\/docs\/tutorials\/gravity-offline-language-learning-voice-recognition-sensor\/<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u0179r\u00f3d\u0142a:<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">Konfiguracja i dzia\u0142anie<\/h2>\n\n\n\n<iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/GcZpXVAkt4U?si=GZ5j0JGRzXxIbynO\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n\n\n\n<h2 class=\"wp-block-heading\">Trening<\/h2>\n\n\n\n<iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/6yKBlNiXV4Q?si=BrsOFJ1wGF-r41Y-\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n\n\n\n<h2 class=\"wp-block-heading\">Inne<\/h2>\n\n\n\n<iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/RLhK_yZynYI?si=WN2fvoe1Gp8s554c\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n\n\n\n<iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/XlILfn9Z7H8?si=R20W27_IW0S_qURM\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n","protected":false},"excerpt":{"rendered":"<p>Zasilanie 3,3V &#8211; 5V Obs\u0142uga modu\u0142u Uczenie dodatkowej frazy wybudzaj\u0105cej Aby nauczy\u0107 modu\u0142 nowej frazy wybudzaj\u0105cej (zawsze aktywne pozostaje &#8222;Hello Robot!&#8222;) nale\u017cy po wywo\u0142aniu standardowym wyg\u0142osi\u0107 fraz\u0119: Learning wake word&#8222;&#8230;.<\/p>\n","protected":false},"author":3,"featured_media":6882,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[153,80,141,183,65],"tags":[184,160,30],"class_list":["post-6258","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino-ide","category-esp32","category-micropython","category-node-red","category-programowanie","tag-df2301q","tag-mqtt","tag-tutorial"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts\/6258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/comments?post=6258"}],"version-history":[{"count":47,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts\/6258\/revisions"}],"predecessor-version":[{"id":6902,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/posts\/6258\/revisions\/6902"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/media\/6882"}],"wp:attachment":[{"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/media?parent=6258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/categories?post=6258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arduino.net.pl\/index.php\/wp-json\/wp\/v2\/tags?post=6258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}