Advertisement
SemlerPDX

Hello-World_ArduinoConsoleApp_CompanionSketch

May 22nd, 2022 (edited)
608
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This example Arduino Sketch is for use on Arduino Uno/Nano/Micro (or equiv. clone boards)
  2. // -Problem of serial read timeout on Micro with USB CDC Serial hardware not present on Uno/Nano/Mini
  3. // --complete details here:
  4. // https://github.com/SemlerPDX/ArduinoConsoleAppTest1
  5.  
  6.  
  7. void WriteMethod_Characters(String dataToSend) {
  8.   for (int i = 0; i <= dataToSend.length(); i++) {
  9.     Serial.write(dataToSend.charAt(i));
  10.   }
  11. }
  12.  
  13. void setup() {
  14.   Serial.begin(9600); // Define speed at 9600 baud
  15.   while (!Serial) {
  16.     ; // wait for serial port to connect. Needed for native USB
  17.   }
  18. }
  19.  
  20. void loop() {
  21.   String dataPrints = "";
  22.   dataPrints.concat("[Hello,");
  23.   dataPrints.concat(Serial.availableForWrite());
  24.   dataPrints.concat(",World]");
  25.  
  26.   //This issue occurs regardless of print()/println()/write() methods
  27.   WriteMethod_Characters(dataPrints);
  28.   delay(1000);
  29.   Serial.println();
  30. }
Advertisement
RAW Paste Data Copied
Advertisement