{"id":8053,"date":"2023-03-26T21:18:57","date_gmt":"2023-03-26T21:18:57","guid":{"rendered":"https:\/\/www.fambach.net\/?p=8053"},"modified":"2026-10-15T20:45:23","modified_gmt":"2026-10-15T20:45:23","slug":"codeshorty-serieller-interrupt","status":"publish","type":"post","link":"https:\/\/www.fambach.net\/en\/codeshorty-serieller-interrupt\/","title":{"rendered":"CodeShorty: Serial Interrupt"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Contents\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.fambach.net\/en\/uno-wire-scannen\/#Zweck\" >Purpose<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.fambach.net\/en\/uno-wire-scannen\/#Notige_Bibliotheken\" >N\u00f6tige Bibliotheken<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.fambach.net\/en\/uno-wire-scannen\/#Programm\" >Programme<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.fambach.net\/en\/uno-wire-scannen\/#Probleme\" >Problems<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.fambach.net\/en\/uno-wire-scannen\/#Ausgabe_erfolgt_nicht\" >Ausgabe erfolgt nicht<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.fambach.net\/en\/uno-wire-scannen\/#Fazit\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.fambach.net\/en\/uno-wire-scannen\/#Andere_Shorties\" >Andere Shorties<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.fambach.net\/en\/uno-wire-scannen\/#Quellen\" >Sources<\/a><\/li><\/ul><\/nav><\/div>\n\n<p class=\"wp-block-paragraph\">Ist es m\u00f6glich, Eingaben auf der Seriellen-Schnittstelle per Interrupt abzufangen?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Die Antwort ist wohl eher Jain, es ist m\u00f6glich, die Serial Event Funktion zu verwenden. Diese wird nach jeder Loop ausgef\u00fchrt, unterbricht diese aber nicht.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"zweck\"><span class=\"ez-toc-section\" id=\"Zweck\"><\/span>Purpose<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Benutzereingaben \u00fcber Terminal<\/li><li>Kommunikation mit anderen Ger\u00e4ten \u00fcber die Serielle-Schnittstelle<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"noetige-bibliotheken\"><span class=\"ez-toc-section\" id=\"Notige_Bibliotheken\"><\/span>N\u00f6tige Bibliotheken<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">None <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"programm\"><span class=\"ez-toc-section\" id=\"Programm\"><\/span>Programme<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Es gibt in der Arduino-Gui die M\u00f6glichkeit, eine EventFunktion zu verwenden. Diese wird immer nach dem Loop aufgerufen, unterbricht aber keinen laufenden Code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Source code <code>SerialEvent.ino<\/code> (<span class=\"ub-content-link ub-content-link--ok ub-content-link--status-after\"><a href=\"https:\/\/github.com\/sfambach\/arduino\/tree\/master\/src\/SerialEvent\" class=\"ub-content-link__anchor\">GitHub<\/a><span class=\"ub-status ub-status--ok\" title=\"Link status: OK\"><span class=\"ub-status__icon\" aria-hidden=\"true\">\u25cf<\/span><span class=\"screen-reader-text\">Link status: OK<\/span><\/span><\/span>)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">\/** Test the Serial Event \n *  Autor: S. Fambach\n *  Visit http:\/\/www.fambach.net if you want\n *\/\n\n\nboolean stringComplete = false;\nString serialInput;\n\n\/**\n * Remove sting to the first occurance of \\n\n *\/\nString getFirstInput() {\n  int index = serialInput.indexOf(\"\\n\");\n  String ret = serialInput.substring(0, index);\n  \/\/ remove also the new line\n  serialInput.remove(0, index+1);\n  stringComplete = false;\n  return ret;\n}\n\nvoid setup() {\n\n  \/\/ start the serial\n  Serial.begin(115200);\n\n  \/\/ reserve some memmory for the string\n  serialInput.reserve(50);\n}\n\nvoid loop() {\n\n  \/\/ if there is a finished input do something\n  if ( stringComplete ) {\n    Serial.print(\"Received: \");\n    Serial.println(getFirstInput());\n\n  }\n}\n\n\/** \n *  serial event function will be called after the loop automatically\n *  \n *\/\nvoid serialEvent() {\n\n  \/\/ read everything from the serial\n  while (Serial.available()) {\n    Serial.print(\".\");\n    char inChar = (char)Serial.read();\n    \/\/ add it to the inputString:\n    serialInput += inChar;\n\n    if (inChar == '\\n' ) {\n      stringComplete = true;\n\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Damit die Event Funktion nicht blockiert, habe ich die WHILE Schleife herausgenommen. Die Funktion ist die gleiche wie vorher, allerdings wird bei jedem Zeichen nochmal die Arbeitsschleife durchlaufen. Dies kann evtl. zu anderen unerw\u00fcnschten Effekten f\u00fchren.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Source code <code>SerialEventNonBlocking.ino<\/code> (<span class=\"ub-content-link ub-content-link--ok ub-content-link--status-after\"><a href=\"https:\/\/github.com\/sfambach\/arduino\/tree\/master\/src\/SerialEventNonBlocking\" class=\"ub-content-link__anchor\">GitHub<\/a><span class=\"ub-status ub-status--ok\" title=\"Link status: OK\"><span class=\"ub-status__icon\" aria-hidden=\"true\">\u25cf<\/span><span class=\"screen-reader-text\">Link status: OK<\/span><\/span><\/span>)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">\/** Test the Serial Event\n *  Read data in the event and print it when its finished\n *  Autor: S. Fambach\n *  Visit http:\/\/www.fambach.net if you want\n*\/\n\n\nboolean stringComplete = false;\nString serialInput;\n\n\/**\n   Remove sting to the first occurance of \\n\n*\/\nString getFirstInput() {\n  int index = serialInput.indexOf(\"\\n\");\n  String ret = serialInput.substring(0, index);\n  \/\/ remove also the new line\n  serialInput.remove(0, index + 1);\n  stringComplete = false;\n  return ret;\n}\n\nvoid setup() {\n\n  \/\/ start the serial\n  Serial.begin(115200);\n\n  \/\/ reserve some memmory for the string\n  serialInput.reserve(50);\n}\n\nvoid loop() {\n\n  \/\/ if there is a finished input do something\n  if ( stringComplete ) {\n    Serial.print(\"Received: \");\n    Serial.println(getFirstInput());\n\n  }\n}\n\n\/**\n    serial event function will be called after the loop automatically\n\n*\/\nvoid serialEvent() {\n\n  \/\/ read something\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"probleme\"><span class=\"ez-toc-section\" id=\"Probleme\"><\/span>Problems<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ausgabe-erfolgt-nicht\"><span class=\"ez-toc-section\" id=\"Ausgabe_erfolgt_nicht\"><\/span>Ausgabe erfolgt nicht<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Darauf achten, dass das verwendete Terminal auf das Zeilenende \u201enew line\u201c eingestellt ist.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"fazit\"><span class=\"ez-toc-section\" id=\"Fazit\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Kein Interrupt, aber daf\u00fcr eine Funktionalit\u00e4t, die man nutzen kann.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"andere-shorties\"><span class=\"ez-toc-section\" id=\"Andere_Shorties\"><\/span>Andere Shorties<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<ul class=\"display-posts-listing\"><li class=\"listing-item\"><span class=\"ub-content-link ub-content-link--ok ub-content-link--status-after\"><a class=\"title ub-content-link__anchor\" href=\"https:\/\/www.fambach.net\/en\/codeshorty-serieller-interrupt\/\">CodeShorty: Serial Interrupt<\/a><span class=\"ub-status ub-status--ok\" title=\"Link status: OK\"><span class=\"ub-status__icon\" aria-hidden=\"true\">\u25cf<\/span><span class=\"screen-reader-text\">Link status: OK<\/span><\/span><\/span><\/li><li class=\"listing-item\"><span class=\"ub-content-link ub-content-link--ok ub-content-link--status-after\"><a class=\"title ub-content-link__anchor\" href=\"https:\/\/www.fambach.net\/en\/uno-wire-scannen\/\">CodeShorty: Wire Scanning (Uno)<\/a><span class=\"ub-status ub-status--ok\" title=\"Link status: OK\"><span class=\"ub-status__icon\" aria-hidden=\"true\">\u25cf<\/span><span class=\"screen-reader-text\">Link status: OK<\/span><\/span><\/span><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"quellen\"><span class=\"ez-toc-section\" id=\"Quellen\"><\/span>Sources<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><span class=\"ub-content-link ub-content-link--ok ub-content-link--status-after\"><a href=\"https:\/\/forum.arduino.cc\/t\/how-to-use-serial-interrupt-in-arduino\/335712\/29\" class=\"ub-content-link__anchor\">https:\/\/forum.arduino.cc\/t\/how-to-use-serial-interrupt-in-arduino\/335712\/29<\/a><span class=\"ub-status ub-status--ok\" title=\"Link status: OK\"><span class=\"ub-status__icon\" aria-hidden=\"true\">\u25cf<\/span><span class=\"screen-reader-text\">Link status: OK<\/span><\/span><\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span class=\"ub-content-link ub-content-link--ok ub-content-link--status-after\"><a href=\"https:\/\/www.arduino.cc\/en\/Tutorial\/BuiltInExamples\/SerialEvent\" class=\"ub-content-link__anchor\">https:\/\/www.arduino.cc\/en\/Tutorial\/BuiltInExamples\/SerialEvent<\/a><span class=\"ub-status ub-status--ok\" title=\"Link status: OK\"><span class=\"ub-status__icon\" aria-hidden=\"true\">\u25cf<\/span><span class=\"screen-reader-text\">Link status: OK<\/span><\/span><\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span class=\"ub-content-link ub-content-link--unknown ub-content-link--status-after\"><a href=\"https:\/\/forum.arduino.cc\/t\/interrupt-uber-serielle-schnittstelle\/545390\" class=\"ub-content-link__anchor\">https:\/\/forum.arduino.cc\/t\/interrupt-uber-serielle-schnittstelle\/545390<\/a><span class=\"ub-status ub-status--unknown\" title=\"Link status: Unknown\"><span class=\"ub-status__icon\" aria-hidden=\"true\">\u25cf<\/span><span class=\"screen-reader-text\">Link status: Unknown<\/span><\/span><\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span class=\"ub-content-link ub-content-link--unknown ub-content-link--status-after\"><a href=\"https:\/\/forum.arduino.cc\/t\/interrupt-sobald-daten-in-serial-eingangspuffer-stehen\/132916\" class=\"ub-content-link__anchor\">https:\/\/forum.arduino.cc\/t\/interrupt-sobald-daten-in-serial-eingangspuffer-stehen\/132916<\/a><span class=\"ub-status ub-status--unknown\" title=\"Link status: Unknown\"><span class=\"ub-status__icon\" aria-hidden=\"true\">\u25cf<\/span><span class=\"screen-reader-text\">Link status: Unknown<\/span><\/span><\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>","protected":false},"excerpt":{"rendered":"<p>Ist es m\u00f6glich, Eingaben auf der Seriellen-Schnittstelle per Interrupt abzufangen? Die Antwort ist wohl eher Jain, es ist m\u00f6glich, die Serial Event Funktion zu verwenden. Diese wird nach jeder Loop ausgef\u00fchrt, unterbricht diese aber nicht. Zweck Benutzereingaben \u00fcber Terminal Kommunikation mit anderen Ger\u00e4ten \u00fcber die Serielle-Schnittstelle N\u00f6tige Bibliotheken Keine Programm Es gibt in der Arduino-Gui &#8230;<\/p>\n<a href=\"https:\/\/www.fambach.net\/en\/uno-wire-scannen\/\" class=\"read-more-link\">Carry on reading <span class=\"screen-reader-text\">\"CodeShorty: Wire Scannen (Uno)\"<\/span> <span class=\"meta-nav\">\u2192<\/span><\/a>","protected":false},"author":1,"featured_media":7120,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"no","_lmt_disable":"no","footnotes":""},"categories":[175,184,539],"tags":[54,497,35,540,542,541],"class_list":["post-8053","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino-gui","category-c-c","category-codeshorty","tag-arduino-gui","tag-c-2","tag-c","tag-serial","tag-serielle-schnittstelle","tag-serielles-interface","penguin-post","penguin-post-not-sticky"],"modified_by":"sfambach","_links":{"self":[{"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/posts\/8053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/comments?post=8053"}],"version-history":[{"count":27,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/posts\/8053\/revisions"}],"predecessor-version":[{"id":19637,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/posts\/8053\/revisions\/19637"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/media\/7120"}],"wp:attachment":[{"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/media?parent=8053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/categories?post=8053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/tags?post=8053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}