🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Display mirror data sent over serial terminal.

    PRODUCTS
    2
    6
    5.9k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ajb2k3A
      ajb2k3
      last edited by ajb2k3

      Sorry all having a serious stupid moment here!

      How do I get

      m5.lcd.print();

      to show the data getting sent over the serial terminal?
      Following in my code.

      // Example for M5Stack StepMotor Module (I2C verison)
      // 2018/6/27 JimmyLai
      #include <M5Stack.h>
      #include <Wire.h>
      void setup() {
      // put your setup code here, to run once:
      M5.begin();
      Wire.begin();
      Serial.begin(115200);
      m5.Lcd.setTextColor(WHITE, BLACK);
      m5.Lcd.setTextSize(2);
      m5.lcd.setBrightness(100);
      M5.Lcd.setCursor(4, 10);
      M5.Lcd.println("Press A to move turntable.");
      SendCommand(0x70, "G21");
      SendCommand(0x70, "$2=1"); //Sets the steps per mm on the Z axis to 1.
      }
      void SendByte(byte addr, byte b) {
      Wire.beginTransmission(addr);
      Wire.write(b);
      Wire.endTransmission();
      }
      void SendCommand(byte addr, char *c) {
      Wire.beginTransmission(addr);
      while ((*c) != 0) {
      Wire.write(*c);
      c++;
      }
      Wire.write(0x0d);
      Wire.write(0x0a);
      Wire.endTransmission();
      }
      void loop() {
      if (digitalRead(39) == LOW) // A button
      {
      while (digitalRead(39) == LOW) delay(1);
      SendCommand(0x70, "G1 Y6.4");
      SendCommand(0x70, "M2");
      }
      // Get Data from Module.
      Wire.requestFrom(0x70, 1);
      if (Wire.available() > 0) {
      int u = Wire.read();
      if (u != 0) Serial.write(u);
      }
      Wire.requestFrom(0x71, 1);
      if (Wire.available() > 0) {
      int u = Wire.read();
      if (u != 0) Serial.write(u);
      }
      delay(1);
      // Send Data to Module.
      while (Serial.available() > 0) {
      int inByte = Serial.read();
      SendByte(0x70, inByte);
      SendByte(0x71, inByte);
      }
      }

      UIFlow, so easy an adult can learn it!
      If I don't know it, be patient!
      I've ether not learned it or am too drunk to remember it!
      Author of the WIP UIFlow Handbook!
      M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

      RopR 1 Reply Last reply Reply Quote 0
      • RopR
        Rop @ajb2k3
        last edited by Rop

        Hint: If you surround your code with three backticks on an empty line, it ends up looking like below, which is much more readable for everyone...

        // Example for M5Stack StepMotor Module (I2C verison)
        // 2018/6/27 JimmyLai
        
        #include <M5Stack.h>
        #include <Wire.h>
        
        void setup() {
          // put your setup code here, to run once:
          M5.begin();
          Wire.begin();
          Serial.begin(115200);
          m5.Lcd.setTextColor(WHITE, BLACK);
          m5.Lcd.setTextSize(2);
          m5.lcd.setBrightness(100);
          M5.Lcd.setCursor(4, 10);
          M5.Lcd.println("Press A to move turntable.");
          SendCommand(0x70, "G21");
          SendCommand(0x70, "$2=1"); //Sets the steps per mm on the Z axis to 1.
         }
        
        void SendByte(byte addr, byte b) {
          Wire.beginTransmission(addr);
          Wire.write(b);
          Wire.endTransmission();
        }
        
        void SendCommand(byte addr, char *c) {
          Wire.beginTransmission(addr);
          while ((*c) != 0) {
            Wire.write(*c);
            c++;
          }
          Wire.write(0x0d);
          Wire.write(0x0a);
          Wire.endTransmission();
        }
        
        void loop() {
          if (digitalRead(39) == LOW)  // A button
          {
            while (digitalRead(39) == LOW) delay(1);
            SendCommand(0x70, "G1 Y6.4");
            SendCommand(0x70, "M2");
          }
          // Get Data from Module.
          Wire.requestFrom(0x70, 1);
          if (Wire.available() > 0) {
            int u = Wire.read();
            if (u != 0) Serial.write(u);
          }
          Wire.requestFrom(0x71, 1);
          if (Wire.available() > 0) {
            int u = Wire.read();
            if (u != 0) Serial.write(u); 
          }
          delay(1);
          // Send Data to Module.
          while (Serial.available() > 0) {
            int inByte = Serial.read();
            SendByte(0x70, inByte);
            SendByte(0x71, inByte);
          }
        }
        
        • I wouldn't use if (digitalRead(39) == LOW) to read the button because m5.BtnA.wasPressed() has all the debounce and everything built-in.

        • If you want the text to scroll if more serial data comes in, you could use M5ez. Then you could just print to ez.canvas instead of to m5.lcd. The user manual in on the site, the part about printing to the canvas is here. M5ez also has easier display functions, button handling and much much more.

        1 Reply Last reply Reply Quote 0
        • ajb2k3A
          ajb2k3
          last edited by ajb2k3

          Thanks I'm working off M5's demo code which is causing alot of head scratching

          Back tics?

          UIFlow, so easy an adult can learn it!
          If I don't know it, be patient!
          I've ether not learned it or am too drunk to remember it!
          Author of the WIP UIFlow Handbook!
          M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

          RopR 1 Reply Last reply Reply Quote 0
          • RopR
            Rop @ajb2k3
            last edited by

            @ajb2k3 Back-tics are the ` single quote that is not ' but the one that on an english keyboard is ~ without shift.

            1 Reply Last reply Reply Quote 0
            • ajb2k3A
              ajb2k3
              last edited by ajb2k3

              I always intended to use M5EZ for the front end but I have been concentrating on the back end code.

              Also need to work out a boot Splash style start screen.

              UIFlow, so easy an adult can learn it!
              If I don't know it, be patient!
              I've ether not learned it or am too drunk to remember it!
              Author of the WIP UIFlow Handbook!
              M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

              1 Reply Last reply Reply Quote 0
              • ajb2k3A
                ajb2k3
                last edited by ajb2k3

                @rop 在

                My current issue is that because there is no

                serial.print();

                I cant issue

                m5.lcd.print();

                or

                ez.canvas.print();

                I'm seriously confused with this code.

                UIFlow, so easy an adult can learn it!
                If I don't know it, be patient!
                I've ether not learned it or am too drunk to remember it!
                Author of the WIP UIFlow Handbook!
                M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post