Display mirror data sent over serial terminal.



  • 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);
    }
    }



  • 此回复已被删除!


  • 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.



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

    Back tics?



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



  • 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.



  • @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.


登录后回复
 

与 M5Stack Community 的连接断开,我们正在尝试重连,请耐心等待